summaryrefslogtreecommitdiff
path: root/rust/binary_test.go
diff options
context:
space:
mode:
authorIvan Lozano <ivanlozano@google.com>2020-10-02 10:03:23 -0400
committerIvan Lozano <ivanlozano@google.com>2020-10-02 12:31:23 -0400
commitbf63d00c5487d18d69e1040a94400546f0750476 (patch)
tree8785122fb3c3b81f91499da801b4887c6506ddd2 /rust/binary_test.go
parent45dda43df0b32122d833d43166f2fa2f9a170889 (diff)
rust: Add static binary support
Adds the "static_executable" property to rust_binary modules which allows for building fully static executables. This only impacts bionic targets. Bug: 169434439 Test: rust_binary module with static_executable true builds, runs on device. Change-Id: I83c19fddd070859b7e56d248237cfd73e1768519
Diffstat (limited to 'rust/binary_test.go')
-rw-r--r--rust/binary_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/rust/binary_test.go b/rust/binary_test.go
index f31a7fcda..b44a5bc71 100644
--- a/rust/binary_test.go
+++ b/rust/binary_test.go
@@ -114,6 +114,34 @@ func TestBinaryFlags(t *testing.T) {
}
}
+func TestStaticBinaryFlags(t *testing.T) {
+ ctx := testRust(t, `
+ rust_binary {
+ name: "fizz",
+ srcs: ["foo.rs"],
+ static_executable: true,
+ }`)
+
+ fizzOut := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Output("fizz")
+ fizzMod := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Module().(*Module)
+
+ flags := fizzOut.Args["rustcFlags"]
+ linkFlags := fizzOut.Args["linkFlags"]
+ if !strings.Contains(flags, "-C relocation-model=static") {
+ t.Errorf("static binary missing '-C relocation-model=static' in rustcFlags, found: %#v", flags)
+ }
+ if !strings.Contains(linkFlags, "-static") {
+ t.Errorf("static binary missing '-static' in linkFlags, found: %#v", flags)
+ }
+
+ if !android.InList("libc", fizzMod.Properties.AndroidMkStaticLibs) {
+ t.Errorf("static binary not linking against libc as a static library")
+ }
+ if len(fizzMod.Properties.AndroidMkSharedLibs) > 0 {
+ t.Errorf("static binary incorrectly linking against shared libraries")
+ }
+}
+
func TestLinkObjects(t *testing.T) {
ctx := testRust(t, `
rust_binary {