Skip to content

Commit 23c6ec6

Browse files
committed
build with musl on linux because glibc may differ on lambda
1 parent f26acd4 commit 23c6ec6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

aws_lambda_builders/workflows/rust_cargo/actions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ def cargo_metadata(self):
103103
return json.loads(out)
104104

105105
def build_command(self, package):
106-
cmd = [self.binaries["cargo"].binary_path, "build", "-p", package]
106+
cmd = [self.binaries["cargo"].binary_path, "build", "-p", package, "--target", "x86_64-unknown-linux-musl"]
107107
if self.mode != BuildMode.DEBUG:
108108
cmd.append("--release")
109-
if self.platform.lower() != "linux":
110-
cmd.extend(["--target", "x86_64-unknown-linux-musl"])
111109
return cmd
112110

113111
def resolve_binary(self, cargo_meta):

tests/unit/workflows/rust_cargo/test_actions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,26 @@ class TestBuildAction(TestCase):
2828
def test_linux_release_build_cargo_command(self):
2929
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
3030
action = BuildAction("source_dir", "foo", {"cargo": cargo}, "linux", BuildMode.RELEASE)
31-
self.assertEqual(action.build_command("foo"), ["path/to/cargo", "build", "-p", "foo", "--release"])
31+
self.assertEqual(
32+
action.build_command("foo"),
33+
["path/to/cargo", "build", "-p", "foo", "--target", "x86_64-unknown-linux-musl", "--release"],
34+
)
3235

3336
def test_nonlinux_release_build_cargo_command(self):
3437
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
3538
action = BuildAction("source_dir", "foo", {"cargo": cargo}, "darwin", BuildMode.RELEASE)
3639
self.assertEqual(
3740
action.build_command("foo"),
38-
["path/to/cargo", "build", "-p", "foo", "--release", "--target", "x86_64-unknown-linux-musl"],
41+
["path/to/cargo", "build", "-p", "foo", "--target", "x86_64-unknown-linux-musl", "--release"],
3942
)
4043

4144
def test_linux_debug_build_cargo_command(self):
4245
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
4346
action = BuildAction("source_dir", "foo", {"cargo": cargo}, "linux", BuildMode.DEBUG)
44-
self.assertEqual(action.build_command("foo"), ["path/to/cargo", "build", "-p", "foo"])
47+
self.assertEqual(
48+
action.build_command("foo"),
49+
["path/to/cargo", "build", "-p", "foo", "--target", "x86_64-unknown-linux-musl"],
50+
)
4551

4652
def test_nonlinux_debug_build_cargo_command(self):
4753
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")

0 commit comments

Comments
 (0)