Loading rust/compiler.go +20 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package rust import ( "fmt" "path/filepath" "strings" "github.com/google/blueprint/proptools" Loading Loading @@ -235,6 +236,25 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag if err != nil { ctx.PropertyErrorf("lints", err.Error()) } // linkage-related flags are disallowed. for _, s := range compiler.Properties.Ld_flags { if strings.HasPrefix(s, "-Wl,-l") || strings.HasPrefix(s, "-Wl,-L") { ctx.PropertyErrorf("ld_flags", "'-Wl,-l' and '-Wl,-L' flags cannot be manually specified") } } for _, s := range compiler.Properties.Flags { if strings.HasPrefix(s, "-l") || strings.HasPrefix(s, "-L") { ctx.PropertyErrorf("flags", "'-l' and '-L' flags cannot be manually specified") } if strings.HasPrefix(s, "--extern") { ctx.PropertyErrorf("flags", "'--extern' flag cannot be manually specified") } if strings.HasPrefix(s, "-Clink-args=") || strings.HasPrefix(s, "-C link-args=") { ctx.PropertyErrorf("flags", "'-C link-args' flag cannot be manually specified") } } flags.RustFlags = append(flags.RustFlags, lintFlags) flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...) flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...) Loading rust/compiler_test.go +70 −0 Original line number Diff line number Diff line Loading @@ -208,3 +208,73 @@ func TestStdDeviceLinkage(t *testing.T) { t.Errorf("libstd is not linked dynamically for dylibs") } } // Ensure that manual link flags are disallowed. func TestManualLinkageRejection(t *testing.T) { // rustc flags testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-lbar"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["--extern=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-Clink-args=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-C link-args=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-L foo/"], } `) // lld flags testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], ld_flags: ["-Wl,-L bar/"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], ld_flags: ["-Wl,-lbar"], } `) } Loading
rust/compiler.go +20 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package rust import ( "fmt" "path/filepath" "strings" "github.com/google/blueprint/proptools" Loading Loading @@ -235,6 +236,25 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag if err != nil { ctx.PropertyErrorf("lints", err.Error()) } // linkage-related flags are disallowed. for _, s := range compiler.Properties.Ld_flags { if strings.HasPrefix(s, "-Wl,-l") || strings.HasPrefix(s, "-Wl,-L") { ctx.PropertyErrorf("ld_flags", "'-Wl,-l' and '-Wl,-L' flags cannot be manually specified") } } for _, s := range compiler.Properties.Flags { if strings.HasPrefix(s, "-l") || strings.HasPrefix(s, "-L") { ctx.PropertyErrorf("flags", "'-l' and '-L' flags cannot be manually specified") } if strings.HasPrefix(s, "--extern") { ctx.PropertyErrorf("flags", "'--extern' flag cannot be manually specified") } if strings.HasPrefix(s, "-Clink-args=") || strings.HasPrefix(s, "-C link-args=") { ctx.PropertyErrorf("flags", "'-C link-args' flag cannot be manually specified") } } flags.RustFlags = append(flags.RustFlags, lintFlags) flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...) flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...) Loading
rust/compiler_test.go +70 −0 Original line number Diff line number Diff line Loading @@ -208,3 +208,73 @@ func TestStdDeviceLinkage(t *testing.T) { t.Errorf("libstd is not linked dynamically for dylibs") } } // Ensure that manual link flags are disallowed. func TestManualLinkageRejection(t *testing.T) { // rustc flags testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-lbar"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["--extern=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-Clink-args=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-C link-args=foo"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], flags: ["-L foo/"], } `) // lld flags testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], ld_flags: ["-Wl,-L bar/"], } `) testRustError(t, ".* cannot be manually specified", ` rust_binary { name: "foo", srcs: [ "foo.rs", ], ld_flags: ["-Wl,-lbar"], } `) }