Allow users to enable local incremental Rust builds

This CL allows users to set the SOONG_RUSTC_INCREMENTAL environment
variable to enable incremental Rust builds.  The out/soong/rustc
directory is used for intermediate artifacts.

Test: m rust
Change-Id: Ica2587c30596325b7d3e82d8e3c1d610b92718b8
diff --git a/rust/builder.go b/rust/builder.go
index 60b5926..a7efc28 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -216,6 +216,13 @@
 	// Suppress an implicit sysroot
 	rustcFlags = append(rustcFlags, "--sysroot=/dev/null")
 
+	// Enable incremental compilation if requested by user
+	if ctx.Config().IsEnvTrue("SOONG_RUSTC_INCREMENTAL") {
+		incrementalPath := android.PathForOutput(ctx, "rustc").String()
+
+		rustcFlags = append(rustcFlags, "-C incremental="+incrementalPath)
+	}
+
 	// Collect linker flags
 	linkFlags = append(linkFlags, flags.GlobalLinkFlags...)
 	linkFlags = append(linkFlags, flags.LinkFlags...)