[rust] Add SourceProviders as crates support.
This allows SourceProvider modules to create rust_library variants so
that generated source can be referenced as an external crate rather than
via an include macro. This is done by including rust_bindgen modules
like any other library, as a dependency in either rlibs, dylibs, or
rustlibs.
This renames the stem and flags properties for rust_bindgen modules to
source_stem and bindgen_flags, respectively. This deconflicts with the
usage in baseCompiler.
This also removes 'subName' from the Module struct and moves it over to
SourceProvider, which was the only user. This allows us to set it in
baseSourceProvider's AndroidMk; setting it in Module's AndroidMk was
causing problems finding NOTICE files for bindgen library variants.
Bug: 159064919
Test: New Soong tests pass.
Test: Local test rust_binary can use rust_bindgen module as a crate.
Change-Id: Ieb2cb614c2dd0b5aa7120541d77f6f822a6a1806
diff --git a/rust/source_provider.go b/rust/source_provider.go
index da6147a..8bb7849 100644
--- a/rust/source_provider.go
+++ b/rust/source_provider.go
@@ -19,8 +19,13 @@
)
type SourceProviderProperties struct {
- // sets name of the output
- Stem *string `android:"arch_variant"`
+ // name for the generated source file. Defaults to module name (e.g. moduleNameFoo.rs is produced by default).
+ // Importantly, the inherited "stem" property for this module sets the output filename for the generated library
+ // variants only
+ Source_stem *string `android:"arch_variant"`
+
+ // crate name, used for the library variant of this source provider. See additional details in rust_library.
+ Crate_name string `android:"arch_variant"`
}
type baseSourceProvider struct {
@@ -28,6 +33,7 @@
outputFile android.Path
subAndroidMkOnce map[subAndroidMkProvider]bool
+ subName string
}
var _ SourceProvider = (*baseSourceProvider)(nil)
@@ -37,6 +43,7 @@
Srcs() android.Paths
sourceProviderProps() []interface{}
sourceProviderDeps(ctx DepsContext, deps Deps) Deps
+ setSubName(subName string)
}
func (sp *baseSourceProvider) Srcs() android.Paths {
@@ -59,8 +66,8 @@
func (sp *baseSourceProvider) getStem(ctx android.ModuleContext) string {
stem := ctx.ModuleName()
- if String(sp.Properties.Stem) != "" {
- stem = String(sp.Properties.Stem)
+ if String(sp.Properties.Source_stem) != "" {
+ stem = String(sp.Properties.Source_stem)
}
return stem
}
@@ -68,3 +75,7 @@
func (sp *baseSourceProvider) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
return deps
}
+
+func (sp *baseSourceProvider) setSubName(subName string) {
+ sp.subName = subName
+}