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/library.go b/rust/library.go
index 7432a12..87b25cb 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -485,6 +485,23 @@
 	return flags
 }
 
+func (library *libraryDecorator) compilationSourcesAndData(ctx ModuleContext) android.Paths {
+	var extraSrcs android.Paths
+	if library.rlib() {
+		extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Rlib.Srcs)
+	} else if library.dylib() {
+		extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Dylib.Srcs)
+	} else if library.static() {
+		extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
+	} else if library.shared() {
+		extraSrcs = android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
+	}
+	return android.Concat(
+		library.baseCompiler.compilationSourcesAndData(ctx),
+		extraSrcs,
+	)
+}
+
 func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
 	var outputFile android.ModuleOutPath
 	var ret buildOutput
@@ -525,7 +542,6 @@
 
 	flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
 	flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
-	flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects.Strings()...)
 
 	if library.dylib() {
 		// We need prefer-dynamic for now to avoid linking in the static stdlib. See:
@@ -536,13 +552,13 @@
 
 	// Call the appropriate builder for this library type
 	if library.rlib() {
-		ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
+		ret.kytheFile = TransformSrctoRlib(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
 	} else if library.dylib() {
-		ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
+		ret.kytheFile = TransformSrctoDylib(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
 	} else if library.static() {
-		ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile
+		ret.kytheFile = TransformSrctoStatic(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
 	} else if library.shared() {
-		ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile
+		ret.kytheFile = TransformSrctoShared(ctx, library, crateRootPath, deps, flags, outputFile).kytheFile
 	}
 
 	if library.rlib() || library.dylib() {