diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 53bc065f9..58d6ad0ad 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -16,6 +16,7 @@ package cc import ( "path/filepath" + "strings" "android/soong/android" "github.com/google/blueprint" @@ -98,7 +99,23 @@ func (mt *binarySdkMemberType) organizeVariants(member android.SdkMember) *nativ func buildSharedNativeBinarySnapshot(info *nativeBinaryInfo, builder android.SnapshotBuilder, member android.SdkMember) { pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary") - pbm.AddProperty("compile_multilib", "both") + archVariantCount := len(info.archVariantProperties) + + // Choose setting for compile_multilib that is appropriate for the arch variants supplied. + var multilib string + if archVariantCount == 2 { + multilib = "both" + } else if archVariantCount == 1 { + if strings.HasSuffix(info.archVariantProperties[0].archType, "64") { + multilib = "64" + } else { + multilib = "32" + } + } + if multilib != "" { + pbm.AddProperty("compile_multilib", multilib) + } + archProperties := pbm.AddPropertySet("arch") for _, av := range info.archVariantProperties { archTypeProperties := archProperties.AddPropertySet(av.archType) diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 9c8e29206..4d7f943ba 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -749,3 +749,94 @@ include/Test.h -> include/include/Test.h `), ) } + +func TestHostSnapshotWithMultiLib64(t *testing.T) { + // b/145598135 - Generating host snapshots for anything other than linux is not supported. + SkipIfNotLinux(t) + + result := testSdkWithCc(t, ` + module_exports { + name: "myexports", + device_supported: false, + host_supported: true, + target: { + host: { + compile_multilib: "64", + }, + }, + native_static_libs: ["mynativelib"], + } + + cc_library_static { + name: "mynativelib", + device_supported: false, + host_supported: true, + srcs: [ + "Test.cpp", + "aidl/foo/bar/Test.aidl", + ], + export_include_dirs: ["include"], + aidl: { + export_aidl_headers: true, + }, + system_shared_libs: [], + stl: "none", + } + `) + + result.CheckSnapshot("myexports", "linux_glibc_common", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_library_static { + name: "myexports_mynativelib@current", + sdk_member_name: "mynativelib", + device_supported: false, + host_supported: true, + export_include_dirs: ["include/include"], + arch: { + x86_64: { + srcs: ["x86_64/lib/mynativelib.a"], + export_include_dirs: ["x86_64/include_gen/mynativelib"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_static { + name: "mynativelib", + prefer: false, + device_supported: false, + host_supported: true, + export_include_dirs: ["include/include"], + arch: { + x86_64: { + srcs: ["x86_64/lib/mynativelib.a"], + export_include_dirs: ["x86_64/include_gen/mynativelib"], + }, + }, + stl: "none", + system_shared_libs: [], +} + +module_exports_snapshot { + name: "myexports@current", + device_supported: false, + host_supported: true, + target: { + host: { + compile_multilib: "64", + }, + }, + native_static_libs: ["myexports_mynativelib@current"], +}`), + checkAllCopyRules(` +include/Test.h -> include/include/Test.h +.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a +.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h +.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h +.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h +`), + ) +} diff --git a/sdk/update.go b/sdk/update.go index ff567be61..c64995f46 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -107,10 +107,15 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC // The members are first grouped by type and then grouped by name. The order of // the types is the order they are referenced in android.SdkMemberTypesRegistry. // The names are in the order in which the dependencies were added. -func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember { +// +// Returns the members as well as the multilib setting to use. +func (s *sdk) collectMembers(ctx android.ModuleContext) ([]*sdkMember, string) { byType := make(map[android.SdkMemberType][]*sdkMember) byName := make(map[string]*sdkMember) + lib32 := false // True if any of the members have 32 bit version. + lib64 := false // True if any of the members have 64 bit version. + ctx.WalkDeps(func(child android.Module, parent android.Module) bool { tag := ctx.OtherModuleDependencyTag(child) if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok { @@ -122,7 +127,6 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember { } name := ctx.OtherModuleName(child) - member := byName[name] if member == nil { member = &sdkMember{memberType: memberType, name: name} @@ -130,6 +134,13 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember { byType[memberType] = append(byType[memberType], member) } + multilib := child.Target().Arch.ArchType.Multilib + if multilib == "lib32" { + lib32 = true + } else if multilib == "lib64" { + lib64 = true + } + // Only append new variants to the list. This is needed because a member can be both // exported by the sdk and also be a transitive sdk member. member.variants = appendUniqueVariants(member.variants, child.(android.SdkAware)) @@ -148,7 +159,17 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember { members = append(members, membersOfType...) } - return members + // Compute the setting of multilib. + var multilib string + if lib32 && lib64 { + multilib = "both" + } else if lib32 { + multilib = "32" + } else if lib64 { + multilib = "64" + } + + return members, multilib } func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware { @@ -207,7 +228,8 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { } s.builderForTests = builder - for _, member := range s.collectMembers(ctx) { + members, multilib := s.collectMembers(ctx) + for _, member := range members { member.memberType.BuildSnapshot(ctx, builder, member) } @@ -249,6 +271,16 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { } addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule) + + // Compile_multilib defaults to both and must always be set to both on the + // device and so only needs to be set when targeted at the host and is neither + // unspecified or both. + if s.HostSupported() && multilib != "" && multilib != "both" { + targetSet := snapshotModule.AddPropertySet("target") + hostSet := targetSet.AddPropertySet("host") + hostSet.AddProperty("compile_multilib", multilib) + } + for _, memberListProperty := range s.memberListProperties() { names := memberListProperty.getter(s.dynamicMemberTypeListProperties) if len(names) > 0 {