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
This commit is contained in:
Sam Delmerico
2023-06-16 10:28:04 -04:00
parent d96a60685a
commit a588d153c8
28 changed files with 1403 additions and 384 deletions

View File

@@ -36,9 +36,9 @@ func TestFeaturesToFlags(t *testing.T) {
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"fizz\"'") ||
!strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"buzz\"'") {
t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
if !strings.Contains(libfooDylib.RuleParams.Command, "cfg 'feature=\"fizz\"'") ||
!strings.Contains(libfooDylib.RuleParams.Command, "cfg 'feature=\"buzz\"'") {
t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, command: %#v", libfooDylib.RuleParams.Command)
}
}
@@ -57,9 +57,9 @@ func TestCfgsToFlags(t *testing.T) {
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'std'") ||
!strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'cfg1=\"one\"'") {
t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
if !strings.Contains(libfooDylib.RuleParams.Command, "cfg 'std'") ||
!strings.Contains(libfooDylib.RuleParams.Command, "cfg 'cfg1=\"one\"'") {
t.Fatalf("missing std and cfg1 flags for libfoo dylib, rustcFlags: %#v", libfooDylib.RuleParams.Command)
}
}
@@ -146,14 +146,14 @@ func TestCargoCompat(t *testing.T) {
fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Rule("rustc")
if !strings.Contains(fizz.Args["envVars"], "CARGO_BIN_NAME=fizz") {
t.Fatalf("expected 'CARGO_BIN_NAME=fizz' in envVars, actual envVars: %#v", fizz.Args["envVars"])
if !strings.Contains(fizz.RuleParams.Command, "CARGO_BIN_NAME=fizz") {
t.Fatalf("expected 'CARGO_BIN_NAME=fizz' in envVars, actual command: %#v", fizz.RuleParams.Command)
}
if !strings.Contains(fizz.Args["envVars"], "CARGO_CRATE_NAME=foo") {
t.Fatalf("expected 'CARGO_CRATE_NAME=foo' in envVars, actual envVars: %#v", fizz.Args["envVars"])
if !strings.Contains(fizz.RuleParams.Command, "CARGO_CRATE_NAME=foo") {
t.Fatalf("expected 'CARGO_CRATE_NAME=foo' in envVars, actual command: %#v", fizz.RuleParams.Command)
}
if !strings.Contains(fizz.Args["envVars"], "CARGO_PKG_VERSION=1.0.0") {
t.Fatalf("expected 'CARGO_PKG_VERSION=1.0.0' in envVars, actual envVars: %#v", fizz.Args["envVars"])
if !strings.Contains(fizz.RuleParams.Command, "CARGO_PKG_VERSION=1.0.0") {
t.Fatalf("expected 'CARGO_PKG_VERSION=1.0.0' in envVars, actual command: %#v", fizz.RuleParams.Command)
}
}
@@ -230,13 +230,13 @@ func TestLints(t *testing.T) {
).RunTest(t)
r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
android.AssertStringDoesContain(t, "libfoo flags", r.Args["rustcFlags"], tc.fooFlags)
android.AssertStringDoesContain(t, "libfoo flags", r.RuleParams.Command, tc.fooFlags)
r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
android.AssertStringDoesContain(t, "libbar flags", r.Args["rustcFlags"], "${config.RustDefaultLints}")
android.AssertStringDoesContain(t, "libbar flags", r.RuleParams.Command, "${config.RustDefaultLints}")
r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
android.AssertStringDoesContain(t, "libfoobar flags", r.Args["rustcFlags"], "${config.RustAllowAllLints}")
android.AssertStringDoesContain(t, "libfoobar flags", r.RuleParams.Command, "${config.RustAllowAllLints}")
})
}
}