summaryrefslogtreecommitdiff
path: root/rust/compiler.go
diff options
context:
space:
mode:
authorThiƩbaud Weksteen <tweek@google.com>2021-04-07 14:53:06 +0200
committerThiƩbaud Weksteen <tweek@google.com>2021-04-07 15:04:10 +0200
commitc44e7372ed80d334baa0bd51039ccc403e0b7c5b (patch)
tree60afb0fc91409d552ebc297d241c709556c8ce8e /rust/compiler.go
parentda42a5a2096fd2a9800d16b8a0156e629e11034b (diff)
rust: Add cfgs property
Rust configuration options ("--cfg") are currently defined using the "flags" property. Adds a specific property to be able to forward these to the rust-analyzer configuration (rust-project.json). Bug: 183727250 Test: m libstd Change-Id: Ida89097814bcd1a45c02a8a79ec5a8e9e59701bd
Diffstat (limited to 'rust/compiler.go')
-rw-r--r--rust/compiler.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/rust/compiler.go b/rust/compiler.go
index 41b73719a..d4df26da0 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -76,7 +76,7 @@ type BaseCompilerProperties struct {
// errors). The default value is "default".
Lints *string
- // flags to pass to rustc
+ // flags to pass to rustc. To enable configuration options or features, use the "cfgs" or "features" properties.
Flags []string `android:"path,arch_variant"`
// flags to pass to the linker
@@ -125,6 +125,9 @@ type BaseCompilerProperties struct {
// list of features to enable for this crate
Features []string `android:"arch_variant"`
+ // list of configuration options to enable for this crate. To enable features, use the "features" property.
+ Cfgs []string `android:"arch_variant"`
+
// specific rust edition that should be used if the default version is not desired
Edition *string `android:"arch_variant"`
@@ -210,9 +213,17 @@ func (compiler *baseCompiler) compilerProps() []interface{} {
return []interface{}{&compiler.Properties}
}
-func (compiler *baseCompiler) featuresToFlags(features []string) []string {
+func (compiler *baseCompiler) cfgsToFlags() []string {
+ flags := []string{}
+ for _, cfg := range compiler.Properties.Cfgs {
+ flags = append(flags, "--cfg '"+cfg+"'")
+ }
+ return flags
+}
+
+func (compiler *baseCompiler) featuresToFlags() []string {
flags := []string{}
- for _, feature := range features {
+ for _, feature := range compiler.Properties.Features {
flags = append(flags, "--cfg 'feature=\""+feature+"\"'")
}
return flags
@@ -226,7 +237,8 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
}
flags.RustFlags = append(flags.RustFlags, lintFlags)
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
- flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
+ flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...)
+ flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...)
flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition())
flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
flags.GlobalRustFlags = append(flags.GlobalRustFlags, config.GlobalRustFlags...)