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
diff --git a/rust/compiler.go b/rust/compiler.go
index de59f39..6b3ccfc 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -154,6 +154,14 @@
 	// 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 {
@@ -309,6 +317,14 @@
 	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
 }