rust: Remove libtest from stdlibs list

libtest does not need to be linked for every module type, so remove it
from the stdlibs list. Instead, link it only when building benchmarks or
tests.

Bug: 193782599
Test: cd external/rust/crates/; mma
Test: Rust tests still run correctly.
Change-Id: I536be8754da0987e09340744d9ebf668b8e734d0
This commit is contained in:
Ivan Lozano 2021-07-15 15:44:10 -04:00
parent 9e3e9c905b
commit 3ee74c8252
5 changed files with 11 additions and 24 deletions

View file

@ -101,6 +101,7 @@ func (benchmark *benchmarkDecorator) compilerFlags(ctx ModuleContext, flags Flag
func (benchmark *benchmarkDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps = benchmark.binaryDecorator.compilerDeps(ctx, deps)
deps.Rustlibs = append(deps.Rustlibs, "libtest")
deps.Rustlibs = append(deps.Rustlibs, "libcriterion")
return deps

View file

@ -29,7 +29,6 @@ var (
DefaultEdition = "2018"
Stdlibs = []string{
"libstd",
"libtest",
}
// Mapping between Soong internal arch types and std::env constants.

View file

@ -169,3 +169,11 @@ func RustTestHostFactory() android.Module {
func (test *testDecorator) stdLinkage(ctx *depsContext) RustLinkage {
return RlibLinkage
}
func (test *testDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps = test.binaryDecorator.compilerDeps(ctx, deps)
deps.Rustlibs = append(deps.Rustlibs, "libtest")
return deps
}

View file

@ -170,12 +170,10 @@ func GatherRequiredDepsForTest() string {
name: "libtest",
crate_name: "test",
srcs: ["foo.rs"],
no_stdlibs: true,
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
min_sdk_version: "29",
}

View file

@ -569,7 +569,6 @@ func TestVendorSnapshotUse(t *testing.T) {
],
rlibs: [
"libstd",
"libtest",
"librust_vendor_available",
],
binaries: [
@ -597,7 +596,6 @@ func TestVendorSnapshotUse(t *testing.T) {
],
rlibs: [
"libstd",
"libtest",
"librust_vendor_available",
],
binaries: [
@ -664,22 +662,6 @@ func TestVendorSnapshotUse(t *testing.T) {
},
}
vendor_snapshot_rlib {
name: "libtest",
version: "30",
target_arch: "arm64",
vendor: true,
sysroot: true,
arch: {
arm64: {
src: "libtest.rlib",
},
arm: {
src: "libtest.rlib",
},
},
}
vendor_snapshot_rlib {
name: "librust_vendor_available",
version: "30",
@ -917,7 +899,6 @@ func TestVendorSnapshotUse(t *testing.T) {
"vendor/lib64.so": nil,
"vendor/liblog.so": nil,
"vendor/libstd.rlib": nil,
"vendor/libtest.rlib": nil,
"vendor/librust_vendor_available.rlib": nil,
"vendor/crtbegin_so.o": nil,
"vendor/crtend_so.o": nil,
@ -962,7 +943,7 @@ func TestVendorSnapshotUse(t *testing.T) {
}
libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64", "libtest.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
}
@ -977,7 +958,7 @@ func TestVendorSnapshotUse(t *testing.T) {
}
libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64", "libtest.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor_rlib.30.arm64.rlib-std", "libstd.vendor_rlib.30.arm64"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
}