rust: Refactor cfg and feature flag calculation

Move the cfg and feature flag calculation out of compilerFlags so that
it's a separate step.

The previous arrangement resulted in overridden compilerFlags which
must to set any additional cfgs/features before calling the base.
This is a bit confusing and undocumented behavior, so instead break
it out into a separate call that can itself be overriden.

Bug: N/A
Test: Soong tests pass
Change-Id: I28e4f707b3b3ca6eb621b7613c3737817f877bb8
This commit is contained in:
Ivan Lozano
2021-09-23 11:50:33 -04:00
parent 1b15345ac9
commit 67eada34db
3 changed files with 36 additions and 10 deletions

View File

@@ -430,15 +430,25 @@ func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
}
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags {
flags = library.baseCompiler.cfgFlags(ctx, flags)
if library.dylib() {
// We need to add a dependency on std in order to link crates as dylibs.
// The hack to add this dependency is guarded by the following cfg so
// that we don't force a dependency when it isn't needed.
library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
}
flags.RustFlags = append(flags.RustFlags, library.baseCompiler.cfgsToFlags()...)
flags.RustdocFlags = append(flags.RustdocFlags, library.baseCompiler.cfgsToFlags()...)
return flags
}
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
flags = library.baseCompiler.compilerFlags(ctx, flags)
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
if library.shared() || library.static() {
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
}