diff options
Diffstat (limited to 'rust/compiler.go')
-rw-r--r-- | rust/compiler.go | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index a2546a194..1d2fb58c3 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -30,22 +30,22 @@ import ( type RustLinkage int const ( - DefaultLinkage RustLinkage = iota + DylibLinkage RustLinkage = iota RlibLinkage - DylibLinkage ) type compiler interface { initialize(ctx ModuleContext) compilerFlags(ctx ModuleContext, flags Flags) Flags cfgFlags(ctx ModuleContext, flags Flags) Flags - featureFlags(ctx ModuleContext, flags Flags) Flags + featureFlags(ctx ModuleContext, module *Module, flags Flags) Flags + baseCompilerProps() BaseCompilerProperties compilerProps() []interface{} compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput compilerDeps(ctx DepsContext, deps Deps) Deps crateName() string edition() string - features() []string + features(ctx android.ConfigurableEvaluatorContext, module *Module) []string rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath Thinlto() bool @@ -69,7 +69,7 @@ type compiler interface { Disabled() bool SetDisabled() - stdLinkage(ctx *depsContext) RustLinkage + stdLinkage(device bool) RustLinkage noStdlibs() bool unstrippedOutputFilePath() android.Path @@ -150,21 +150,21 @@ type BaseCompilerProperties struct { Aliases []string // list of rust rlib crate dependencies - Rlibs []string `android:"arch_variant"` + Rlibs proptools.Configurable[[]string] `android:"arch_variant"` // list of rust automatic crate dependencies. // Rustlibs linkage is rlib for host targets and dylib for device targets. - Rustlibs []string `android:"arch_variant"` + Rustlibs proptools.Configurable[[]string] `android:"arch_variant"` // list of rust proc_macro crate dependencies - Proc_macros []string `android:"arch_variant"` + Proc_macros proptools.Configurable[[]string] `android:"arch_variant"` // list of C shared library dependencies - Shared_libs []string `android:"arch_variant"` + Shared_libs proptools.Configurable[[]string] `android:"arch_variant"` // list of C static library dependencies. These dependencies do not normally propagate to dependents // and may need to be redeclared. See whole_static_libs for bundling static dependencies into a library. - Static_libs []string `android:"arch_variant"` + Static_libs proptools.Configurable[[]string] `android:"arch_variant"` // Similar to static_libs, but will bundle the static library dependency into a library. This is helpful // to avoid having to redeclare the dependency for dependents of this library, but in some cases may also @@ -179,13 +179,13 @@ type BaseCompilerProperties struct { // // For rust_library rlib variants, these libraries will be bundled into the resulting rlib library. This will // include all of the static libraries symbols in any dylibs or binaries which use this rlib as well. - Whole_static_libs []string `android:"arch_variant"` + Whole_static_libs proptools.Configurable[[]string] `android:"arch_variant"` // list of Rust system library dependencies. // // This is usually only needed when `no_stdlibs` is true, in which case it can be used to depend on system crates // like `core` and `alloc`. - Stdlibs []string `android:"arch_variant"` + Stdlibs proptools.Configurable[[]string] `android:"arch_variant"` // crate name, required for modules which produce Rust libraries: rust_library, rust_ffi and SourceProvider // modules which create library variants (rust_bindgen). This must be the expected extern crate name used in @@ -194,7 +194,7 @@ type BaseCompilerProperties struct { Crate_name string `android:"arch_variant"` // list of features to enable for this crate - Features []string `android:"arch_variant"` + Features proptools.Configurable[[]string] `android:"arch_variant"` // list of configuration options to enable for this crate. To enable features, use the "features" property. Cfgs proptools.Configurable[[]string] `android:"arch_variant"` @@ -316,11 +316,11 @@ func (compiler *baseCompiler) Aliases() map[string]string { return aliases } -func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage { +func (compiler *baseCompiler) stdLinkage(device bool) RustLinkage { // For devices, we always link stdlibs in as dylibs by default. if compiler.preferRlib() { return RlibLinkage - } else if ctx.Device() { + } else if device { return DylibLinkage } else { return RlibLinkage @@ -337,6 +337,10 @@ func (compiler *baseCompiler) compilerProps() []interface{} { return []interface{}{&compiler.Properties} } +func (compiler *baseCompiler) baseCompilerProps() BaseCompilerProperties { + return compiler.Properties +} + func cfgsToFlags(cfgs []string) []string { flags := make([]string, 0, len(cfgs)) for _, cfg := range cfgs { @@ -346,22 +350,23 @@ func cfgsToFlags(cfgs []string) []string { return flags } -func (compiler *baseCompiler) features() []string { - return compiler.Properties.Features +func (compiler *baseCompiler) features(ctx android.ConfigurableEvaluatorContext, module *Module) []string { + eval := module.ConfigurableEvaluator(ctx) + return compiler.Properties.Features.GetOrDefault(eval, nil) } -func (compiler *baseCompiler) featuresToFlags() []string { +func (compiler *baseCompiler) featuresToFlags(ctx android.ConfigurableEvaluatorContext, module *Module) []string { flags := []string{} - for _, feature := range compiler.features() { + for _, feature := range compiler.features(ctx, module) { flags = append(flags, "--cfg 'feature=\""+feature+"\"'") } return flags } -func (compiler *baseCompiler) featureFlags(ctx ModuleContext, flags Flags) Flags { - flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...) - flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...) +func (compiler *baseCompiler) featureFlags(ctx ModuleContext, module *Module, flags Flags) Flags { + flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(ctx, module)...) + flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags(ctx, module)...) return flags } @@ -495,13 +500,13 @@ func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath { } func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { - deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...) - deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...) - deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...) - deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...) - deps.WholeStaticLibs = append(deps.WholeStaticLibs, compiler.Properties.Whole_static_libs...) - deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...) - deps.Stdlibs = append(deps.Stdlibs, compiler.Properties.Stdlibs...) + deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs.GetOrDefault(ctx, nil)...) + deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs.GetOrDefault(ctx, nil)...) + deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros.GetOrDefault(ctx, nil)...) + deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs.GetOrDefault(ctx, nil)...) + deps.WholeStaticLibs = append(deps.WholeStaticLibs, compiler.Properties.Whole_static_libs.GetOrDefault(ctx, nil)...) + deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs.GetOrDefault(ctx, nil)...) + deps.Stdlibs = append(deps.Stdlibs, compiler.Properties.Stdlibs.GetOrDefault(ctx, nil)...) if !Bool(compiler.Properties.No_stdlibs) { for _, stdlib := range config.Stdlibs { |