1*9880d681SAndroid Build Coastguard Worker// Copyright (C) 2016 The Android Open Source Project 2*9880d681SAndroid Build Coastguard Worker// 3*9880d681SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*9880d681SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*9880d681SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*9880d681SAndroid Build Coastguard Worker// 7*9880d681SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*9880d681SAndroid Build Coastguard Worker// 9*9880d681SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*9880d681SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*9880d681SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*9880d681SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*9880d681SAndroid Build Coastguard Worker// limitations under the License. 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Workerpackage llvm 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Workerimport ( 18*9880d681SAndroid Build Coastguard Worker "android/soong/android" 19*9880d681SAndroid Build Coastguard Worker "android/soong/cc" 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 22*9880d681SAndroid Build Coastguard Worker) 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Workerfunc globalFlags(ctx android.LoadHookContext) []string { 25*9880d681SAndroid Build Coastguard Worker var cflags []string 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker if ctx.Config().IsEnvTrue("FORCE_BUILD_LLVM_DISABLE_NDEBUG") { 28*9880d681SAndroid Build Coastguard Worker cflags = append(cflags, "-D_DEBUG", "-UNDEBUG") 29*9880d681SAndroid Build Coastguard Worker } 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker return cflags 32*9880d681SAndroid Build Coastguard Worker} 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Workerfunc deviceFlags(ctx android.LoadHookContext) []string { 35*9880d681SAndroid Build Coastguard Worker var cflags []string 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker return cflags 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Workerfunc hostFlags(ctx android.LoadHookContext) []string { 41*9880d681SAndroid Build Coastguard Worker var cflags []string 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker if ctx.Config().IsEnvTrue("FORCE_BUILD_LLVM_DEBUG") { 44*9880d681SAndroid Build Coastguard Worker cflags = append(cflags, "-O0", "-g") 45*9880d681SAndroid Build Coastguard Worker } 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker return cflags 48*9880d681SAndroid Build Coastguard Worker} 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workerfunc llvmDefaults(ctx android.LoadHookContext) { 51*9880d681SAndroid Build Coastguard Worker type props struct { 52*9880d681SAndroid Build Coastguard Worker Target struct { 53*9880d681SAndroid Build Coastguard Worker Android struct { 54*9880d681SAndroid Build Coastguard Worker Cflags []string 55*9880d681SAndroid Build Coastguard Worker Enabled *bool 56*9880d681SAndroid Build Coastguard Worker } 57*9880d681SAndroid Build Coastguard Worker Host struct { 58*9880d681SAndroid Build Coastguard Worker Enabled *bool 59*9880d681SAndroid Build Coastguard Worker } 60*9880d681SAndroid Build Coastguard Worker Not_windows struct { 61*9880d681SAndroid Build Coastguard Worker Cflags []string 62*9880d681SAndroid Build Coastguard Worker } 63*9880d681SAndroid Build Coastguard Worker } 64*9880d681SAndroid Build Coastguard Worker Cflags []string 65*9880d681SAndroid Build Coastguard Worker } 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker p := &props{} 68*9880d681SAndroid Build Coastguard Worker p.Cflags = globalFlags(ctx) 69*9880d681SAndroid Build Coastguard Worker p.Target.Android.Cflags = deviceFlags(ctx) 70*9880d681SAndroid Build Coastguard Worker // Mingw fails to link binaries with lots of debug information 71*9880d681SAndroid Build Coastguard Worker p.Target.Not_windows.Cflags = hostFlags(ctx) 72*9880d681SAndroid Build Coastguard Worker 73*9880d681SAndroid Build Coastguard Worker if ctx.Config().IsEnvTrue("DISABLE_LLVM_DEVICE_BUILDS") { 74*9880d681SAndroid Build Coastguard Worker p.Target.Android.Enabled = proptools.BoolPtr(false) 75*9880d681SAndroid Build Coastguard Worker } 76*9880d681SAndroid Build Coastguard Worker 77*9880d681SAndroid Build Coastguard Worker ctx.AppendProperties(p) 78*9880d681SAndroid Build Coastguard Worker} 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Workerfunc forceBuildLlvmComponents(ctx android.LoadHookContext) { 81*9880d681SAndroid Build Coastguard Worker forceBuild := false 82*9880d681SAndroid Build Coastguard Worker if ctx.Config().IsEnvTrue("FORCE_BUILD_LLVM_COMPONENTS") { 83*9880d681SAndroid Build Coastguard Worker forceBuild = true 84*9880d681SAndroid Build Coastguard Worker } 85*9880d681SAndroid Build Coastguard Worker if len(ctx.Config().SanitizeHost()) > 0 { 86*9880d681SAndroid Build Coastguard Worker forceBuild = true 87*9880d681SAndroid Build Coastguard Worker } 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker if !forceBuild { 90*9880d681SAndroid Build Coastguard Worker type props struct { 91*9880d681SAndroid Build Coastguard Worker Target struct { 92*9880d681SAndroid Build Coastguard Worker Darwin_arm64 struct { 93*9880d681SAndroid Build Coastguard Worker Enabled *bool 94*9880d681SAndroid Build Coastguard Worker } 95*9880d681SAndroid Build Coastguard Worker Host struct { 96*9880d681SAndroid Build Coastguard Worker Enabled *bool 97*9880d681SAndroid Build Coastguard Worker } 98*9880d681SAndroid Build Coastguard Worker Linux_bionic_arm64 struct { 99*9880d681SAndroid Build Coastguard Worker Enabled *bool 100*9880d681SAndroid Build Coastguard Worker } 101*9880d681SAndroid Build Coastguard Worker Linux_musl struct { 102*9880d681SAndroid Build Coastguard Worker Enabled *bool 103*9880d681SAndroid Build Coastguard Worker } 104*9880d681SAndroid Build Coastguard Worker } 105*9880d681SAndroid Build Coastguard Worker } 106*9880d681SAndroid Build Coastguard Worker p := &props{} 107*9880d681SAndroid Build Coastguard Worker p.Target.Darwin_arm64.Enabled = proptools.BoolPtr(true) 108*9880d681SAndroid Build Coastguard Worker p.Target.Host.Enabled = proptools.BoolPtr(false) 109*9880d681SAndroid Build Coastguard Worker p.Target.Linux_bionic_arm64.Enabled = proptools.BoolPtr(true) 110*9880d681SAndroid Build Coastguard Worker p.Target.Linux_musl.Enabled = proptools.BoolPtr(true) 111*9880d681SAndroid Build Coastguard Worker ctx.AppendProperties(p) 112*9880d681SAndroid Build Coastguard Worker } 113*9880d681SAndroid Build Coastguard Worker} 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Workerfunc init() { 116*9880d681SAndroid Build Coastguard Worker android.RegisterModuleType("llvm_defaults", llvmDefaultsFactory) 117*9880d681SAndroid Build Coastguard Worker android.RegisterModuleType("force_build_llvm_components_defaults", forceBuildLlvmComponentsDefaultsFactory) 118*9880d681SAndroid Build Coastguard Worker} 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Workerfunc llvmDefaultsFactory() android.Module { 121*9880d681SAndroid Build Coastguard Worker module := cc.DefaultsFactory() 122*9880d681SAndroid Build Coastguard Worker android.AddLoadHook(module, llvmDefaults) 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Worker return module 125*9880d681SAndroid Build Coastguard Worker} 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Workerfunc forceBuildLlvmComponentsDefaultsFactory() android.Module { 128*9880d681SAndroid Build Coastguard Worker module := cc.DefaultsFactory() 129*9880d681SAndroid Build Coastguard Worker android.AddLoadHook(module, forceBuildLlvmComponents) 130*9880d681SAndroid Build Coastguard Worker return module 131*9880d681SAndroid Build Coastguard Worker} 132