rust: Support new rust_stdlib_prebuilt_host type
Refactor Rust prebuilts to support the new rust_stdlib_prebuilt_host
module type, and change the format for depending on the prebuilt host
stdlibs.
Bug: 140642453
Test: m
Change-Id: Ifbc4741818777934e917631c788b20911856c44a
diff --git a/rust/androidmk.go b/rust/androidmk.go
index 7eb5dbd..c9f6486 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -147,6 +147,7 @@
}
})
}
+
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
ctx.SubAndroidMk(ret, procMacro.baseCompiler)
diff --git a/rust/compiler.go b/rust/compiler.go
index 293b17b..3040e5d 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -363,9 +363,9 @@
if !Bool(compiler.Properties.No_stdlibs) {
for _, stdlib := range config.Stdlibs {
- // If we're building for the primary arch of the build host, use the compiler's stdlibs
+ // If we're building for the build host, use the prebuilt stdlibs
if ctx.Target().Os == ctx.Config().BuildOS {
- stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
+ stdlib = "prebuilt_" + stdlib
}
deps.Stdlibs = append(deps.Stdlibs, stdlib)
}
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
index 6099eec..6f17272 100644
--- a/rust/prebuilt.go
+++ b/rust/prebuilt.go
@@ -32,6 +32,8 @@
}
type prebuiltLibraryDecorator struct {
+ android.Prebuilt
+
*libraryDecorator
Properties PrebuiltProperties
}
@@ -54,6 +56,13 @@
return module.Init()
}
+func addSrcSupplier(module android.PrebuiltInterface, prebuilt *prebuiltLibraryDecorator) {
+ srcsSupplier := func(_ android.BaseModuleContext, _ android.Module) []string {
+ return prebuilt.prebuiltSrcs()
+ }
+ android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "srcs")
+}
+
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
module, library := NewRustLibrary(hod)
library.BuildOnlyRust()
@@ -62,6 +71,9 @@
libraryDecorator: library,
}
module.compiler = prebuilt
+
+ addSrcSupplier(module, prebuilt)
+
return module, prebuilt
}
@@ -73,6 +85,9 @@
libraryDecorator: library,
}
module.compiler = prebuilt
+
+ addSrcSupplier(module, prebuilt)
+
return module, prebuilt
}
@@ -84,6 +99,9 @@
libraryDecorator: library,
}
module.compiler = prebuilt
+
+ addSrcSupplier(module, prebuilt)
+
return module, prebuilt
}
@@ -130,3 +148,7 @@
return srcs
}
+
+func (prebuilt *prebuiltLibraryDecorator) prebuilt() *android.Prebuilt {
+ return &prebuilt.Prebuilt
+}
diff --git a/rust/rust.go b/rust/rust.go
index b3e543e..3cc7868 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -1019,6 +1019,13 @@
}
}
+func (mod *Module) Prebuilt() *android.Prebuilt {
+ if p, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
+ return p.prebuilt()
+ }
+ return nil
+}
+
func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
diff --git a/rust/testing.go b/rust/testing.go
index 94cdd9d..dac04d6 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -53,74 +53,14 @@
func GatherRequiredDepsForTest() string {
bp := `
rust_prebuilt_library {
- name: "libstd_x86_64-unknown-linux-gnu",
- crate_name: "std",
- rlib: {
- srcs: ["libstd.rlib"],
- },
- dylib: {
- srcs: ["libstd.so"],
- },
- host_supported: true,
- sysroot: true,
- }
- rust_prebuilt_library {
- name: "libtest_x86_64-unknown-linux-gnu",
- crate_name: "test",
- rlib: {
- srcs: ["libtest.rlib"],
- },
- dylib: {
- srcs: ["libtest.so"],
- },
- host_supported: true,
- sysroot: true,
- }
- rust_prebuilt_library {
- name: "libstd_i686-unknown-linux-gnu",
- crate_name: "std",
- rlib: {
- srcs: ["libstd.rlib"],
- },
- dylib: {
- srcs: ["libstd.so"],
- },
- host_supported: true,
- sysroot: true,
- }
- rust_prebuilt_library {
- name: "libtest_i686-unknown-linux-gnu",
- crate_name: "test",
- rlib: {
- srcs: ["libtest.rlib"],
- },
- dylib: {
- srcs: ["libtest.so"],
- },
- host_supported: true,
- sysroot: true,
- }
- rust_prebuilt_library {
- name: "libstd_x86_64-apple-darwin",
- crate_name: "std",
- rlib: {
- srcs: ["libstd.rlib"],
- },
- dylib: {
- srcs: ["libstd.so"],
- },
- host_supported: true,
- sysroot: true,
- }
- rust_prebuilt_library {
- name: "libtest_x86_64-apple-darwin",
- crate_name: "test",
- rlib: {
- srcs: ["libtest.rlib"],
- },
- dylib: {
- srcs: ["libtest.so"],
- },
+ name: "libstd",
+ crate_name: "std",
+ rlib: {
+ srcs: ["libstd.rlib"],
+ },
+ dylib: {
+ srcs: ["libstd.so"],
+ },
host_supported: true,
sysroot: true,
}