summaryrefslogtreecommitdiff
path: root/cc/compiler.go
diff options
context:
space:
mode:
Diffstat (limited to 'cc/compiler.go')
-rw-r--r--cc/compiler.go59
1 files changed, 35 insertions, 24 deletions
diff --git a/cc/compiler.go b/cc/compiler.go
index f2bced10a..949603e40 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -324,6 +324,10 @@ func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
getNamedMapForConfig(ctx.Config(), key).Store(module, true)
}
+func requiresGlobalIncludes(ctx ModuleContext) bool {
+ return !(ctx.useSdk() || ctx.InVendorOrProduct()) || ctx.Host()
+}
+
func useGnuExtensions(gnuExtensions *bool) bool {
return proptools.BoolDefault(gnuExtensions, true)
}
@@ -360,6 +364,29 @@ func parseCStd(cStdPtr *string) string {
}
}
+func AddTargetFlags(ctx android.ModuleContext, flags Flags, tc config.Toolchain, version string, bpf bool) Flags {
+ target := "-target " + tc.ClangTriple()
+ if ctx.Os().Class == android.Device {
+ if version == "" || version == "current" {
+ target += strconv.Itoa(android.FutureApiLevelInt)
+ } else {
+ apiLevel := nativeApiLevelOrPanic(ctx, version)
+ target += strconv.Itoa(apiLevel.FinalOrFutureInt())
+ }
+ }
+
+ // bpf targets don't need the default target triple. b/308826679
+ if bpf {
+ 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)
+
+ return flags
+}
+
// Create a Flags struct that collects the compile flags from global values,
// per-target values, module type values, and per-module Blueprints properties
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
@@ -429,7 +456,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+modulePath)
}
- if !(ctx.useSdk() || ctx.InVendorOrProduct()) || ctx.Host() {
+ if requiresGlobalIncludes(ctx) {
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
"${config.CommonGlobalIncludes}",
tc.IncludeFlags())
@@ -513,25 +540,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Local.ConlyFlags = config.ClangFilterUnknownCflags(flags.Local.ConlyFlags)
flags.Local.LdFlags = config.ClangFilterUnknownCflags(flags.Local.LdFlags)
- target := "-target " + tc.ClangTriple()
- if ctx.Os().Class == android.Device {
- version := ctx.minSdkVersion()
- if version == "" || version == "current" {
- target += strconv.Itoa(android.FutureApiLevelInt)
- } else {
- apiLevel := nativeApiLevelOrPanic(ctx, version)
- 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)
+ flags = AddTargetFlags(ctx, flags, tc, ctx.minSdkVersion(), Bool(compiler.Properties.Bpf_target))
hod := "Host"
if ctx.Os().Class == android.Device {
@@ -785,7 +794,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
objs := compileObjs(ctx, buildFlags, "", srcs,
append(android.PathsForModuleSrc(ctx, compiler.Properties.Tidy_disabled_srcs), compiler.generatedSources...),
android.PathsForModuleSrc(ctx, compiler.Properties.Tidy_timeout_srcs),
- pathDeps, compiler.cFlagsDeps)
+ pathDeps, compiler.cFlagsDeps, ctx.getSharedFlags())
if ctx.Failed() {
return Objects{}
@@ -795,10 +804,12 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
}
// Compile a list of source files into objects a specified subdirectory
-func compileObjs(ctx ModuleContext, flags builderFlags, subdir string,
- srcFiles, noTidySrcs, timeoutTidySrcs, pathDeps android.Paths, cFlagsDeps android.Paths) Objects {
+func compileObjs(ctx android.ModuleContext, flags builderFlags, subdir string,
+ srcFiles, noTidySrcs, timeoutTidySrcs, pathDeps android.Paths, cFlagsDeps android.Paths,
+ sharedFlags *SharedFlags) Objects {
- return transformSourceToObj(ctx, subdir, srcFiles, noTidySrcs, timeoutTidySrcs, flags, pathDeps, cFlagsDeps)
+ return transformSourceToObj(ctx, subdir, srcFiles, noTidySrcs, timeoutTidySrcs, flags, pathDeps, cFlagsDeps,
+ sharedFlags)
}
// Properties for rust_bindgen related to generating rust bindings.