summaryrefslogtreecommitdiff
path: root/cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc')
-rw-r--r--cc/Android.bp2
-rw-r--r--cc/bp2build.go182
-rw-r--r--cc/cc.go27
-rw-r--r--cc/cc_test.go79
-rw-r--r--cc/compiler.go20
-rw-r--r--cc/config/global.go4
-rw-r--r--cc/gen.go33
-rw-r--r--cc/library.go95
-rw-r--r--cc/lto.go5
-rw-r--r--cc/sanitize.go6
10 files changed, 351 insertions, 102 deletions
diff --git a/cc/Android.bp b/cc/Android.bp
index be2cc5a34..f49dc1a9e 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -9,6 +9,7 @@ bootstrap_go_package {
"blueprint",
"blueprint-pathtools",
"soong",
+ "soong-aidl-library",
"soong-android",
"soong-bazel",
"soong-cc-config",
@@ -22,7 +23,6 @@ bootstrap_go_package {
srcs: [
"afdo.go",
"fdo_profile.go",
-
"androidmk.go",
"api_level.go",
"bp2build.go",
diff --git a/cc/bp2build.go b/cc/bp2build.go
index cf5f74d4d..fa98df4cd 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -38,6 +38,7 @@ const (
protoSrcPartition = "proto"
aidlSrcPartition = "aidl"
syspropSrcPartition = "sysprop"
+ yaccSrcPartition = "yacc"
stubsSuffix = "_stub_libs_current"
)
@@ -154,6 +155,7 @@ func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.Lab
// know the language of these sources until the genrule is executed.
cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
syspropSrcPartition: bazel.LabelPartition{Extensions: []string{".sysprop"}},
+ yaccSrcPartition: bazel.LabelPartition{Extensions: []string{".y", "yy"}},
}
return bazel.PartitionLabelListAttribute(ctx, &srcs, labels)
@@ -404,6 +406,12 @@ type compilerAttributes struct {
// Sysprop sources
syspropSrcs bazel.LabelListAttribute
+ // Yacc sources
+ yaccSrc *bazel.LabelAttribute
+ yaccFlags bazel.StringListAttribute
+ yaccGenLocationHeader bazel.BoolAttribute
+ yaccGenPositionHeader bazel.BoolAttribute
+
hdrs bazel.LabelListAttribute
rtti bazel.BoolAttribute
@@ -492,7 +500,7 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi
instructionSet := proptools.StringDefault(props.Instruction_set, "")
if instructionSet == "arm" {
- ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm", "-arm_isa_thumb"})
+ ca.features.SetSelectValue(axis, config, []string{"arm_isa_arm"})
} else if instructionSet != "" && instructionSet != "thumb" {
ctx.ModuleErrorf("Unknown value for instruction_set: %s", instructionSet)
}
@@ -566,6 +574,12 @@ func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, i
ca.asmSrcs = partitionedSrcs[asmSrcPartition]
ca.lSrcs = partitionedSrcs[lSrcPartition]
ca.llSrcs = partitionedSrcs[llSrcPartition]
+ if yacc := partitionedSrcs[yaccSrcPartition]; !yacc.IsEmpty() {
+ if len(yacc.Value.Includes) > 1 {
+ ctx.PropertyErrorf("srcs", "Found multiple yacc (.y/.yy) files in library")
+ }
+ ca.yaccSrc = bazel.MakeLabelAttribute(yacc.Value.Includes[0].Label)
+ }
ca.syspropSrcs = partitionedSrcs[syspropSrcPartition]
ca.absoluteIncludes.DeduplicateAxesFromBase()
@@ -728,6 +742,8 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
compilerAttrs := compilerAttributes{}
linkerAttrs := linkerAttributes{}
+ var aidlLibs bazel.LabelList
+
// Iterate through these axes in a deterministic order. This is required
// because processing certain dependencies may result in concatenating
// elements along other axes. (For example, processing NoConfig may result
@@ -742,7 +758,13 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
if baseCompilerProps.Lex != nil {
compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags)
}
+ if baseCompilerProps.Yacc != nil {
+ compilerAttrs.yaccFlags.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Flags)
+ compilerAttrs.yaccGenLocationHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_location_hh)
+ compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh)
+ }
(&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps)
+ aidlLibs.Append(android.BazelLabelForModuleDeps(ctx, baseCompilerProps.Aidl.Libs))
}
var exportHdrs []string
@@ -815,7 +837,15 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
(&linkerAttrs).wholeArchiveDeps.Add(protoDep.wholeStaticLib)
(&linkerAttrs).implementationWholeArchiveDeps.Add(protoDep.implementationWholeStaticLib)
- aidlDep := bp2buildCcAidlLibrary(ctx, module, compilerAttrs.aidlSrcs, linkerAttrs)
+ aidlDep := bp2buildCcAidlLibrary(
+ ctx, module,
+ compilerAttrs.aidlSrcs,
+ bazel.LabelListAttribute{
+ Value: aidlLibs,
+ },
+ linkerAttrs,
+ compilerAttrs,
+ )
if aidlDep != nil {
if lib, ok := module.linker.(*libraryDecorator); ok {
if proptools.Bool(lib.Properties.Aidl.Export_aidl_headers) {
@@ -826,6 +856,12 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
}
}
+ // Create a cc_yacc_static_library if srcs contains .y/.yy files
+ // This internal target will produce an .a file that will be statically linked to the parent library
+ if yaccDep := bp2buildCcYaccLibrary(ctx, compilerAttrs, linkerAttrs); yaccDep != nil {
+ (&linkerAttrs).implementationWholeArchiveDeps.Add(yaccDep)
+ }
+
convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs)
(&compilerAttrs).srcs.Add(&convertedLSrcs.srcName)
(&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName)
@@ -864,6 +900,48 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
}
}
+type ccYaccLibraryAttributes struct {
+ Src bazel.LabelAttribute
+ Flags bazel.StringListAttribute
+ Gen_location_hh bazel.BoolAttribute
+ Gen_position_hh bazel.BoolAttribute
+ Local_includes bazel.StringListAttribute
+ Implementation_deps bazel.LabelListAttribute
+ Implementation_dynamic_deps bazel.LabelListAttribute
+}
+
+func bp2buildCcYaccLibrary(ctx android.Bp2buildMutatorContext, ca compilerAttributes, la linkerAttributes) *bazel.LabelAttribute {
+ if ca.yaccSrc == nil {
+ return nil
+ }
+ yaccLibraryLabel := ctx.Module().Name() + "_yacc"
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_yacc_static_library",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_yacc_library.bzl",
+ },
+ android.CommonAttributes{
+ Name: yaccLibraryLabel,
+ },
+ &ccYaccLibraryAttributes{
+ Src: *ca.yaccSrc,
+ Flags: ca.yaccFlags,
+ Gen_location_hh: ca.yaccGenLocationHeader,
+ Gen_position_hh: ca.yaccGenPositionHeader,
+ Local_includes: ca.localIncludes,
+ Implementation_deps: la.implementationDeps,
+ Implementation_dynamic_deps: la.implementationDynamicDeps,
+ },
+ )
+
+ yaccLibrary := &bazel.LabelAttribute{
+ Value: &bazel.Label{
+ Label: ":" + yaccLibraryLabel,
+ },
+ }
+ return yaccLibrary
+}
+
// As a workaround for b/261657184, we are manually adding the default value
// of system_dynamic_deps for the linux_musl os.
// TODO: Solve this properly
@@ -912,11 +990,16 @@ func bp2buildFdoProfile(
func bp2buildCcAidlLibrary(
ctx android.Bp2buildMutatorContext,
m *Module,
- aidlLabelList bazel.LabelListAttribute,
+ aidlSrcs bazel.LabelListAttribute,
+ aidlLibs bazel.LabelListAttribute,
linkerAttrs linkerAttributes,
+ compilerAttrs compilerAttributes,
) *bazel.LabelAttribute {
- if !aidlLabelList.IsEmpty() {
- aidlLibs, aidlSrcs := aidlLabelList.Partition(func(src bazel.Label) bool {
+ var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute
+ apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
+
+ if !aidlSrcs.IsEmpty() {
+ aidlLibsFromSrcs, aidlFiles = aidlSrcs.Partition(func(src bazel.Label) bool {
if fg, ok := android.ToFileGroupAsLibrary(ctx, src.OriginalModuleName); ok &&
fg.ShouldConvertToAidlLibrary(ctx) {
return true
@@ -924,55 +1007,69 @@ func bp2buildCcAidlLibrary(
return false
})
- apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
- sdkAttrs := bp2BuildParseSdkAttributes(m)
-
- if !aidlSrcs.IsEmpty() {
+ if !aidlFiles.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library"
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "aidl_library",
Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
},
- android.CommonAttributes{Name: aidlLibName},
- &aidlLibraryAttributes{
- Srcs: aidlSrcs,
+ android.CommonAttributes{
+ Name: aidlLibName,
Tags: apexAvailableTags,
},
+ &aidlLibraryAttributes{
+ Srcs: aidlFiles,
+ },
)
- aidlLibs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
+ aidlLibsFromSrcs.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + aidlLibName}})
}
+ }
- if !aidlLibs.IsEmpty() {
- ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
- // Since parent cc_library already has these dependencies, we can add them as implementation
- // deps so that they don't re-export
- implementationDeps := linkerAttrs.deps.Clone()
- implementationDeps.Append(linkerAttrs.implementationDeps)
- implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone()
- implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps)
+ allAidlLibs := aidlLibs.Clone()
+ allAidlLibs.Append(aidlLibsFromSrcs)
- ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "cc_aidl_library",
- Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
- },
- android.CommonAttributes{Name: ccAidlLibrarylabel},
- &ccAidlLibraryAttributes{
- Deps: aidlLibs,
- Implementation_deps: *implementationDeps,
- Implementation_dynamic_deps: *implementationDynamicDeps,
- Tags: apexAvailableTags,
- sdkAttributes: sdkAttrs,
- },
- )
- label := &bazel.LabelAttribute{
- Value: &bazel.Label{
- Label: ":" + ccAidlLibrarylabel,
- },
- }
- return label
+ if !allAidlLibs.IsEmpty() {
+ ccAidlLibrarylabel := m.Name() + "_cc_aidl_library"
+ // Since parent cc_library already has these dependencies, we can add them as implementation
+ // deps so that they don't re-export
+ implementationDeps := linkerAttrs.deps.Clone()
+ implementationDeps.Append(linkerAttrs.implementationDeps)
+ implementationDynamicDeps := linkerAttrs.dynamicDeps.Clone()
+ implementationDynamicDeps.Append(linkerAttrs.implementationDynamicDeps)
+
+ sdkAttrs := bp2BuildParseSdkAttributes(m)
+
+ exportedIncludes := bp2BuildParseExportedIncludes(ctx, m, &compilerAttrs.includes)
+ includeAttrs := includesAttributes{
+ Export_includes: exportedIncludes.Includes,
+ Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
+ Export_system_includes: exportedIncludes.SystemIncludes,
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
}
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "cc_aidl_library",
+ Bzl_load_location: "//build/bazel/rules/cc:cc_aidl_library.bzl",
+ },
+ android.CommonAttributes{Name: ccAidlLibrarylabel},
+ &ccAidlLibraryAttributes{
+ Deps: *allAidlLibs,
+ Implementation_deps: *implementationDeps,
+ Implementation_dynamic_deps: *implementationDynamicDeps,
+ Tags: apexAvailableTags,
+ sdkAttributes: sdkAttrs,
+ includesAttributes: includeAttrs,
+ },
+ )
+ label := &bazel.LabelAttribute{
+ Value: &bazel.Label{
+ Label: ":" + ccAidlLibrarylabel,
+ },
+ }
+ return label
}
return nil
@@ -1169,6 +1266,9 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
}
la.additionalLinkerInputs.SetSelectValue(axis, config, additionalLinkerInputs)
+ if axis == bazel.OsConfigurationAxis && (config == bazel.OsDarwin || config == bazel.OsLinux || config == bazel.OsWindows) {
+ linkerFlags = append(linkerFlags, props.Host_ldlibs...)
+ }
la.linkopts.SetSelectValue(axis, config, linkerFlags)
if axisFeatures != nil {
diff --git a/cc/cc.go b/cc/cc.go
index 7237686e4..f4b565550 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -27,6 +27,7 @@ import (
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
+ "android/soong/aidl_library"
"android/soong/android"
"android/soong/bazel/cquery"
"android/soong/cc/config"
@@ -110,6 +111,9 @@ type Deps struct {
// Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
SystemSharedLibs []string
+ // Used by DepMutator to pass aidl_library modules to aidl compiler
+ AidlLibs []string
+
// If true, statically link the unwinder into native libraries/binaries.
StaticUnwinderIfLegacy bool
@@ -182,6 +186,9 @@ type PathDeps struct {
// For Darwin builds, the path to the second architecture's output that should
// be combined with this architectures's output into a FAT MachO file.
DarwinSecondArchOutput android.OptionalPath
+
+ // Paths to direct srcs and transitive include dirs from direct aidl_library deps
+ AidlLibraryInfos []aidl_library.AidlLibraryInfo
}
// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
@@ -765,6 +772,7 @@ var (
stubImplDepTag = dependencyTag{name: "stub_impl"}
JniFuzzLibTag = dependencyTag{name: "jni_fuzz_lib_tag"}
FdoProfileTag = dependencyTag{name: "fdo_profile"}
+ aidlLibraryTag = dependencyTag{name: "aidl_library"}
)
func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
@@ -2751,6 +2759,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
}
+ if len(deps.AidlLibs) > 0 {
+ actx.AddDependency(
+ c,
+ aidlLibraryTag,
+ deps.AidlLibs...,
+ )
+ }
+
updateImportedLibraryDependency(ctx)
}
@@ -3055,6 +3071,17 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return
}
+ if depTag == aidlLibraryTag {
+ if ctx.OtherModuleHasProvider(dep, aidl_library.AidlLibraryProvider) {
+ depPaths.AidlLibraryInfos = append(
+ depPaths.AidlLibraryInfos,
+ ctx.OtherModuleProvider(
+ dep,
+ aidl_library.AidlLibraryProvider).(aidl_library.AidlLibraryInfo),
+ )
+ }
+ }
+
ccDep, ok := dep.(LinkableInterface)
if !ok {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index f9e661ff2..422df7310 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -24,6 +24,7 @@ import (
"strings"
"testing"
+ "android/soong/aidl_library"
"android/soong/android"
"android/soong/bazel/cquery"
)
@@ -38,6 +39,7 @@ func TestMain(m *testing.M) {
var prepareForCcTest = android.GroupFixturePreparers(
PrepareForTestWithCcIncludeVndk,
+ aidl_library.PrepareForTestWithAidlLibrary,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceVndkVersion = StringPtr("current")
variables.ProductVndkVersion = StringPtr("current")
@@ -4418,9 +4420,65 @@ func TestStubsLibReexportsHeaders(t *testing.T) {
}
}
+func TestAidlLibraryWithHeader(t *testing.T) {
+ t.Parallel()
+ ctx := android.GroupFixturePreparers(
+ prepareForCcTest,
+ aidl_library.PrepareForTestWithAidlLibrary,
+ android.MockFS{
+ "package_bar/Android.bp": []byte(`
+ aidl_library {
+ name: "bar",
+ srcs: ["x/y/Bar.aidl"],
+ strip_import_prefix: "x",
+ }
+ `)}.AddToFixture(),
+ android.MockFS{
+ "package_foo/Android.bp": []byte(`
+ aidl_library {
+ name: "foo",
+ srcs: ["a/b/Foo.aidl"],
+ strip_import_prefix: "a",
+ deps: ["bar"],
+ }
+ cc_library {
+ name: "libfoo",
+ aidl: {
+ libs: ["foo"],
+ }
+ }
+ `),
+ }.AddToFixture(),
+ ).RunTest(t).TestContext
+
+ libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
+ manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))
+ aidlCommand := manifest.Commands[0].GetCommand()
+
+ expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x"
+ if !strings.Contains(aidlCommand, expectedAidlFlags) {
+ t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlags)
+ }
+
+ outputs := strings.Join(libfoo.AllOutputs(), " ")
+
+ android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BpFoo.h")
+ android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BnFoo.h")
+ android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/Foo.h")
+ android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp")
+ // Confirm that the aidl header doesn't get compiled to cpp and h files
+ android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BpBar.h")
+ android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BnBar.h")
+ android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/Bar.h")
+ android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp")
+}
+
func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
t.Parallel()
- ctx := testCc(t, `
+ ctx := android.GroupFixturePreparers(
+ prepareForCcTest,
+ aidl_library.PrepareForTestWithAidlLibrary,
+ ).RunTestWithBp(t, `
cc_library {
name: "libfoo",
srcs: ["a/Foo.aidl"],
@@ -4705,7 +4763,15 @@ func TestIncludeDirsExporting(t *testing.T) {
})
t.Run("ensure only aidl headers are exported", func(t *testing.T) {
- ctx := testCc(t, genRuleModules+`
+ ctx := android.GroupFixturePreparers(
+ prepareForCcTest,
+ aidl_library.PrepareForTestWithAidlLibrary,
+ ).RunTestWithBp(t, `
+ aidl_library {
+ name: "libfoo_aidl",
+ srcs: ["x/y/Bar.aidl"],
+ strip_import_prefix: "x",
+ }
cc_library_shared {
name: "libfoo",
srcs: [
@@ -4714,10 +4780,11 @@ func TestIncludeDirsExporting(t *testing.T) {
"a.proto",
],
aidl: {
+ libs: ["libfoo_aidl"],
export_aidl_headers: true,
}
}
- `)
+ `).TestContext
foo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module()
checkIncludeDirs(t, ctx, foo,
expectedIncludeDirs(`
@@ -4728,11 +4795,17 @@ func TestIncludeDirsExporting(t *testing.T) {
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h
`),
expectedOrderOnlyDeps(`
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h
+ .intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h
`),
)
})
diff --git a/cc/compiler.go b/cc/compiler.go
index 88985b6f9..5da745e02 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -120,6 +120,9 @@ type BaseCompilerProperties struct {
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
@@ -272,6 +275,7 @@ 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.AidlLibs = append(deps.AidlLibs, compiler.Properties.Aidl.Libs...)
android.ProtoDeps(ctx, &compiler.Proto)
if compiler.hasSrcExt(".proto") {
@@ -561,7 +565,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
}
- if compiler.hasSrcExt(".aidl") {
+ 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 +576,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")
}
@@ -660,6 +672,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 +684,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
diff --git a/cc/config/global.go b/cc/config/global.go
index e5ce48ebe..d4106eb18 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -354,14 +354,14 @@ func init() {
// Automatically initialize any uninitialized stack variables.
// Prefer zero-init if multiple options are set.
if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
- flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -Wno-unused-command-line-argument")
+ flags = append(flags, "-ftrivial-auto-var-init=zero")
} else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
flags = append(flags, "-ftrivial-auto-var-init=pattern")
} else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
} else {
// Default to zero initialization.
- flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -Wno-unused-command-line-argument")
+ flags = append(flags, "-ftrivial-auto-var-init=zero")
}
// Workaround for ccache with clang.
diff --git a/cc/gen.go b/cc/gen.go
index dfbb177e6..dbb9560ba 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -18,7 +18,9 @@ import (
"path/filepath"
"strings"
+ "android/soong/aidl_library"
"android/soong/bazel"
+
"github.com/google/blueprint"
"android/soong/android"
@@ -124,11 +126,6 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr
headerBn := outDir.Join(ctx, aidlPackage, "Bn"+shortName+".h")
headerBp := outDir.Join(ctx, aidlPackage, "Bp"+shortName+".h")
- baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel())
- if baseDir != "" {
- aidlFlags += " -I" + baseDir
- }
-
cmd := rule.Command()
cmd.BuiltTool("aidl-cpp").
FlagWithDepFile("-d", depFile).
@@ -282,7 +279,10 @@ type generatedSourceInfo struct {
syspropOrderOnlyDeps android.Paths
}
-func genSources(ctx android.ModuleContext, srcFiles android.Paths,
+func genSources(
+ ctx android.ModuleContext,
+ aidlLibraryInfos []aidl_library.AidlLibraryInfo,
+ srcFiles android.Paths,
buildFlags builderFlags) (android.Paths, android.Paths, generatedSourceInfo) {
var info generatedSourceInfo
@@ -330,7 +330,8 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"),
android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
}
- cppFile, aidlHeaders := genAidl(ctx, aidlRule, srcFile, buildFlags.aidlFlags)
+ baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
+ cppFile, aidlHeaders := genAidl(ctx, aidlRule, srcFile, buildFlags.aidlFlags+" -I"+baseDir)
srcFiles[i] = cppFile
info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
@@ -352,6 +353,24 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
}
}
+ for _, aidlLibraryInfo := range aidlLibraryInfos {
+ for _, aidlSrc := range aidlLibraryInfo.Srcs {
+ if aidlRule == nil {
+ // TODO(b/279960133): Sandbox inputs to ensure aidl headers are explicitly specified
+ aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"),
+ android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
+ }
+ cppFile, aidlHeaders := genAidl(ctx, aidlRule, aidlSrc, buildFlags.aidlFlags)
+
+ srcFiles = append(srcFiles, cppFile)
+ info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
+ // Use the generated headers as order only deps to ensure that they are up to date when
+ // needed.
+ // TODO: Reduce the size of the ninja file by using one order only dep for the whole rule
+ info.aidlOrderOnlyDeps = append(info.aidlOrderOnlyDeps, aidlHeaders...)
+ }
+ }
+
if aidlRule != nil {
aidlRule.Build("aidl", "gen aidl")
}
diff --git a/cc/library.go b/cc/library.go
index 13b333a12..09a7253ab 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -271,7 +271,9 @@ type ccAidlLibraryAttributes struct {
Implementation_deps bazel.LabelListAttribute
Implementation_dynamic_deps bazel.LabelListAttribute
Tags bazel.StringListAttribute
+
sdkAttributes
+ includesAttributes
}
type stripAttributes struct {
@@ -335,6 +337,14 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
Native_coverage: baseAttributes.Native_coverage,
}
+ includeAttrs := includesAttributes{
+ Export_includes: exportedIncludes.Includes,
+ Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
+ Export_system_includes: exportedIncludes.SystemIncludes,
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
+ }
+
sharedCommonAttrs := staticOrSharedAttributes{
Srcs: *srcs.Clone().Append(sharedAttrs.Srcs),
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c),
@@ -356,41 +366,34 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: staticCommonAttrs,
+ includesAttributes: includeAttrs,
Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
- Export_includes: exportedIncludes.Includes,
- Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
- Export_system_includes: exportedIncludes.SystemIncludes,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
- Rtti: compilerAttrs.rtti,
- Stl: compilerAttrs.stl,
- Cpp_std: compilerAttrs.cppStd,
- C_std: compilerAttrs.cStd,
+ Rtti: compilerAttrs.rtti,
+ Stl: compilerAttrs.stl,
+ Cpp_std: compilerAttrs.cppStd,
+ C_std: compilerAttrs.cStd,
Features: *staticFeatures,
}
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
staticOrSharedAttributes: sharedCommonAttrs,
- Cppflags: compilerAttrs.cppFlags,
- Conlyflags: compilerAttrs.conlyFlags,
- Asflags: asFlags,
+ includesAttributes: includeAttrs,
- Export_includes: exportedIncludes.Includes,
- Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
- Export_system_includes: exportedIncludes.SystemIncludes,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
- Linkopts: linkerAttrs.linkopts,
- Rtti: compilerAttrs.rtti,
- Stl: compilerAttrs.stl,
- Cpp_std: compilerAttrs.cppStd,
- C_std: compilerAttrs.cStd,
- Use_version_lib: linkerAttrs.useVersionLib,
+ Cppflags: compilerAttrs.cppFlags,
+ Conlyflags: compilerAttrs.conlyFlags,
+ Asflags: asFlags,
+
+ Linkopts: linkerAttrs.linkopts,
+ Rtti: compilerAttrs.rtti,
+ Stl: compilerAttrs.stl,
+ Cpp_std: compilerAttrs.cppStd,
+ C_std: compilerAttrs.cStd,
+ Use_version_lib: linkerAttrs.useVersionLib,
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
@@ -2114,7 +2117,7 @@ func (library *libraryDecorator) link(ctx ModuleContext,
// Optionally export aidl headers.
if Bool(library.Properties.Aidl.Export_aidl_headers) {
- if library.baseCompiler.hasSrcExt(".aidl") {
+ if library.baseCompiler.hasAidl(deps) {
dir := android.PathForModuleGen(ctx, "aidl")
library.reexportDirs(dir)
@@ -2880,6 +2883,13 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
linkerAttrs := baseAttributes.linkerAttributes
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &compilerAttrs.includes)
+ includeAttrs := includesAttributes{
+ Export_includes: exportedIncludes.Includes,
+ Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
+ Export_system_includes: exportedIncludes.SystemIncludes,
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
+ }
// Append shared/static{} stanza properties. These won't be specified on
// cc_library_* itself, but may be specified in cc_defaults that this module
@@ -2937,11 +2947,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
- Export_includes: exportedIncludes.Includes,
- Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
- Export_system_includes: exportedIncludes.SystemIncludes,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
+ includesAttributes: includeAttrs,
Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags,
@@ -2967,11 +2973,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
- Export_includes: exportedIncludes.Includes,
- Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
- Export_system_includes: exportedIncludes.SystemIncludes,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
+ includesAttributes: includeAttrs,
+
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
@@ -3007,9 +3010,18 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs)
}
+type includesAttributes struct {
+ Export_includes bazel.StringListAttribute
+ Export_absolute_includes bazel.StringListAttribute
+ Export_system_includes bazel.StringListAttribute
+ Local_includes bazel.StringListAttribute
+ Absolute_includes bazel.StringListAttribute
+}
+
// TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibraryStaticAttributes struct {
staticOrSharedAttributes
+ includesAttributes
Use_version_lib bazel.BoolAttribute
Rtti bazel.BoolAttribute
@@ -3017,12 +3029,7 @@ type bazelCcLibraryStaticAttributes struct {
Cpp_std *string
C_std *string
- Export_includes bazel.StringListAttribute
- Export_absolute_includes bazel.StringListAttribute
- Export_system_includes bazel.StringListAttribute
- Local_includes bazel.StringListAttribute
- Absolute_includes bazel.StringListAttribute
- Hdrs bazel.LabelListAttribute
+ Hdrs bazel.LabelListAttribute
Cppflags bazel.StringListAttribute
Conlyflags bazel.StringListAttribute
@@ -3034,6 +3041,7 @@ type bazelCcLibraryStaticAttributes struct {
// TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibrarySharedAttributes struct {
staticOrSharedAttributes
+ includesAttributes
Linkopts bazel.StringListAttribute
Use_version_lib bazel.BoolAttribute
@@ -3043,12 +3051,7 @@ type bazelCcLibrarySharedAttributes struct {
Cpp_std *string
C_std *string
- Export_includes bazel.StringListAttribute
- Export_absolute_includes bazel.StringListAttribute
- Export_system_includes bazel.StringListAttribute
- Local_includes bazel.StringListAttribute
- Absolute_includes bazel.StringListAttribute
- Hdrs bazel.LabelListAttribute
+ Hdrs bazel.LabelListAttribute
Strip stripAttributes
Additional_linker_inputs bazel.LabelListAttribute
diff --git a/cc/lto.go b/cc/lto.go
index 581856b46..1afa1ddd9 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -91,6 +91,11 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
return flags
}
+ // TODO(b/254713216): LTO doesn't work on riscv64 yet.
+ if ctx.Arch().ArchType == android.Riscv64 {
+ return flags
+ }
+
if lto.LTO(ctx) {
var ltoCFlag string
var ltoLdFlag string
diff --git a/cc/sanitize.go b/cc/sanitize.go
index df96b89c8..7fddc1b83 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -653,6 +653,12 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
s.Integer_overflow = nil
}
+ // TODO(b/254713216): CFI doesn't work for riscv64 yet because LTO doesn't work.
+ if ctx.Arch().ArchType == android.Riscv64 {
+ s.Cfi = nil
+ s.Diag.Cfi = nil
+ }
+
// Disable CFI for musl
if ctx.toolchain().Musl() {
s.Cfi = nil