rust: Alias rust_ffi_rlib to rust_library_rlib
With the new transition mutators, the distinctions between rust_ffi_rlib
and rust_library_rlib are not necessary. This CL removes the remaining
distinctions to allow an unusual use case where a rust_library and a
rust_ffi_rlib would otherwise be created from the same source. This
would allow defining a single rust_library_rlib that works for both rust
modules and cc modules.
One key change is that rust_ffi_rlibs only produced an rlib-std variant
previously, and now produce dylib-std variants as well.This surfaced an
issue where a libstd linkage mismatch would cause rustc to throw a
consufing missing crate error. We instead add logic to catch this in
Soong and provide a more useful error message.
Bug: 383552450
Test: m rust
Test: m blueprint_tests
Change-Id: I611ca46934059735d06229952cfd8e0ab7050486
diff --git a/rust/library.go b/rust/library.go
index bd3359b..93a9a3d 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -40,15 +40,15 @@
android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
android.RegisterModuleType("rust_ffi", RustFFIFactory)
android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
- android.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
+ android.RegisterModuleType("rust_ffi_rlib", RustLibraryRlibFactory)
android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
- android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
+ android.RegisterModuleType("rust_ffi_host_rlib", RustLibraryRlibHostFactory)
// TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib
// Alias rust_ffi_static to the rust_ffi_rlib factory
- android.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory)
- android.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory)
+ android.RegisterModuleType("rust_ffi_static", RustLibraryRlibFactory)
+ android.RegisterModuleType("rust_ffi_host_static", RustLibraryRlibHostFactory)
}
type VariantLibraryProperties struct {
@@ -114,8 +114,6 @@
includeDirs android.Paths
sourceProvider SourceProvider
- isFFI bool
-
// table-of-contents file for cdylib crates to optimize out relinking when possible
tocFile android.OptionalPath
}
@@ -156,8 +154,6 @@
BuildOnlyShared()
toc() android.OptionalPath
-
- isFFILibrary() bool
}
func (library *libraryDecorator) nativeCoverage() bool {
@@ -262,13 +258,13 @@
}
}
-func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
- if library.static() || library.MutatedProperties.VariantIsStaticStd || (library.rlib() && library.isFFILibrary()) {
+func (library *libraryDecorator) stdLinkage(device bool) RustLinkage {
+ if library.static() || library.MutatedProperties.VariantIsStaticStd {
return RlibLinkage
} else if library.baseCompiler.preferRlib() {
return RlibLinkage
}
- return DefaultLinkage
+ return DylibLinkage
}
var _ compiler = (*libraryDecorator)(nil)
@@ -298,7 +294,7 @@
return module.Init()
}
-// rust_library_rlib produces an rlib (Rust crate type "rlib").
+// rust_library_rlib and rust_ffi_static produces an rlib (Rust crate type "rlib").
func RustLibraryRlibFactory() android.Module {
module, library := NewRustLibrary(android.HostAndDeviceSupported)
library.BuildOnlyRlib()
@@ -337,8 +333,8 @@
return module.Init()
}
-// rust_library_rlib_host produces an rlib for the host (Rust crate
-// type "rlib").
+// rust_library_rlib_host and rust_ffi_static_host produces an rlib for the host
+// (Rust crate type "rlib").
func RustLibraryRlibHostFactory() android.Module {
module, library := NewRustLibrary(android.HostSupported)
library.BuildOnlyRlib()
@@ -353,33 +349,12 @@
return module.Init()
}
-// rust_ffi_rlib_host produces an rlib for the host (Rust crate
-// type "rlib").
-func RustFFIRlibHostFactory() android.Module {
- module, library := NewRustLibrary(android.HostSupported)
- library.BuildOnlyRlib()
-
- library.isFFI = true
- return module.Init()
-}
-
-// rust_ffi_rlib produces an rlib (Rust crate type "rlib").
-func RustFFIRlibFactory() android.Module {
- module, library := NewRustLibrary(android.HostAndDeviceSupported)
- library.BuildOnlyRlib()
-
- 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 = false
-
- library.isFFI = true
}
func (library *libraryDecorator) BuildOnlyRust() {
@@ -408,8 +383,6 @@
library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildShared = false
library.MutatedProperties.BuildStatic = true
-
- library.isFFI = true
}
func (library *libraryDecorator) BuildOnlyShared() {
@@ -417,12 +390,6 @@
library.MutatedProperties.BuildDylib = false
library.MutatedProperties.BuildStatic = false
library.MutatedProperties.BuildShared = true
-
- library.isFFI = true
-}
-
-func (library *libraryDecorator) isFFILibrary() bool {
- return library.isFFI
}
func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
@@ -511,7 +478,9 @@
flags = CommonLibraryCompilerFlags(ctx, flags)
- if library.isFFI {
+ if library.rlib() || library.shared() {
+ // rlibs collect include dirs as well since they are used to
+ // produce staticlibs in the final C linkages
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
}
@@ -821,11 +790,7 @@
// Only create a variant if a library is actually being built.
if library, ok := m.compiler.(libraryInterface); ok {
if library.rlib() && !library.sysroot() {
- if library.isFFILibrary() {
- return []string{"rlib-std"}
- } else {
- return []string{"rlib-std", "dylib-std"}
- }
+ return []string{"rlib-std", "dylib-std"}
}
}
}