diff --git a/cc/builder.go b/cc/builder.go index 8719d4f87..367bda380 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -798,9 +798,12 @@ func transformObjToStaticLib(ctx android.ModuleContext, // Generate a Rust staticlib from a list of rlibDeps. Returns nil if TransformRlibstoStaticlib is nil or rlibDeps is empty. func generateRustStaticlib(ctx android.ModuleContext, rlibDeps []RustRlibDep) android.Path { if TransformRlibstoStaticlib == nil && len(rlibDeps) > 0 { - // This should only be reachable if a module defines static_rlibs and + // This should only be reachable if a module defines Rust deps in static_libs and // soong-rust hasn't been loaded alongside soong-cc (e.g. in soong-cc tests). - panic(fmt.Errorf("TransformRlibstoStaticlib is not set and static_rlibs is defined in %s", ctx.ModuleName())) + panic(fmt.Errorf( + "TransformRlibstoStaticlib is not set and rust deps are defined in static_libs for %s", + ctx.ModuleName())) + } else if len(rlibDeps) == 0 { return nil } @@ -829,6 +832,7 @@ func generateRustStaticlib(ctx android.ModuleContext, rlibDeps []RustRlibDep) an func genRustStaticlibSrcFile(crateNames []string) string { lines := []string{ "// @Soong generated Source", + "#![no_std]", // pre-emptively set no_std to support both std and no_std. } for _, crate := range crateNames { lines = append(lines, fmt.Sprintf("extern crate %s;", crate)) diff --git a/cc/cc.go b/cc/cc.go index 3a8932cf7..24f6b839c 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -99,7 +99,6 @@ type Deps struct { StaticLibs, LateStaticLibs, WholeStaticLibs []string HeaderLibs []string RuntimeLibs []string - Rlibs []string // UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to // prevent automatically exporting symbols. @@ -746,11 +745,6 @@ func (d libraryDependencyTag) static() bool { return d.Kind == staticLibraryDependency } -// rlib returns true if the libraryDependencyTag is tagging an rlib dependency. -func (d libraryDependencyTag) rlib() bool { - return d.Kind == rlibLibraryDependency -} - func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation { if d.shared() { return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} @@ -917,6 +911,8 @@ type Module struct { hideApexVariantFromMake bool logtagsPaths android.Paths + + WholeRustStaticlib bool } func (c *Module) AddJSONData(d *map[string]interface{}) { @@ -1192,6 +1188,16 @@ func (c *Module) BuildSharedVariant() bool { panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName())) } +func (c *Module) BuildRlibVariant() bool { + // cc modules can never build rlib variants + return false +} + +func (c *Module) IsRustFFI() bool { + // cc modules are not Rust modules + return false +} + func (c *Module) Module() android.Module { return c } @@ -2280,7 +2286,6 @@ func (c *Module) deps(ctx DepsContext) Deps { deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) - deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs) deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs) @@ -2575,28 +2580,20 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { } for _, lib := range deps.StaticLibs { + // Some dependencies listed in static_libs might actually be rust_ffi rlib variants. depTag := libraryDependencyTag{Kind: staticLibraryDependency} + if inList(lib, deps.ReexportStaticLibHeaders) { depTag.reexportFlags = true } if inList(lib, deps.ExcludeLibsForApex) { depTag.excludeInApex = true } - actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "static"}, }, depTag, lib) } - for _, lib := range deps.Rlibs { - depTag := libraryDependencyTag{Kind: rlibLibraryDependency} - actx.AddVariationDependencies([]blueprint.Variation{ - {Mutator: "link", Variation: ""}, - {Mutator: "rust_libraries", Variation: "rlib"}, - {Mutator: "rust_stdlinkage", Variation: "rlib-std"}, - }, depTag, lib) - } - // staticUnwinderDep is treated as staticDep for Q apexes // so that native libraries/binaries are linked with static unwinder // because Q libc doesn't have unwinder APIs @@ -3184,78 +3181,86 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order)) } - case libDepTag.rlib(): - rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()} - depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep) - depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep) - depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...) - depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...) - case libDepTag.static(): - staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider) - if !isStaticLib { - if !ctx.Config().AllowMissingDependencies() { - ctx.ModuleErrorf("module %q is not a static library", depName) - } else { - ctx.AddMissingDependencies([]string{depName}) - } - return - } + if ccDep.RustLibraryInterface() { + rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()} + depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep) + depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...) + if libDepTag.wholeStatic { + depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...) + depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep) - // Stubs lib doesn't link to the static lib dependencies. Don't set - // linkFile, depFile, and ptr. - if c.IsStubs() { - break - } - - linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary) - if libDepTag.wholeStatic { - ptr = &depPaths.WholeStaticLibs - if len(staticLibraryInfo.Objects.objFiles) > 0 { - depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects) - } else { - // This case normally catches prebuilt static - // libraries, but it can also occur when - // AllowMissingDependencies is on and the - // dependencies has no sources of its own - // but has a whole_static_libs dependency - // on a missing library. We want to depend - // on the .a file so that there is something - // in the dependency tree that contains the - // error rule for the missing transitive - // dependency. - depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path()) + // If whole_static, track this as we want to make sure that in a final linkage for a shared library, + // exported functions from the rust generated staticlib still exported. + if c.CcLibrary() && c.Shared() { + c.WholeRustStaticlib = true + } } - depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, - staticLibraryInfo.WholeStaticLibsFromPrebuilts...) + } else { - switch libDepTag.Order { - case earlyLibraryDependency: - panic(fmt.Errorf("early static libs not suppported")) - case normalLibraryDependency: - // static dependencies will be handled separately so they can be ordered - // using transitive dependencies. - ptr = nil - directStaticDeps = append(directStaticDeps, staticLibraryInfo) - case lateLibraryDependency: - ptr = &depPaths.LateStaticLibs - default: - panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order)) + staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider) + if !isStaticLib { + if !ctx.Config().AllowMissingDependencies() { + ctx.ModuleErrorf("module %q is not a static library", depName) + } else { + ctx.AddMissingDependencies([]string{depName}) + } + return } - } - // We re-export the Rust static_rlibs so rlib dependencies don't need to be redeclared by cc_library_static dependents. - // E.g. libfoo (cc_library_static) depends on libfoo.ffi (a rust_ffi rlib), libbar depending on libfoo shouldn't have to also add libfoo.ffi to static_rlibs. - depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, depExporterInfo.RustRlibDeps...) - depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...) + // Stubs lib doesn't link to the static lib dependencies. Don't set + // linkFile, depFile, and ptr. + if c.IsStubs() { + break + } - if libDepTag.unexportedSymbols { - depPaths.LdFlags = append(depPaths.LdFlags, - "-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base()) + linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary) + if libDepTag.wholeStatic { + ptr = &depPaths.WholeStaticLibs + if len(staticLibraryInfo.Objects.objFiles) > 0 { + depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects) + } else { + // This case normally catches prebuilt static + // libraries, but it can also occur when + // AllowMissingDependencies is on and the + // dependencies has no sources of its own + // but has a whole_static_libs dependency + // on a missing library. We want to depend + // on the .a file so that there is something + // in the dependency tree that contains the + // error rule for the missing transitive + // dependency. + depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path()) + } + depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, + staticLibraryInfo.WholeStaticLibsFromPrebuilts...) + } else { + switch libDepTag.Order { + case earlyLibraryDependency: + panic(fmt.Errorf("early static libs not supported")) + case normalLibraryDependency: + // static dependencies will be handled separately so they can be ordered + // using transitive dependencies. + ptr = nil + directStaticDeps = append(directStaticDeps, staticLibraryInfo) + case lateLibraryDependency: + ptr = &depPaths.LateStaticLibs + default: + panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order)) + } + } + + // Collect any exported Rust rlib deps from static libraries which have been included as whole_static_libs + depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...) + + if libDepTag.unexportedSymbols { + depPaths.LdFlags = append(depPaths.LdFlags, + "-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base()) + } } } - if libDepTag.static() && !libDepTag.wholeStatic { + if libDepTag.static() && !libDepTag.wholeStatic && !ccDep.RustLibraryInterface() { if !ccDep.CcLibraryInterface() || !ccDep.Static() { ctx.ModuleErrorf("module %q not a static library", depName) return @@ -3342,12 +3347,14 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { c.Properties.AndroidMkSharedLibs = append( c.Properties.AndroidMkSharedLibs, makeLibName) case libDepTag.static(): - if libDepTag.wholeStatic { - c.Properties.AndroidMkWholeStaticLibs = append( - c.Properties.AndroidMkWholeStaticLibs, makeLibName) - } else { - c.Properties.AndroidMkStaticLibs = append( - c.Properties.AndroidMkStaticLibs, makeLibName) + if !ccDep.RustLibraryInterface() { + if libDepTag.wholeStatic { + c.Properties.AndroidMkWholeStaticLibs = append( + c.Properties.AndroidMkWholeStaticLibs, makeLibName) + } else { + c.Properties.AndroidMkStaticLibs = append( + c.Properties.AndroidMkStaticLibs, makeLibName) + } } } } else if !c.IsStubs() { diff --git a/cc/compiler.go b/cc/compiler.go index 0f6ef9699..03f9899d8 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -794,9 +794,6 @@ type RustBindgenClangProperties struct { // be added to the include path using -I Local_include_dirs []string `android:"arch_variant,variant_prepend"` - // list of Rust static libraries. - Static_rlibs []string `android:"arch_variant,variant_prepend"` - // list of static libraries that provide headers for this binding. Static_libs []string `android:"arch_variant,variant_prepend"` diff --git a/cc/library.go b/cc/library.go index e49f50cc0..4373b46b4 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1135,8 +1135,12 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) - if generatedLib := generateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil { - deps.StaticLibs = append(deps.StaticLibs, generatedLib) + if generatedLib := generateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil && !library.buildStubs() { + if ctx.Module().(*Module).WholeRustStaticlib { + deps.WholeStaticLibs = append(deps.WholeStaticLibs, generatedLib) + } else { + deps.StaticLibs = append(deps.StaticLibs, generatedLib) + } } transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, @@ -2149,7 +2153,6 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { modules := mctx.CreateLocalVariations(variations...) static := modules[0].(LinkableInterface) shared := modules[1].(LinkableInterface) - static.SetStatic() shared.SetShared() @@ -2173,6 +2176,12 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) { mctx.CreateLocalVariations(variations...) mctx.AliasVariation(variations[0]) } + if library.BuildRlibVariant() && library.IsRustFFI() && !buildStatic { + // Rust modules do not build static libs, but rlibs are used as if they + // were via `static_libs`. Thus we need to alias the BuildRlibVariant + // to "static" for Rust FFI libraries. + mctx.CreateAliasVariation("static", "") + } } } diff --git a/cc/linkable.go b/cc/linkable.go index 2309fe800..1672366a7 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -94,12 +94,16 @@ type LinkableInterface interface { SelectedStl() string BuildStaticVariant() bool + BuildRlibVariant() bool BuildSharedVariant() bool SetStatic() SetShared() IsPrebuilt() bool Toc() android.OptionalPath + // IsRustFFI returns true if this is a Rust FFI library. + IsRustFFI() bool + // IsFuzzModule returns true if this a *_fuzz module. IsFuzzModule() bool diff --git a/cc/linker.go b/cc/linker.go index 1675df698..d2974c204 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -39,9 +39,6 @@ type BaseLinkerProperties struct { // the dependency's .a file will be linked into this module using -Wl,--whole-archive. Whole_static_libs []string `android:"arch_variant,variant_prepend"` - // list of Rust libs that should be statically linked into this module. - Static_rlibs []string `android:"arch_variant"` - // list of modules that should be statically linked into this module. Static_libs []string `android:"arch_variant,variant_prepend"` @@ -127,10 +124,6 @@ type BaseLinkerProperties struct { // variant of the C/C++ module. Header_libs []string - // list of Rust libs that should be statically linked to build vendor or product - // variant. - Static_rlibs []string - // list of shared libs that should not be used to build vendor or // product variant of the C/C++ module. Exclude_shared_libs []string @@ -159,10 +152,6 @@ type BaseLinkerProperties struct { // variant of the C/C++ module. Static_libs []string - // list of Rust libs that should be statically linked to build the recovery - // variant. - Static_rlibs []string - // list of shared libs that should not be used to build // the recovery variant of the C/C++ module. Exclude_shared_libs []string @@ -184,10 +173,6 @@ type BaseLinkerProperties struct { // variant of the C/C++ module. Static_libs []string - // list of Rust libs that should be statically linked to build the ramdisk - // variant. - Static_rlibs []string - // list of shared libs that should not be used to build // the ramdisk variant of the C/C++ module. Exclude_shared_libs []string @@ -205,10 +190,6 @@ type BaseLinkerProperties struct { // the vendor ramdisk variant of the C/C++ module. Exclude_shared_libs []string - // list of Rust libs that should be statically linked to build the vendor ramdisk - // variant. - Static_rlibs []string - // list of static libs that should not be used to build // the vendor ramdisk variant of the C/C++ module. Exclude_static_libs []string @@ -224,10 +205,6 @@ type BaseLinkerProperties struct { // variants. Shared_libs []string - // list of Rust libs that should be statically linked to build the vendor ramdisk - // variant. - Static_rlibs []string - // list of ehader libs that only should be used to build platform variant of // the C/C++ module. Header_libs []string @@ -322,7 +299,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...) deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...) deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Static_rlibs...) deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...) deps.RuntimeLibs = append(deps.RuntimeLibs, linker.Properties.Runtime_libs...) @@ -366,7 +342,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor.Exclude_static_libs) deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs) deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor.Exclude_runtime_libs) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Vendor.Static_rlibs...) } if ctx.inProduct() { @@ -380,7 +355,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Product.Exclude_static_libs) deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Product.Exclude_static_libs) deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Product.Exclude_runtime_libs) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Product.Static_rlibs...) } if ctx.inRecovery() { @@ -394,7 +368,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Recovery.Exclude_static_libs) deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs) deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Recovery.Exclude_runtime_libs) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Recovery.Static_rlibs...) } if ctx.inRamdisk() { @@ -405,7 +378,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Ramdisk.Exclude_static_libs) deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Ramdisk.Exclude_static_libs) deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Ramdisk.Exclude_runtime_libs) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Ramdisk.Static_rlibs...) } if ctx.inVendorRamdisk() { @@ -415,7 +387,6 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs) deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_static_libs) deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor_ramdisk.Exclude_runtime_libs) - deps.Rlibs = append(deps.Rlibs, linker.Properties.Target.Vendor_ramdisk.Static_rlibs...) } if !ctx.useSdk() { diff --git a/rust/binary.go b/rust/binary.go index 996951366..cba29a023 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -134,6 +134,9 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path ret := buildOutput{outputFile: outputFile} crateRootPath := crateRootPath(ctx, binary) + // Ensure link dirs are not duplicated + deps.linkDirs = android.FirstUniqueStrings(deps.linkDirs) + flags.RustFlags = append(flags.RustFlags, deps.depFlags...) flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...) flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...) diff --git a/rust/builder_test.go b/rust/builder_test.go index c093ac4df..ae5ccde27 100644 --- a/rust/builder_test.go +++ b/rust/builder_test.go @@ -65,6 +65,11 @@ func TestCompilationOutputFiles(t *testing.T) { crate_name: "rust_ffi", srcs: ["lib.rs"], } + rust_ffi_static { + name: "librust_ffi_static", + crate_name: "rust_ffi", + srcs: ["lib.rs"], + } `) testcases := []struct { testName string @@ -118,14 +123,14 @@ func TestCompilationOutputFiles(t *testing.T) { }, }, { - testName: "rust_ffi static", - moduleName: "librust_ffi", - variant: "android_arm64_armv8-a_static", + testName: "rust_ffi_static rlib", + moduleName: "librust_ffi_static", + variant: "android_arm64_armv8-a_rlib_rlib-std", expectedFiles: []string{ - "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/librust_ffi.a", - "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/librust_ffi.a.clippy", - "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/meta_lic", - "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_static/rustdoc.timestamp", + "out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/librust_ffi_static.rlib", + "out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/librust_ffi_static.rlib.clippy", + "out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/meta_lic", + "out/soong/.intermediates/librust_ffi_static/android_arm64_armv8-a_rlib_rlib-std/rustdoc.timestamp", }, }, { @@ -148,6 +153,7 @@ func TestCompilationOutputFiles(t *testing.T) { "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so", "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/unstripped/librust_ffi.so.toc", "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/meta_lic", + "out/soong/.intermediates/librust_ffi/android_arm64_armv8-a_shared/rustdoc.timestamp", "out/soong/target/product/test_device/system/lib64/librust_ffi.so", }, }, diff --git a/rust/fuzz_test.go b/rust/fuzz_test.go index 0d4622a7e..6cb8b9319 100644 --- a/rust/fuzz_test.go +++ b/rust/fuzz_test.go @@ -114,17 +114,23 @@ func TestCCFuzzDepBundling(t *testing.T) { srcs: ["foo.rs"], shared_libs: ["libcc_transitive_dep"], } + rust_ffi_static { + name: "libtest_fuzzing_static", + crate_name: "test_fuzzing", + srcs: ["foo.rs"], + shared_libs: ["libcc_transitive_dep"], + } cc_fuzz { name: "fuzz_shared_libtest", shared_libs: ["libtest_fuzzing"], } cc_fuzz { name: "fuzz_static_libtest", - static_rlibs: ["libtest_fuzzing"], + static_libs: ["libtest_fuzzing"], } cc_fuzz { name: "fuzz_staticffi_libtest", - static_libs: ["libtest_fuzzing"], + static_libs: ["libtest_fuzzing_static"], } `) diff --git a/rust/image_test.go b/rust/image_test.go index 71e271c89..d84eb10c5 100644 --- a/rust/image_test.go +++ b/rust/image_test.go @@ -22,18 +22,20 @@ import ( "android/soong/cc" ) -// Test that cc modules can link against vendor_available rust_ffi_rlib/rust_ffi_static libraries. +// Test that cc modules can depend on vendor_available rust_ffi_rlib/rust_ffi_static libraries. func TestVendorLinkage(t *testing.T) { ctx := testRust(t, ` cc_binary { name: "fizz_vendor_available", - static_libs: ["libfoo_vendor_static"], - static_rlibs: ["libfoo_vendor"], + static_libs: [ + "libfoo_vendor", + "libfoo_vendor_static" + ], vendor_available: true, } cc_binary { name: "fizz_soc_specific", - static_rlibs: ["libfoo_vendor"], + static_libs: ["libfoo_vendor"], soc_specific: true, } rust_ffi_rlib { @@ -52,8 +54,8 @@ func TestVendorLinkage(t *testing.T) { vendorBinary := ctx.ModuleForTests("fizz_vendor_available", "android_vendor_arm64_armv8-a").Module().(*cc.Module) - if !android.InList("libfoo_vendor_static.vendor", vendorBinary.Properties.AndroidMkStaticLibs) { - t.Errorf("vendorBinary should have a dependency on libfoo_vendor_static.vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs) + if android.InList("libfoo_vendor_static.vendor", vendorBinary.Properties.AndroidMkStaticLibs) { + t.Errorf("vendorBinary should not have a staticlib dependency on libfoo_vendor_static.vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs) } } @@ -110,8 +112,10 @@ func TestVendorRamdiskLinkage(t *testing.T) { ctx := testRust(t, ` cc_library_shared { name: "libcc_vendor_ramdisk", - static_rlibs: ["libfoo_vendor_ramdisk"], - static_libs: ["libfoo_static_vendor_ramdisk"], + static_libs: [ + "libfoo_vendor_ramdisk", + "libfoo_static_vendor_ramdisk" + ], system_shared_libs: [], vendor_ramdisk_available: true, } @@ -131,8 +135,8 @@ func TestVendorRamdiskLinkage(t *testing.T) { vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_shared").Module().(*cc.Module) - if !android.InList("libfoo_static_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) { - t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_static_vendor_ramdisk") + if android.InList("libfoo_static_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) { + t.Errorf("libcc_vendor_ramdisk should not have a dependency on the libfoo_static_vendor_ramdisk static library") } } diff --git a/rust/library.go b/rust/library.go index 2a21263bd..96c02c832 100644 --- a/rust/library.go +++ b/rust/library.go @@ -43,9 +43,9 @@ func init() { android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory) // TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib - // Alias rust_ffi_static to the combined rust_ffi_rlib factory - android.RegisterModuleType("rust_ffi_static", RustFFIStaticRlibFactory) - android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticRlibHostFactory) + // Alias rust_ffi_static to the rust_ffi_rlib factory + android.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory) + android.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory) } type VariantLibraryProperties struct { @@ -353,7 +353,7 @@ func RustFFISharedHostFactory() android.Module { // type "rlib"). func RustFFIRlibHostFactory() android.Module { module, library := NewRustLibrary(android.HostSupported) - library.BuildOnlyRlibStatic() + library.BuildOnlyRlib() library.isFFI = true return module.Init() @@ -368,30 +368,12 @@ func RustFFIRlibFactory() android.Module { return module.Init() } -// rust_ffi_static produces a staticlib and an rlib variant -func RustFFIStaticRlibFactory() android.Module { - module, library := NewRustLibrary(android.HostAndDeviceSupported) - library.BuildOnlyRlibStatic() - - library.isFFI = true - return module.Init() -} - -// rust_ffi_static_host produces a staticlib and an rlib variant for the host -func RustFFIStaticRlibHostFactory() android.Module { - module, library := NewRustLibrary(android.HostSupported) - library.BuildOnlyRlibStatic() - - library.isFFI = true - return module.Init() -} - func (library *libraryDecorator) BuildOnlyFFI() { library.MutatedProperties.BuildDylib = false // we build rlibs for later static ffi linkage. library.MutatedProperties.BuildRlib = true library.MutatedProperties.BuildShared = true - library.MutatedProperties.BuildStatic = true + library.MutatedProperties.BuildStatic = false library.isFFI = true } @@ -417,14 +399,6 @@ func (library *libraryDecorator) BuildOnlyRlib() { library.MutatedProperties.BuildStatic = false } -func (library *libraryDecorator) BuildOnlyRlibStatic() { - library.MutatedProperties.BuildDylib = false - library.MutatedProperties.BuildRlib = true - library.MutatedProperties.BuildShared = false - library.MutatedProperties.BuildStatic = true - library.isFFI = true -} - func (library *libraryDecorator) BuildOnlyStatic() { library.MutatedProperties.BuildRlib = false library.MutatedProperties.BuildDylib = false @@ -766,10 +740,13 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { // The order of the variations (modules) matches the variant names provided. Iterate // through the new variation modules and set their mutated properties. + var emptyVariant = false + var rlibVariant = false for i, v := range modules { switch variants[i] { case rlibVariation: v.(*Module).compiler.(libraryInterface).setRlib() + rlibVariant = true case dylibVariation: v.(*Module).compiler.(libraryInterface).setDylib() if v.(*Module).ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation { @@ -784,11 +761,19 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { // Disable the compilation steps. v.(*Module).compiler.SetDisabled() case "": - // if there's an empty variant, alias it so it is the default variant - mctx.AliasVariation("") + emptyVariant = true } } + if rlibVariant && library.isFFILibrary() { + // If an rlib variant is set and this is an FFI library, make it the + // default variant so CC can link against it appropriately. + mctx.AliasVariation(rlibVariation) + } else if emptyVariant { + // If there's an empty variant, alias it so it is the default variant + mctx.AliasVariation("") + } + // If a source variant is created, add an inter-variant dependency // between the other variants and the source variant. if sourceVariant { @@ -817,6 +802,7 @@ func LibstdMutator(mctx android.BottomUpMutatorContext) { rlib := modules[0].(*Module) rlib.compiler.(libraryInterface).setRlibStd() rlib.Properties.RustSubName += RlibStdlibSuffix + mctx.AliasVariation("rlib-std") } else { variants := []string{"rlib-std", "dylib-std"} modules := mctx.CreateLocalVariations(variants...) diff --git a/rust/library_test.go b/rust/library_test.go index 1133c28ed..35a420cd5 100644 --- a/rust/library_test.go +++ b/rust/library_test.go @@ -34,10 +34,14 @@ func TestLibraryVariants(t *testing.T) { name: "libfoo.ffi", srcs: ["foo.rs"], crate_name: "foo" + } + rust_ffi_host_static { + name: "libfoo.ffi_static", + srcs: ["foo.rs"], + crate_name: "foo" }`) // Test all variants are being built. - libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static").Rule("rustc") libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc") libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc") @@ -46,7 +50,6 @@ func TestLibraryVariants(t *testing.T) { rlibCrateType := "rlib" dylibCrateType := "dylib" sharedCrateType := "cdylib" - staticCrateType := "staticlib" // Test crate type for rlib is correct. if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) { @@ -58,11 +61,6 @@ func TestLibraryVariants(t *testing.T) { t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"]) } - // Test crate type for C static libraries is correct. - if !strings.Contains(libfooStatic.Args["rustcFlags"], "crate-type="+staticCrateType) { - t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.Args["rustcFlags"]) - } - // Test crate type for FFI rlibs is correct if !strings.Contains(libfooFFIRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) { t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooFFIRlib.Args["rustcFlags"]) @@ -188,23 +186,18 @@ func TestSharedLibraryToc(t *testing.T) { func TestStaticLibraryLinkage(t *testing.T) { ctx := testRust(t, ` - rust_ffi { + rust_ffi_static { name: "libfoo", srcs: ["foo.rs"], crate_name: "foo", }`) libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_rlib-std") - libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static") if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkRlibs) { t.Errorf("Static libstd rlib expected to be a dependency of Rust rlib libraries. Rlib deps are: %#v", libfoo.Module().(*Module).Properties.AndroidMkDylibs) } - if !android.InList("libstd", libfooStatic.Module().(*Module).Properties.AndroidMkRlibs) { - t.Errorf("Static libstd rlib expected to be a dependency of Rust static libraries. Rlib deps are: %#v", - libfoo.Module().(*Module).Properties.AndroidMkDylibs) - } } func TestNativeDependencyOfRlib(t *testing.T) { @@ -215,39 +208,31 @@ func TestNativeDependencyOfRlib(t *testing.T) { rlibs: ["librust_rlib"], srcs: ["foo.rs"], } - rust_ffi_static { - name: "libffi_static", - crate_name: "ffi_static", - rlibs: ["librust_rlib"], - srcs: ["foo.rs"], - } rust_library_rlib { name: "librust_rlib", crate_name: "rust_rlib", srcs: ["foo.rs"], - shared_libs: ["shared_cc_dep"], - static_libs: ["static_cc_dep"], + shared_libs: ["libshared_cc_dep"], + static_libs: ["libstatic_cc_dep"], } cc_library_shared { - name: "shared_cc_dep", + name: "libshared_cc_dep", srcs: ["foo.cpp"], } cc_library_static { - name: "static_cc_dep", + name: "libstatic_cc_dep", srcs: ["foo.cpp"], } `) rustRlibRlibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_rlib-std") rustRlibDylibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_dylib-std") - ffiStatic := ctx.ModuleForTests("libffi_static", "android_arm64_armv8-a_static") ffiRlib := ctx.ModuleForTests("libffi_rlib", "android_arm64_armv8-a_rlib_rlib-std") modules := []android.TestingModule{ rustRlibRlibStd, rustRlibDylibStd, ffiRlib, - ffiStatic, } // librust_rlib specifies -L flag to cc deps output directory on rustc command @@ -258,17 +243,17 @@ func TestNativeDependencyOfRlib(t *testing.T) { // TODO: We could consider removing these flags for _, module := range modules { if !strings.Contains(module.Rule("rustc").Args["libFlags"], - "-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared/") { + "-L out/soong/.intermediates/libshared_cc_dep/android_arm64_armv8-a_shared/") { t.Errorf( - "missing -L flag for shared_cc_dep, rustcFlags: %#v", - rustRlibRlibStd.Rule("rustc").Args["libFlags"], + "missing -L flag for libshared_cc_dep of %s, rustcFlags: %#v", + module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"], ) } if !strings.Contains(module.Rule("rustc").Args["libFlags"], - "-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static/") { + "-L out/soong/.intermediates/libstatic_cc_dep/android_arm64_armv8-a_static/") { t.Errorf( - "missing -L flag for static_cc_dep, rustcFlags: %#v", - rustRlibRlibStd.Rule("rustc").Args["libFlags"], + "missing -L flag for libstatic_cc_dep of %s, rustcFlags: %#v", + module.Module().Name(), rustRlibRlibStd.Rule("rustc").Args["libFlags"], ) } } @@ -305,15 +290,23 @@ func TestAutoDeps(t *testing.T) { "libbar", "librlib_only", ], + } + rust_ffi_host_static { + name: "libfoo.ffi.static", + srcs: ["foo.rs"], + crate_name: "foo", + rustlibs: [ + "libbar", + "librlib_only", + ], }`) libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib_rlib-std") libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib") libfooFFIRlib := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_rlib_rlib-std") - libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static") libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared") - for _, static := range []android.TestingModule{libfooRlib, libfooStatic, libfooFFIRlib} { + for _, static := range []android.TestingModule{libfooRlib, libfooFFIRlib} { if !android.InList("libbar.rlib-std", static.Module().(*Module).Properties.AndroidMkRlibs) { t.Errorf("libbar not present as rlib dependency in static lib: %s", static.Module().Name()) } @@ -381,6 +374,12 @@ func TestLibstdLinkage(t *testing.T) { crate_name: "bar", rustlibs: ["libfoo"], } + rust_ffi_static { + name: "libbar_static", + srcs: ["foo.rs"], + crate_name: "bar", + rustlibs: ["libfoo"], + } rust_ffi { name: "libbar.prefer_rlib", srcs: ["foo.rs"], @@ -394,7 +393,6 @@ func TestLibstdLinkage(t *testing.T) { libfooRlibDynamic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module) libbarShared := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module().(*Module) - libbarStatic := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Module().(*Module) libbarFFIRlib := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_rlib_rlib-std").Module().(*Module) // prefer_rlib works the same for both rust_library and rust_ffi, so a single check is sufficient here. @@ -413,12 +411,6 @@ func TestLibstdLinkage(t *testing.T) { if !android.InList("libstd", libbarShared.Properties.AndroidMkDylibs) { t.Errorf("Device rust_ffi_shared does not link libstd as an dylib") } - if !android.InList("libstd", libbarStatic.Properties.AndroidMkRlibs) { - t.Errorf("Device rust_ffi_static does not link libstd as an rlib") - } - if !android.InList("libfoo.rlib-std", libbarStatic.Properties.AndroidMkRlibs) { - t.Errorf("Device rust_ffi_static does not link dependent rustlib rlib-std variant") - } if !android.InList("libstd", libbarFFIRlib.Properties.AndroidMkRlibs) { t.Errorf("Device rust_ffi_rlib does not link libstd as an rlib") } diff --git a/rust/rust.go b/rust/rust.go index 3a3ca4d33..6b7b2fbae 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -420,7 +420,7 @@ type PathDeps struct { depFlags []string depLinkFlags []string - // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. + // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker // Both of these are exported and propagate to dependencies. linkDirs []string linkObjects []string @@ -442,9 +442,6 @@ type PathDeps struct { // Paths to generated source files SrcDeps android.Paths srcProviderFiles android.Paths - - // Used by Generated Libraries - depExportedRlibs []cc.RustRlibDep } type RustLibraries []RustLibrary @@ -465,6 +462,7 @@ type xref interface { type flagExporter struct { linkDirs []string + ccLinkDirs []string linkObjects []string } @@ -658,6 +656,24 @@ func (mod *Module) BuildStaticVariant() bool { panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) } +func (mod *Module) BuildRlibVariant() bool { + if mod.compiler != nil { + if library, ok := mod.compiler.(libraryInterface); ok { + return library.buildRlib() + } + } + panic(fmt.Errorf("BuildRlibVariant called on non-library module: %q", mod.BaseModuleName())) +} + +func (mod *Module) IsRustFFI() bool { + if mod.compiler != nil { + if library, ok := mod.compiler.(libraryInterface); ok { + return library.isFFILibrary() + } + } + return false +} + func (mod *Module) BuildSharedVariant() bool { if mod.compiler != nil { if library, ok := mod.compiler.(libraryInterface); ok { @@ -1237,7 +1253,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { ctx.VisitDirectDeps(func(dep android.Module) { depName := ctx.OtherModuleName(dep) depTag := ctx.OtherModuleDependencyTag(dep) - if _, exists := skipModuleList[depName]; exists { return } @@ -1250,8 +1265,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { //Handle Rust Modules makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName) - switch depTag { - case dylibDepTag: + switch { + case depTag == dylibDepTag: dylib, ok := rustDep.compiler.(libraryInterface) if !ok || !dylib.dylib() { ctx.ModuleErrorf("mod %q not an dylib library", depName) @@ -1261,8 +1276,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName)) - case rlibDepTag: - + case depTag == rlibDepTag: rlib, ok := rustDep.compiler.(libraryInterface) if !ok || !rlib.rlib() { ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) @@ -1277,16 +1291,25 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path())) - case procMacroDepTag: + case depTag == procMacroDepTag: directProcMacroDeps = append(directProcMacroDeps, rustDep) mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) // proc_macro link dirs need to be exported, so collect those here. depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(rustDep.OutputFile().Path())) - case sourceDepTag: + case depTag == sourceDepTag: if _, ok := mod.sourceProvider.(*protobufDecorator); ok { collectIncludedProtos(mod, rustDep) } + case cc.IsStaticDepTag(depTag): + // Rust FFI rlibs should not be declared in a Rust modules + // "static_libs" list as we can't handle them properly at the + // moment (for example, they only produce an rlib-std variant). + // Instead, a normal rust_library variant should be used. + ctx.PropertyErrorf("static_libs", + "found '%s' in static_libs; use a rust_library module in rustlibs instead of a rust_ffi module in static_libs", + depName) + } transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs) diff --git a/rust/rust_test.go b/rust/rust_test.go index 8b96df8b3..0d005d0a2 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -447,23 +447,30 @@ func TestRustRlibs(t *testing.T) { export_include_dirs: ["foo_includes"] } + rust_ffi_rlib { + name: "libbuzz", + crate_name: "buzz", + srcs: ["src/lib.rs"], + export_include_dirs: ["buzz_includes"] + } + cc_library_shared { name: "libcc_shared", srcs:["foo.c"], - static_rlibs: ["libbar"], + static_libs: ["libbar"], } cc_library_static { name: "libcc_static", srcs:["foo.c"], - static_rlibs: ["libfoo"], + static_libs: ["libbuzz"], + whole_static_libs: ["libfoo"], } cc_binary { name: "ccBin", srcs:["foo.c"], - static_rlibs: ["libbar"], - static_libs: ["libcc_static"], + static_libs: ["libcc_static", "libbar"], } `) @@ -514,10 +521,13 @@ func TestRustRlibs(t *testing.T) { "-Ibar_includes", ccbin_cc.Args) } - // Make sure that direct dependencies and indirect dependencies are + // Make sure that direct dependencies and indirect whole static dependencies are // propagating correctly to the generated rlib. if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern foo=") { - t.Errorf("Missing indirect dependency libfoo when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"]) + t.Errorf("Missing indirect whole_static_lib dependency libfoo when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"]) + } + if strings.Contains(ccbin_rustc.Args["libFlags"], "--extern buzz=") { + t.Errorf("Indirect static_lib dependency libbuzz found when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"]) } if !strings.Contains(ccbin_rustc.Args["libFlags"], "--extern bar=") { t.Errorf("Missing direct dependency libbar when writing generated Rust staticlib: %#v", ccbin_rustc.Args["libFlags"]) diff --git a/rust/testing.go b/rust/testing.go index f31c59188..6ee49a971 100644 --- a/rust/testing.go +++ b/rust/testing.go @@ -189,11 +189,11 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) { ctx.RegisterModuleType("rust_ffi", RustFFIFactory) ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory) ctx.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory) - ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticRlibFactory) + ctx.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory) ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory) ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory) ctx.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory) - ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticRlibHostFactory) + ctx.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory) ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory) ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)