support sandboxed rust rules

This commit adds support for compiling rust rules inside the sbox
sandbox. To compile a rust module with sandboxing enabled, the entry
point to the crate must be specified via the `crate_root` property, and
all input sources and compile-time data must be specified via the `srcs`
and `compile_data` properties.

Bug: 286077158
Change-Id: I8c9dc5cf7578037a583b4be2e2f73cf20ffd4408
diff --git a/rust/config/global.go b/rust/config/global.go
index bacea03..deaccfd 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -126,3 +126,27 @@
 func BazelRustToolchainVars(config android.Config) string {
 	return android.BazelToolchainVars(config, exportedVars)
 }
+
+func RustPath(ctx android.PathContext, file string) android.SourcePath {
+	type rustToolKey string
+	key := android.NewCustomOnceKey(rustToolKey(file))
+	return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
+		return rustPath(ctx).Join(ctx, file)
+	})
+}
+
+var rustPathKey = android.NewOnceKey("clangPath")
+
+func rustPath(ctx android.PathContext) android.SourcePath {
+	return ctx.Config().OnceSourcePath(rustPathKey, func() android.SourcePath {
+		rustBase := RustDefaultBase
+		if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
+			rustBase = override
+		}
+		rustVersion := RustDefaultVersion
+		if override := ctx.Config().Getenv("RUST_DEFAULT_VERSION"); override != "" {
+			rustVersion = override
+		}
+		return android.PathForSource(ctx, rustBase, ctx.Config().PrebuiltOS(), rustVersion)
+	})
+}