diff --git a/rust/rust_test.go b/rust/rust_test.go index a54615d68..0c8d35586 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "os" "runtime" + "strings" "testing" "android/soong/android" @@ -175,3 +176,28 @@ func TestDepsTracking(t *testing.T) { } } + +// Test to make sure proc_macros use host variants when building device modules. +func TestProcMacroDeviceDeps(t *testing.T) { + ctx := testRust(t, ` + rust_library_host_rlib { + name: "libbar", + srcs: ["foo.rs"], + } + rust_proc_macro { + name: "libpm", + rlibs: ["libbar"], + srcs: ["foo.rs"], + } + rust_binary { + name: "fizz-buzz", + proc_macros: ["libpm"], + srcs: ["foo.rs"], + } + `) + rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc") + + if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") { + t.Errorf("Proc_macro is not using host variant of dependent modules.") + } +} diff --git a/rust/testing.go b/rust/testing.go index a38697f88..92347f1f3 100644 --- a/rust/testing.go +++ b/rust/testing.go @@ -16,6 +16,7 @@ package rust import ( "android/soong/android" + "android/soong/cc" ) func GatherRequiredDepsForTest() string { @@ -70,12 +71,101 @@ func GatherRequiredDepsForTest() string { srcs: [""], host_supported: true, } + + ////////////////////////////// + // Device module requirements + + toolchain_library { + name: "libgcc", + no_libcrt: true, + nocrt: true, + src: "", + system_shared_libs: [], + } + cc_library { + name: "libc", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + } + cc_library { + name: "libm", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + } + cc_library { + name: "libdl", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + } + cc_object { + name: "crtbegin_dynamic", + } + + cc_object { + name: "crtend_android", + } + cc_library { + name: "liblog", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + } + + ////////////////////////////// + // cc module requirements + + toolchain_library { + name: "libatomic", + src: "", + } + toolchain_library { + name: "libclang_rt.builtins-aarch64-android", + src: "", + } + toolchain_library { + name: "libgcc_stripped", + src: "", + } + cc_library { + name: "libc++_static", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + } + cc_library { + name: "libc++demangle", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + host_supported: false, + } + cc_library { + name: "libc++", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + } + cc_library { + name: "libunwind_llvm", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + } ` return bp } func CreateTestContext(bp string) *android.TestContext { ctx := android.NewTestArchContext() + ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) + ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) ctx.RegisterModuleType("rust_binary", android.ModuleFactoryAdaptor(RustBinaryFactory)) ctx.RegisterModuleType("rust_binary_host", android.ModuleFactoryAdaptor(RustBinaryHostFactory)) ctx.RegisterModuleType("rust_library", android.ModuleFactoryAdaptor(RustLibraryFactory)) @@ -86,9 +176,16 @@ func CreateTestContext(bp string) *android.TestContext { ctx.RegisterModuleType("rust_library_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibFactory)) ctx.RegisterModuleType("rust_proc_macro", android.ModuleFactoryAdaptor(ProcMacroFactory)) ctx.RegisterModuleType("rust_prebuilt_dylib", android.ModuleFactoryAdaptor(PrebuiltDylibFactory)) + ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() + + ctx.BottomUp("image", cc.ImageMutator).Parallel() + ctx.BottomUp("link", cc.LinkageMutator).Parallel() + ctx.BottomUp("version", cc.VersionMutator).Parallel() + ctx.BottomUp("begin", cc.BeginMutator).Parallel() }) + bp = bp + GatherRequiredDepsForTest() mockFS := map[string][]byte{