Skip to content

Commit 008bf08

Browse files
committedApr 29, 2024·
Merge branch 'develop'
2 parents 45d8ced + 86e572a commit 008bf08

File tree

8 files changed

+69
-16
lines changed

8 files changed

+69
-16
lines changed
 

‎aws_lambda_builders/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# Changing version will trigger a new release!
66
# Please make the version change as the last step of your development.
77

8-
__version__ = "1.48.0"
8+
__version__ = "1.49.0"
99
RPC_PROTOCOL_VERSION = "0.3"

‎aws_lambda_builders/builder.py

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def build(
6060
scratch_dir,
6161
manifest_path,
6262
runtime=None,
63+
unpatched_runtime=None,
6364
optimizations=None,
6465
options=None,
6566
executable_search_paths=None,
@@ -154,6 +155,7 @@ def build(
154155
scratch_dir,
155156
manifest_path,
156157
runtime=runtime,
158+
unpatched_runtime=unpatched_runtime,
157159
optimizations=optimizations,
158160
options=options,
159161
executable_search_paths=executable_search_paths,

‎aws_lambda_builders/workflow.py

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(
201201
is_building_layer=False,
202202
experimental_flags=None,
203203
build_in_source=None,
204+
unpatched_runtime=None,
204205
):
205206
# pylint: disable-msg=too-many-locals
206207
"""
@@ -263,6 +264,7 @@ def __init__(
263264
self.combine_dependencies = combine_dependencies
264265
self.architecture = architecture
265266
self.is_building_layer = is_building_layer
267+
self.unpatched_runtime = unpatched_runtime
266268
self.experimental_flags = experimental_flags if experimental_flags else []
267269

268270
# this represents where the build/install happens, not the final output directory (that's the artifacts_dir)

‎aws_lambda_builders/workflows/rust_cargo/actions.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(
2626
binaries,
2727
mode,
2828
subprocess_cargo_lambda,
29+
runtime=None,
2930
architecture=X86_64,
3031
handler=None,
3132
flags=None,
@@ -68,18 +69,27 @@ def __init__(
6869
self._flags = flags
6970
self._architecture = architecture
7071
self._subprocess_cargo_lambda = subprocess_cargo_lambda
72+
self._runtime = runtime
7173

7274
def build_command(self):
7375
cmd = [self._binaries["cargo"].binary_path, "lambda", "build"]
7476
if self._mode != BuildMode.DEBUG:
7577
cmd.append("--release")
76-
if self._architecture == ARM64:
78+
# Provided.al2 runtime only has GLIB_2.26 and cargo lambda builds with a higher version by default
79+
if self._runtime == "provided.al2":
80+
if self._architecture == ARM64:
81+
# We cant use the --arm shortcut because then the incorrect version of GLIBC is used
82+
cmd.append("--target")
83+
cmd.append("aarch64-unknown-linux-gnu.2.26")
84+
if self._architecture == X86_64:
85+
cmd.append("--target")
86+
cmd.append("x86_64-unknown-linux-gnu.2.26")
87+
elif self._architecture == ARM64:
7788
cmd.append("--arm64")
7889
if self._handler:
7990
cmd.extend(["--bin", self._handler])
8091
if self._flags:
8192
cmd.extend(self._flags)
82-
8393
return cmd
8494

8595
def execute(self):

‎aws_lambda_builders/workflows/rust_cargo/workflow.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ class RustCargoLambdaWorkflow(BaseWorkflow):
2222

2323
SUPPORTED_MANIFESTS = ["Cargo.toml"]
2424

25-
def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, mode=None, **kwargs):
25+
def __init__(
26+
self,
27+
source_dir,
28+
artifacts_dir,
29+
scratch_dir,
30+
manifest_path,
31+
runtime=None,
32+
unpatched_runtime=None,
33+
mode=None,
34+
**kwargs,
35+
):
2636
super(RustCargoLambdaWorkflow, self).__init__(
2737
source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs
2838
)
@@ -43,6 +53,7 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim
4353
self.binaries,
4454
mode,
4555
subprocess_cargo_lambda,
56+
unpatched_runtime,
4657
self.architecture,
4758
handler,
4859
flags,

‎requirements/dev.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ parameterized==0.9.0
88
pyelftools~=0.31 # Used to verify the generated Go binary architecture in integration tests (utils.py)
99

1010
# formatter
11-
black==24.3.0
12-
ruff==0.3.4
11+
black==24.4.0
12+
ruff==0.4.1

‎tests/unit/test_builder.py

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def test_with_mocks(
178178
"manifest_path",
179179
architecture="arm64",
180180
runtime="runtime",
181+
unpatched_runtime=None,
181182
optimizations="optimizations",
182183
options="options",
183184
executable_search_paths="executable_search_paths",

‎tests/unit/workflows/rust_cargo/test_actions.py

+37-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest import TestCase
22
from unittest.mock import patch
3+
from parameterized import parameterized
34
import io
45
import logging
56
import os
@@ -43,9 +44,35 @@ def which(cmd, executable_search_paths):
4344
proc = SubprocessCargoLambda(which=which, osutils=self.osutils)
4445
self.subprocess_cargo_lambda = proc
4546

47+
@parameterized.expand(
48+
[
49+
("provided.al2", "x86_64", "x86_64-unknown-linux-gnu.2.26"),
50+
("provided.al2", "arm64", "aarch64-unknown-linux-gnu.2.26"),
51+
]
52+
)
53+
def test_release_build_cargo_command_with_correct_targets(self, runtime, architecture, expected_target):
54+
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
55+
action = RustCargoLambdaBuildAction(
56+
"source_dir", {"cargo": cargo}, None, self.subprocess_cargo_lambda, runtime, architecture
57+
)
58+
self.assertEqual(
59+
action.build_command(),
60+
["path/to/cargo", "lambda", "build", "--release", "--target", expected_target],
61+
)
62+
63+
def test_release_build_cargo_command_for_provided_al2023(self):
64+
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
65+
action = RustCargoLambdaBuildAction(
66+
"source_dir", {"cargo": cargo}, None, self.subprocess_cargo_lambda, "provided.al2023"
67+
)
68+
self.assertEqual(
69+
action.build_command(),
70+
["path/to/cargo", "lambda", "build", "--release"],
71+
)
72+
4673
def test_release_build_cargo_command_without_release_mode(self):
4774
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
48-
action = RustCargoLambdaBuildAction("source_dir", {"cargo": cargo}, None, self.subprocess_cargo_lambda)
75+
action = RustCargoLambdaBuildAction("source_dir", {"cargo": cargo}, None, None, self.subprocess_cargo_lambda)
4976
self.assertEqual(
5077
action.build_command(),
5178
["path/to/cargo", "lambda", "build", "--release"],
@@ -54,7 +81,7 @@ def test_release_build_cargo_command_without_release_mode(self):
5481
def test_release_build_cargo_command(self):
5582
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
5683
action = RustCargoLambdaBuildAction(
57-
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
84+
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda
5885
)
5986
self.assertEqual(
6087
action.build_command(),
@@ -64,7 +91,7 @@ def test_release_build_cargo_command(self):
6491
def test_release_build_cargo_command_with_target(self):
6592
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
6693
action = RustCargoLambdaBuildAction(
67-
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda, "arm64"
94+
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, None, self.subprocess_cargo_lambda, "arm64"
6895
)
6996
self.assertEqual(
7097
action.build_command(),
@@ -74,7 +101,7 @@ def test_release_build_cargo_command_with_target(self):
74101
def test_debug_build_cargo_command(self):
75102
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
76103
action = RustCargoLambdaBuildAction(
77-
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda
104+
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda
78105
)
79106
self.assertEqual(
80107
action.build_command(),
@@ -84,7 +111,7 @@ def test_debug_build_cargo_command(self):
84111
def test_debug_build_cargo_command_with_architecture(self):
85112
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
86113
action = RustCargoLambdaBuildAction(
87-
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64"
114+
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64"
88115
)
89116
self.assertEqual(
90117
action.build_command(),
@@ -95,7 +122,7 @@ def test_debug_build_cargo_command_with_flags(self):
95122
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
96123
flags = ["--package", "package-in-workspace"]
97124
action = RustCargoLambdaBuildAction(
98-
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64", flags=flags
125+
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64", flags=flags
99126
)
100127
self.assertEqual(
101128
action.build_command(),
@@ -105,7 +132,7 @@ def test_debug_build_cargo_command_with_flags(self):
105132
def test_debug_build_cargo_command_with_handler(self):
106133
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
107134
action = RustCargoLambdaBuildAction(
108-
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, self.subprocess_cargo_lambda, "arm64", handler="foo"
135+
"source_dir", {"cargo": cargo}, BuildMode.DEBUG, None, self.subprocess_cargo_lambda, "arm64", handler="foo"
109136
)
110137
self.assertEqual(
111138
action.build_command(),
@@ -115,7 +142,7 @@ def test_debug_build_cargo_command_with_handler(self):
115142
def test_execute_happy_path(self):
116143
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
117144
action = RustCargoLambdaBuildAction(
118-
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
145+
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda, None
119146
)
120147
action.execute()
121148

@@ -125,7 +152,7 @@ def test_execute_cargo_build_fail(self):
125152

126153
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
127154
action = RustCargoLambdaBuildAction(
128-
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
155+
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda, None
129156
)
130157
with self.assertRaises(ActionFailedError) as err_assert:
131158
action.execute()
@@ -136,7 +163,7 @@ def test_execute_happy_with_logger(self):
136163
with patch.object(LOG, "debug") as mock_warning:
137164
cargo = BinaryPath(None, None, None, binary_path="path/to/cargo")
138165
action = RustCargoLambdaBuildAction(
139-
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda
166+
"source_dir", {"cargo": cargo}, BuildMode.RELEASE, self.subprocess_cargo_lambda, None
140167
)
141168
out = action.execute()
142169
self.assertEqual(out, "out")

0 commit comments

Comments
 (0)
Please sign in to comment.