summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matthew Maurer <mmaurer@google.com> 2022-07-26 14:26:33 -0700
committer Matthew Maurer <mmaurer@google.com> 2022-08-01 16:28:51 +0000
commit53a452d1ff172fba9060f2997fec006a70e44c8d (patch)
tree56c025bc93ec205ca8f4041069faf622bd0f02d7
parent0bb7f0494ead02d94946c2ded3bf6bb147d81437 (diff)
rust: Only allow bindgen to produce `rlib`s.
Generated bindings are intended to be slim translation layers, usually consisting of nothing more than type signatures and constants. Generally, they should also be used in exactly one location by the safe wrapper for these bindings. By preventing them from building as `dylib`s, we avoid the per-library overhead of these non-reused pieces of code. Additionally, default visibility restrict all bindgen modules to their subpackages. This is being done both: * to encourage use of a single safe bindings crate * to avoid diamond dependency graphs with mixed rlib/dylib dependencies Bug: 166332519 Test: m; Make sample module use dylib bindgen dependency, see build failure. Change-Id: I8e9d9cb851c2ec99f4ed63e6e18c4ba26b29721c
-rw-r--r--rust/bindgen.go10
-rw-r--r--rust/protobuf.go2
-rw-r--r--rust/source_provider.go5
3 files changed, 14 insertions, 3 deletions
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 72cc894cc..0199d3a37 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -299,7 +299,15 @@ func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorat
ClangProperties: cc.RustBindgenClangProperties{},
}
- module := NewSourceProviderModule(hod, bindgen, false)
+ module := NewSourceProviderModule(hod, bindgen, false, true)
+
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) {
+ type stub_props struct {
+ Visibility []string
+ }
+ props := &stub_props{[]string{":__subpackages__"}}
+ ctx.PrependProperties(props)
+ })
return module, bindgen
}
diff --git a/rust/protobuf.go b/rust/protobuf.go
index 9fe27c4c9..88e80fe35 100644
--- a/rust/protobuf.go
+++ b/rust/protobuf.go
@@ -238,7 +238,7 @@ func NewRustProtobuf(hod android.HostOrDeviceSupported) (*Module, *protobufDecor
Properties: ProtobufProperties{},
}
- module := NewSourceProviderModule(hod, protobuf, false)
+ module := NewSourceProviderModule(hod, protobuf, false, false)
return module, protobuf
}
diff --git a/rust/source_provider.go b/rust/source_provider.go
index 7719611d5..4f8d22b1f 100644
--- a/rust/source_provider.go
+++ b/rust/source_provider.go
@@ -65,9 +65,12 @@ func NewSourceProvider() *BaseSourceProvider {
}
}
-func NewSourceProviderModule(hod android.HostOrDeviceSupported, sourceProvider SourceProvider, enableLints bool) *Module {
+func NewSourceProviderModule(hod android.HostOrDeviceSupported, sourceProvider SourceProvider, enableLints bool, rlibOnly bool) *Module {
_, library := NewRustLibrary(hod)
library.BuildOnlyRust()
+ if rlibOnly {
+ library.BuildOnlyRlib()
+ }
library.sourceProvider = sourceProvider
module := newModule(hod, android.MultilibBoth)