Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specify glibc version when building with cargo lambda for provided.al2 #640

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws_lambda_builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def build(
scratch_dir,
manifest_path,
runtime=None,
unpatched_runtime=None,
optimizations=None,
options=None,
executable_search_paths=None,
Expand Down Expand Up @@ -154,6 +155,7 @@ def build(
scratch_dir,
manifest_path,
runtime=runtime,
unpatched_runtime=unpatched_runtime,
optimizations=optimizations,
options=options,
executable_search_paths=executable_search_paths,
Expand Down
2 changes: 2 additions & 0 deletions aws_lambda_builders/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def __init__(
is_building_layer=False,
experimental_flags=None,
build_in_source=None,
unpatched_runtime=None,
):
# pylint: disable-msg=too-many-locals
"""
Expand Down Expand Up @@ -263,6 +264,7 @@ def __init__(
self.combine_dependencies = combine_dependencies
self.architecture = architecture
self.is_building_layer = is_building_layer
self.unpatched_runtime = unpatched_runtime
self.experimental_flags = experimental_flags if experimental_flags else []

# this represents where the build/install happens, not the final output directory (that's the artifacts_dir)
Expand Down
14 changes: 12 additions & 2 deletions aws_lambda_builders/workflows/rust_cargo/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
source_dir,
binaries,
mode,
runtime,
sidhujus marked this conversation as resolved.
Show resolved Hide resolved
subprocess_cargo_lambda,
architecture=X86_64,
handler=None,
Expand Down Expand Up @@ -68,18 +69,27 @@ def __init__(
self._flags = flags
self._architecture = architecture
self._subprocess_cargo_lambda = subprocess_cargo_lambda
self._runtime = runtime

def build_command(self):
cmd = [self._binaries["cargo"].binary_path, "lambda", "build"]
if self._mode != BuildMode.DEBUG:
cmd.append("--release")
if self._architecture == ARM64:
# Provided.al2 runtime only has GLIB_2.26 and cargo lambda builds with a higher version by default
if self._runtime == "provided.al2":
lucashuy marked this conversation as resolved.
Show resolved Hide resolved
if self._architecture == ARM64:
# We cant use the --arm shortcut because then the incorrect version of GLIBC is used
cmd.append("--target")
cmd.append("aarch64-unknown-linux-gnu.2.26")
if self._architecture == X86_64:
cmd.append("--target")
cmd.append("x86_64-unknown-linux-gnu.2.26")
elif self._architecture == ARM64:
cmd.append("--arm64")
if self._handler:
cmd.extend(["--bin", self._handler])
if self._flags:
cmd.extend(self._flags)

return cmd

def execute(self):
Expand Down
13 changes: 12 additions & 1 deletion aws_lambda_builders/workflows/rust_cargo/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ class RustCargoLambdaWorkflow(BaseWorkflow):

SUPPORTED_MANIFESTS = ["Cargo.toml"]

def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, mode=None, **kwargs):
def __init__(
self,
source_dir,
artifacts_dir,
scratch_dir,
manifest_path,
runtime=None,
unpatched_runtime=None,
mode=None,
**kwargs,
):
super(RustCargoLambdaWorkflow, self).__init__(
source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs
)
Expand All @@ -42,6 +52,7 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim
source_dir,
self.binaries,
mode,
unpatched_runtime,
subprocess_cargo_lambda,
self.architecture,
handler,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def test_with_mocks(
"manifest_path",
architecture="arm64",
runtime="runtime",
unpatched_runtime=None,
optimizations="optimizations",
options="options",
executable_search_paths="executable_search_paths",
Expand Down
50 changes: 40 additions & 10 deletions tests/unit/workflows/rust_cargo/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,39 @@ def which(cmd, executable_search_paths):
proc = SubprocessCargoLambda(which=which, osutils=self.osutils)
self.subprocess_cargo_lambda = proc

def test_release_build_cargo_command_for_provided_al2(self):
sidhujus marked this conversation as resolved.
Show resolved Hide resolved
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, None, "provided.al2", self.subprocess_cargo_lambda
)
self.assertEqual(
action.build_command(),
["path/to/cargo", "lambda", "build", "--release", "--target", "x86_64-unknown-linux-gnu.2.26"],
)

def test_release_build_cargo_command_for_provided_al2_arm64(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, None, "provided.al2", self.subprocess_cargo_lambda, "arm64"
)
self.assertEqual(
action.build_command(),
["path/to/cargo", "lambda", "build", "--release", "--target", "aarch64-unknown-linux-gnu.2.26"],
)

def test_release_build_cargo_command_for_provided_al2023(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, None, "provided.al2023", self.subprocess_cargo_lambda
)
self.assertEqual(
action.build_command(),
["path/to/cargo", "lambda", "build", "--release"],
)

def test_release_build_cargo_command_without_release_mode(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction("source_dir", {"cargo": cargo}, None, self.subprocess_cargo_lambda)
action = RustCargoLambdaBuildAction("source_dir", {"cargo": cargo}, None, None, self.subprocess_cargo_lambda)
self.assertEqual(
action.build_command(),
["path/to/cargo", "lambda", "build", "--release"],
Expand All @@ -54,7 +84,7 @@ def test_release_build_cargo_command_without_release_mode(self):
def test_release_build_cargo_command(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda
)
self.assertEqual(
action.build_command(),
Expand All @@ -64,7 +94,7 @@ def test_release_build_cargo_command(self):
def test_release_build_cargo_command_with_target(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda, "arm64"
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda, "arm64"
)
self.assertEqual(
action.build_command(),
Expand All @@ -74,7 +104,7 @@ def test_release_build_cargo_command_with_target(self):
def test_debug_build_cargo_command(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda
)
self.assertEqual(
action.build_command(),
Expand All @@ -84,7 +114,7 @@ def test_debug_build_cargo_command(self):
def test_debug_build_cargo_command_with_architecture(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64"
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64"
)
self.assertEqual(
action.build_command(),
Expand All @@ -95,7 +125,7 @@ def test_debug_build_cargo_command_with_flags(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
flags = ["--package", "package-in-workspace"]
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64", flags=flags
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64", flags=flags
)
self.assertEqual(
action.build_command(),
Expand All @@ -105,7 +135,7 @@ def test_debug_build_cargo_command_with_flags(self):
def test_debug_build_cargo_command_with_handler(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64", handler="foo"
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64", handler="foo"
)
self.assertEqual(
action.build_command(),
Expand All @@ -115,7 +145,7 @@ def test_debug_build_cargo_command_with_handler(self):
def test_execute_happy_path(self):
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda
)
action.execute()

Expand All @@ -125,7 +155,7 @@ def test_execute_cargo_build_fail(self):

cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda
)
with self.assertRaises(ActionFailedError) as err_assert:
action.execute()
Expand All @@ -136,7 +166,7 @@ def test_execute_happy_with_logger(self):
with patch.object(LOG, "debug") as mock_warning:
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
action = RustCargoLambdaBuildAction(
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda
)
out = action.execute()
self.assertEqual(out, "out")
Expand Down
Loading