diff options
Diffstat (limited to 'rust/compiler.go')
-rw-r--r-- | rust/compiler.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index 0b28135ae..6b3ccfcfa 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -17,6 +17,7 @@ package rust import ( "fmt" "path/filepath" + "strings" "github.com/google/blueprint/proptools" @@ -153,6 +154,14 @@ type BaseCompilerProperties struct { // linkage if all dependencies of the root binary module do not link against libstd\ // the same way. Prefer_rlib *bool `android:"arch_variant"` + + // Enables emitting certain Cargo environment variables. Only intended to be used for compatibility purposes. + // Will set CARGO_CRATE_NAME to the crate_name property's value. + // Will set CARGO_BIN_NAME to the output filename value without the extension. + Cargo_env_compat *bool + + // If cargo_env_compat is true, sets the CARGO_PKG_VERSION env var to this value. + Cargo_pkg_version *string } type baseCompiler struct { @@ -235,6 +244,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()...) @@ -289,6 +317,14 @@ func (compiler *baseCompiler) CargoOutDir() android.OptionalPath { return android.OptionalPathForPath(compiler.cargoOutDir) } +func (compiler *baseCompiler) CargoEnvCompat() bool { + return Bool(compiler.Properties.Cargo_env_compat) +} + +func (compiler *baseCompiler) CargoPkgVersion() string { + return String(compiler.Properties.Cargo_pkg_version) +} + func (compiler *baseCompiler) strippedOutputFilePath() android.OptionalPath { return compiler.strippedOutputFile } @@ -305,7 +341,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { if !Bool(compiler.Properties.No_stdlibs) { for _, stdlib := range config.Stdlibs { // If we're building for the primary arch of the build host, use the compiler's stdlibs - if ctx.Target().Os == android.BuildOs { + if ctx.Target().Os == ctx.Config().BuildOS { stdlib = stdlib + "_" + ctx.toolchain().RustTriple() } deps.Stdlibs = append(deps.Stdlibs, stdlib) |