Loading rust/compiler.go +16 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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"` Loading Loading @@ -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 Loading @@ -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...) Loading rust/compiler_test.go +21 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,27 @@ func TestFeaturesToFlags(t *testing.T) { } } // Test that cfgs flags are being correctly generated. func TestCfgsToFlags(t *testing.T) { ctx := testRust(t, ` rust_library_host { name: "libfoo", srcs: ["foo.rs"], crate_name: "foo", cfgs: [ "std", "cfg1=\"one\"" ], }`) libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'std'") || !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'cfg1=\"one\"'") { t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) } } // Test that we reject multiple source files. func TestEnforceSingleSourceFile(t *testing.T) { Loading Loading
rust/compiler.go +16 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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"` Loading Loading @@ -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 Loading @@ -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...) Loading
rust/compiler_test.go +21 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,27 @@ func TestFeaturesToFlags(t *testing.T) { } } // Test that cfgs flags are being correctly generated. func TestCfgsToFlags(t *testing.T) { ctx := testRust(t, ` rust_library_host { name: "libfoo", srcs: ["foo.rs"], crate_name: "foo", cfgs: [ "std", "cfg1=\"one\"" ], }`) libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc") if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'std'") || !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'cfg1=\"one\"'") { t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) } } // Test that we reject multiple source files. func TestEnforceSingleSourceFile(t *testing.T) { Loading