cc/rust: Alias ffi rlib variant for static_libs
Alias the rlib variant to "link: static". This allows declaring
rust_ffi_rlib modules in static_libs. This effectively removes any
distinction between rust_ffi_static and rust_ffi_rlib. Removing the
functionality for building Rust staticlib modules will be cleaned up in
a follow-on CL.
This should have the effect of changing the default linkage for all rust
modules in static_libs from linking individual staticlibs to building a
single staticlib that includes all rust_ffi rlib dependencies.
This removes the static_rlibs property, as we're now handling
the choice dynamically. This also makes rlibs only propagate through
cc_library_static modules if the rlib is included in
whole_static_lib. This both mirrors the expected behavior of
cc libraries and helps control which version of a crate ends up in the
final link (e.g. libdoh_ffi vs libdoh_ffi_for_test).
Bug: 254469782
Test: m
Test: m blueprint_tests
Change-Id: I2925f67f6dc9329dae3dcccafb8560900ac8a6fc
diff --git a/cc/library.go b/cc/library.go
index e49f50c..4373b46 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1135,8 +1135,12 @@
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 @@
modules := mctx.CreateLocalVariations(variations...)
static := modules[0].(LinkableInterface)
shared := modules[1].(LinkableInterface)
-
static.SetStatic()
shared.SetShared()
@@ -2173,6 +2176,12 @@
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", "")
+ }
}
}