summaryrefslogtreecommitdiff
path: root/cc/compiler.go
diff options
context:
space:
mode:
Diffstat (limited to 'cc/compiler.go')
-rw-r--r--cc/compiler.go168
1 files changed, 128 insertions, 40 deletions
diff --git a/cc/compiler.go b/cc/compiler.go
index 88985b6f9..03f9899d8 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -50,7 +50,7 @@ type BaseCompilerProperties struct {
Exclude_srcs []string `android:"path,arch_variant"`
// list of module-specific flags that will be used for C and C++ compiles.
- Cflags []string `android:"arch_variant"`
+ Cflags proptools.Configurable[[]string] `android:"arch_variant"`
// list of module-specific flags that will be used for C++ compiles
Cppflags []string `android:"arch_variant"`
@@ -98,10 +98,10 @@ type BaseCompilerProperties struct {
// list of generated headers to add to the include path. These are the names
// of genrule modules.
- Generated_headers []string `android:"arch_variant,variant_prepend"`
+ Generated_headers proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// pass -frtti instead of -fno-rtti
- Rtti *bool
+ Rtti *bool `android:"arch_variant"`
// C standard version to use. Can be a specific version (such as "gnu11"),
// "experimental" (which will use draft versions like C1x when available),
@@ -116,10 +116,21 @@ type BaseCompilerProperties struct {
// if set to false, use -std=c++* instead of -std=gnu++*
Gnu_extensions *bool
+ // cc Build rules targeting BPF must set this to true. The correct fix is to
+ // ban targeting bpf in cc rules instead use bpf_rules. (b/323415017)
+ Bpf_target *bool
+
+ // Add "-Xclang -verify" to the cflags and appends "touch $out" to
+ // the clang command line.
+ Clang_verify bool
+
Yacc *YaccProperties
Lex *LexProperties
Aidl struct {
+ // List of aidl_library modules
+ Libs []string
+
// list of directories that will be added to the aidl include paths.
Include_dirs []string
@@ -134,6 +145,22 @@ type BaseCompilerProperties struct {
Flags []string
}
+ // Populated by aidl_interface CPP backend to let other modules (e.g. cc_cmake_snapshot)
+ // access actual source files and not generated cpp intermediary sources.
+ AidlInterface struct {
+ // list of aidl_interface sources
+ Sources []string `blueprint:"mutated"`
+
+ // root directory of AIDL sources
+ AidlRoot string `blueprint:"mutated"`
+
+ // AIDL backend language (e.g. "cpp", "ndk")
+ Lang string `blueprint:"mutated"`
+
+ // list of flags passed to AIDL generator
+ Flags []string `blueprint:"mutated"`
+ } `blueprint:"mutated"`
+
Renderscript struct {
// list of directories that will be added to the llvm-rs-cc include paths
Include_dirs []string
@@ -145,12 +172,6 @@ type BaseCompilerProperties struct {
Target_api *string
}
- Debug, Release struct {
- // list of module-specific flags that will be used for C and C++ compiles in debug or
- // release builds
- Cflags []string `android:"arch_variant"`
- } `android:"arch_variant"`
-
Target struct {
Vendor, Product struct {
// list of source files that should only be used in vendor or
@@ -186,13 +207,13 @@ type BaseCompilerProperties struct {
// build the recovery variant of the C/C++ module.
Exclude_generated_sources []string
}
- Vendor_ramdisk struct {
+ Ramdisk, Vendor_ramdisk struct {
// list of source files that should not be used to
- // build the vendor ramdisk variant of the C/C++ module.
+ // build the ramdisk variants of the C/C++ module.
Exclude_srcs []string `android:"path"`
- // List of additional cflags that should be used to build the vendor ramdisk
- // variant of the C/C++ module.
+ // List of additional cflags that should be used to build the ramdisk
+ // variants of the C/C++ module.
Cflags []string
}
Platform struct {
@@ -247,7 +268,7 @@ func (compiler *baseCompiler) Srcs() android.Paths {
}
func (compiler *baseCompiler) appendCflags(flags []string) {
- compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...)
+ compiler.Properties.Cflags.AppendSimpleValue(flags)
}
func (compiler *baseCompiler) appendAsflags(flags []string) {
@@ -258,6 +279,10 @@ func (compiler *baseCompiler) compilerProps() []interface{} {
return []interface{}{&compiler.Properties, &compiler.Proto}
}
+func (compiler *baseCompiler) baseCompilerProps() BaseCompilerProperties {
+ return compiler.Properties
+}
+
func includeBuildDirectory(prop *bool) bool {
return proptools.BoolDefault(prop, true)
}
@@ -271,7 +296,8 @@ func (compiler *baseCompiler) compilerInit(ctx BaseModuleContext) {}
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps.GeneratedSources = append(deps.GeneratedSources, compiler.Properties.Generated_sources...)
deps.GeneratedSources = removeListFromList(deps.GeneratedSources, compiler.Properties.Exclude_generated_sources)
- deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers...)
+ deps.GeneratedHeaders = append(deps.GeneratedHeaders, compiler.Properties.Generated_headers.GetOrDefault(ctx, nil)...)
+ deps.AidlLibs = append(deps.AidlLibs, compiler.Properties.Aidl.Libs...)
android.ProtoDeps(ctx, &compiler.Proto)
if compiler.hasSrcExt(".proto") {
@@ -335,24 +361,26 @@ func parseCStd(cStdPtr *string) string {
// per-target values, module type values, and per-module Blueprints properties
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
tc := ctx.toolchain()
- modulePath := android.PathForModuleSrc(ctx).String()
+ modulePath := ctx.ModuleDir()
compiler.srcsBeforeGen = android.PathsForModuleSrcExcludes(ctx, compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...)
- CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
+ cflags := compiler.Properties.Cflags.GetOrDefault(ctx, nil)
+ CheckBadCompilerFlags(ctx, "cflags", cflags)
CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags)
CheckBadCompilerFlags(ctx, "vendor.cflags", compiler.Properties.Target.Vendor.Cflags)
CheckBadCompilerFlags(ctx, "product.cflags", compiler.Properties.Target.Product.Cflags)
CheckBadCompilerFlags(ctx, "recovery.cflags", compiler.Properties.Target.Recovery.Cflags)
+ CheckBadCompilerFlags(ctx, "ramdisk.cflags", compiler.Properties.Target.Ramdisk.Cflags)
CheckBadCompilerFlags(ctx, "vendor_ramdisk.cflags", compiler.Properties.Target.Vendor_ramdisk.Cflags)
CheckBadCompilerFlags(ctx, "platform.cflags", compiler.Properties.Target.Platform.Cflags)
esc := proptools.NinjaAndShellEscapeList
- flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Cflags)...)
+ flags.Local.CFlags = append(flags.Local.CFlags, esc(cflags)...)
flags.Local.CppFlags = append(flags.Local.CppFlags, esc(compiler.Properties.Cppflags)...)
flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, esc(compiler.Properties.Conlyflags)...)
flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Asflags)...)
@@ -361,6 +389,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Yacc = compiler.Properties.Yacc
flags.Lex = compiler.Properties.Lex
+ flags.ClangVerify = compiler.Properties.Clang_verify
+ if compiler.Properties.Clang_verify {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-Xclang", "-verify")
+ }
+
// Include dir cflags
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
if len(localIncludeDirs) > 0 {
@@ -380,7 +413,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+modulePath)
}
- if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
+ if !(ctx.useSdk() || ctx.InVendorOrProduct()) || ctx.Host() {
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
"${config.CommonGlobalIncludes}",
tc.IncludeFlags())
@@ -397,10 +430,19 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
}
- if ctx.useVndk() {
+ if ctx.InVendorOrProduct() {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
if ctx.inVendor() {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VENDOR__")
+
+ vendorApiLevel := ctx.Config().VendorApiLevel()
+ if vendorApiLevel == "" {
+ // TODO(b/314036847): This is a fallback for UDC targets.
+ // This must be a build failure when UDC is no longer built
+ // from this source tree.
+ vendorApiLevel = ctx.Config().PlatformSdkVersion().String()
+ }
+ flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VENDOR_API__="+vendorApiLevel)
} else if ctx.inProduct() {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_PRODUCT__")
}
@@ -431,11 +473,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
ctx.ModuleErrorf("%s", err)
}
- CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
-
- // TODO: debug
- flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...)
-
if !ctx.DeviceConfig().BuildBrokenClangCFlags() && len(compiler.Properties.Clang_cflags) != 0 {
ctx.PropertyErrorf("clang_cflags", "property is deprecated, see Changes.md file")
} else {
@@ -465,10 +502,15 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
target += strconv.Itoa(android.FutureApiLevelInt)
} else {
apiLevel := nativeApiLevelOrPanic(ctx, version)
- target += apiLevel.String()
+ target += strconv.Itoa(apiLevel.FinalOrFutureInt())
}
}
+ // bpf targets don't need the default target triple. b/308826679
+ if proptools.Bool(compiler.Properties.Bpf_target) {
+ target = "--target=bpf"
+ }
+
flags.Global.CFlags = append(flags.Global.CFlags, target)
flags.Global.AsFlags = append(flags.Global.AsFlags, target)
flags.Global.LdFlags = append(flags.Global.LdFlags, target)
@@ -484,8 +526,12 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Global.AsFlags = append(flags.Global.AsFlags, tc.Asflags())
flags.Global.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.Global.CppFlags...)
+
+ // bpf targets don't need the target specific toolchain cflags. b/308826679
+ if !proptools.Bool(compiler.Properties.Bpf_target) {
+ flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.Cflags())
+ }
flags.Global.CommonFlags = append(flags.Global.CommonFlags,
- tc.Cflags(),
"${config.CommonGlobalCflags}",
fmt.Sprintf("${config.%sGlobalCflags}", hod))
@@ -493,12 +539,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "${config.ExternalCflags}")
}
- if tc.Bionic() {
- if Bool(compiler.Properties.Rtti) {
- flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti")
- } else {
- flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti")
- }
+ if Bool(compiler.Properties.Rtti) {
+ flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti")
+ } else {
+ flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti")
}
flags.Global.AsFlags = append(flags.Global.AsFlags, "${config.CommonGlobalAsflags}")
@@ -507,7 +551,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags())
- flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainCflags())
+ // bpf targets don't need the target specific toolchain cflags. b/308826679
+ if !proptools.Bool(compiler.Properties.Bpf_target) {
+ flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainCflags())
+ }
cStd := parseCStd(compiler.Properties.C_std)
cppStd := parseCppStd(compiler.Properties.Cpp_std)
@@ -532,6 +579,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
if ctx.inVendorRamdisk() {
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor_ramdisk.Cflags)...)
}
+ if ctx.inRamdisk() {
+ flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Ramdisk.Cflags)...)
+ }
if !ctx.useSdk() {
flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Platform.Cflags)...)
}
@@ -561,7 +611,12 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
}
- if compiler.hasSrcExt(".aidl") {
+ if len(compiler.Properties.Aidl.Libs) > 0 &&
+ (len(compiler.Properties.Aidl.Include_dirs) > 0 || len(compiler.Properties.Aidl.Local_include_dirs) > 0) {
+ ctx.ModuleErrorf("aidl.libs and (aidl.include_dirs or aidl.local_include_dirs) can't be set at the same time. For aidl headers, please only use aidl.libs prop")
+ }
+
+ if compiler.hasAidl(deps) {
flags.aidlFlags = append(flags.aidlFlags, compiler.Properties.Aidl.Flags...)
if len(compiler.Properties.Aidl.Local_include_dirs) > 0 {
localAidlIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Aidl.Local_include_dirs)
@@ -572,6 +627,14 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs))
}
+ var rootAidlIncludeDirs android.Paths
+ for _, aidlLibraryInfo := range deps.AidlLibraryInfos {
+ rootAidlIncludeDirs = append(rootAidlIncludeDirs, aidlLibraryInfo.IncludeDirs.ToList()...)
+ }
+ if len(rootAidlIncludeDirs) > 0 {
+ flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs))
+ }
+
if proptools.BoolDefault(compiler.Properties.Aidl.Generate_traces, true) {
flags.aidlFlags = append(flags.aidlFlags, "-t")
}
@@ -582,8 +645,14 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
}
flags.aidlFlags = append(flags.aidlFlags, "--min_sdk_version="+aidlMinSdkVersion)
- flags.Local.CommonFlags = append(flags.Local.CommonFlags,
- "-I"+android.PathForModuleGen(ctx, "aidl").String())
+ if compiler.hasSrcExt(".aidl") {
+ flags.Local.CommonFlags = append(flags.Local.CommonFlags,
+ "-I"+android.PathForModuleGen(ctx, "aidl").String())
+ }
+ if len(deps.AidlLibraryInfos) > 0 {
+ flags.Local.CommonFlags = append(flags.Local.CommonFlags,
+ "-I"+android.PathForModuleGen(ctx, "aidl_library").String())
+ }
}
if compiler.hasSrcExt(".rscript") || compiler.hasSrcExt(".fs") {
@@ -612,12 +681,27 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
}
+ if ctx.optimizeForSize() {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-Oz")
+ flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm,-enable-ml-inliner=release")
+ }
+
// Exclude directories from manual binder interface allowed list.
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
flags.Local.CFlags = append(flags.Local.CFlags, "-DDO_NOT_CHECK_MANUAL_BINDER_INTERFACES")
}
+ flags.NoOverrideFlags = append(flags.NoOverrideFlags, "${config.NoOverrideGlobalCflags}")
+
+ if flags.Toolchain.Is64Bit() {
+ flags.NoOverrideFlags = append(flags.NoOverrideFlags, "${config.NoOverride64GlobalCflags}")
+ }
+
+ if android.IsThirdPartyPath(ctx.ModuleDir()) {
+ flags.NoOverrideFlags = append(flags.NoOverrideFlags, "${config.NoOverrideExternalGlobalCflags}")
+ }
+
return flags
}
@@ -660,6 +744,10 @@ func ndkPathDeps(ctx ModuleContext) android.Paths {
return nil
}
+func (compiler *baseCompiler) hasAidl(deps PathDeps) bool {
+ return len(deps.AidlLibraryInfos) > 0 || compiler.hasSrcExt(".aidl")
+}
+
func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
pathDeps := deps.GeneratedDeps
pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
@@ -668,7 +756,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
srcs := append(android.Paths(nil), compiler.srcsBeforeGen...)
- srcs, genDeps, info := genSources(ctx, srcs, buildFlags)
+ srcs, genDeps, info := genSources(ctx, deps.AidlLibraryInfos, srcs, buildFlags)
pathDeps = append(pathDeps, genDeps...)
compiler.pathDeps = pathDeps
@@ -680,7 +768,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
// Compile files listed in c.Properties.Srcs into objects
objs := compileObjs(ctx, buildFlags, "", srcs,
- android.PathsForModuleSrc(ctx, compiler.Properties.Tidy_disabled_srcs),
+ append(android.PathsForModuleSrc(ctx, compiler.Properties.Tidy_disabled_srcs), compiler.generatedSources...),
android.PathsForModuleSrc(ctx, compiler.Properties.Tidy_timeout_srcs),
pathDeps, compiler.cFlagsDeps)
@@ -716,7 +804,7 @@ type RustBindgenClangProperties struct {
Header_libs []string `android:"arch_variant,variant_prepend"`
// list of clang flags required to correctly interpret the headers.
- Cflags []string `android:"arch_variant"`
+ Cflags proptools.Configurable[[]string] `android:"arch_variant"`
// list of c++ specific clang flags required to correctly interpret the headers.
// This is provided primarily to make sure cppflags defined in cc_defaults are pulled in.