From a9a1fc07473ef512d3ae84f4c368d5e3752649e6 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Wed, 11 Aug 2021 15:13:43 -0400 Subject: rust: Add support to emit certain Cargo env vars. Some crates expect Cargo to provide certain environment variables. This CL adds a compatability flag that emulates the behavior of Cargo by setting these environment variables when building. Bug: 171011485 Test: New soong tests pass Test: quiche no longer requires patch removing CARGO_PKG_VERSION Change-Id: I4c95c284846f6075428c6f61fe8c260f2e35fbd9 --- rust/builder.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rust/builder.go') diff --git a/rust/builder.go b/rust/builder.go index a5b3ab9de..426a569bf 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -269,6 +269,17 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl envVars = append(envVars, "ANDROID_RUST_VERSION="+config.RustDefaultVersion) + if ctx.RustModule().compiler.CargoEnvCompat() { + if _, ok := ctx.RustModule().compiler.(*binaryDecorator); ok { + envVars = append(envVars, "CARGO_BIN_NAME="+strings.TrimSuffix(outputFile.Base(), outputFile.Ext())) + } + envVars = append(envVars, "CARGO_CRATE_NAME="+ctx.RustModule().CrateName()) + pkgVersion := ctx.RustModule().compiler.CargoPkgVersion() + if pkgVersion != "" { + envVars = append(envVars, "CARGO_PKG_VERSION="+pkgVersion) + } + } + if flags.Clippy { clippyFile := android.PathForModuleOut(ctx, outputFile.Base()+".clippy") ctx.Build(pctx, android.BuildParams{ -- cgit v1.2.3-59-g8ed1b