From 26ecd6c5974fcd3ec09792394e7b9cdf32f5f64f Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Fri, 31 Jul 2020 13:40:31 -0400 Subject: [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 --- rust/library.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'rust/library.go') diff --git a/rust/library.go b/rust/library.go index 6d5eca0d7..6766d618b 100644 --- a/rust/library.go +++ b/rust/library.go @@ -69,6 +69,10 @@ type LibraryMutatedProperties struct { VariantIsShared bool `blueprint:"mutated"` // This variant is a static library VariantIsStatic bool `blueprint:"mutated"` + + // This variant is disabled and should not be compiled + // (used for SourceProvider variants that produce only source) + VariantIsDisabled bool `blueprint:"mutated"` } type libraryDecorator struct { @@ -78,6 +82,7 @@ type libraryDecorator struct { Properties LibraryCompilerProperties MutatedProperties LibraryMutatedProperties includeDirs android.Paths + sourceProvider SourceProvider } type libraryInterface interface { @@ -367,8 +372,13 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { var outputFile android.WritablePath + var srcPath android.Path - srcPath, _ := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs) + if library.sourceProvider != nil { + srcPath = library.sourceProvider.Srcs()[0] + } else { + srcPath, _ = srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs) + } flags.RustFlags = append(flags.RustFlags, deps.depFlags...) @@ -430,6 +440,14 @@ func (library *libraryDecorator) getStem(ctx ModuleContext) string { return stem + String(library.baseCompiler.Properties.Suffix) } +func (library *libraryDecorator) Disabled() bool { + return library.MutatedProperties.VariantIsDisabled +} + +func (library *libraryDecorator) SetDisabled() { + library.MutatedProperties.VariantIsDisabled = true +} + var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+") func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) { @@ -455,12 +473,23 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { switch library := m.compiler.(type) { case libraryInterface: if library.buildRlib() && library.buildDylib() { - modules := mctx.CreateLocalVariations("rlib", "dylib") + variants := []string{"rlib", "dylib"} + if m.sourceProvider != nil { + variants = append(variants, "") + } + modules := mctx.CreateLocalVariations(variants...) + rlib := modules[0].(*Module) dylib := modules[1].(*Module) - rlib.compiler.(libraryInterface).setRlib() dylib.compiler.(libraryInterface).setDylib() + + if m.sourceProvider != nil { + // This library is SourceProvider generated, so the non-library-producing + // variant needs to disable it's compiler and skip installation. + sourceProvider := modules[2].(*Module) + sourceProvider.compiler.SetDisabled() + } } else if library.buildRlib() { modules := mctx.CreateLocalVariations("rlib") modules[0].(*Module).compiler.(libraryInterface).setRlib() @@ -468,6 +497,11 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { modules := mctx.CreateLocalVariations("dylib") modules[0].(*Module).compiler.(libraryInterface).setDylib() } + + if m.sourceProvider != nil { + // Alias the non-library variant to the empty-string variant. + mctx.AliasVariation("") + } } } } -- cgit v1.2.3-59-g8ed1b