Skip to content

Commit 5edea55

Browse files
committed
build: Build all cargo executables at once
1 parent a50788a commit 5edea55

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

ci/builder/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ RUN mkdir rust \
172172
&& `: Until https://github.com/est31/cargo-udeps/pull/147 is released in cargo-udeps` \
173173
&& cargo install --root /usr/local --git https://github.com/est31/cargo-udeps --rev=b84d478ef3efd7264dba8c15c31a50c6399dc5bb --locked cargo-udeps --features=vendored-openssl \
174174
&& cargo install --root /usr/local --version "=0.2.15" --no-default-features --features=s3,openssl/vendored sccache \
175-
&& cargo install --root /usr/local --version "=0.3.6" cargo-binutils
175+
&& cargo install --root /usr/local --version "=0.3.6" cargo-binutils \
176176

177177
# Link the system lld into the cross-compiling sysroot.
178178

misc/python/materialize/mzbuild.py

+35-17
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,28 @@ def extra(self) -> str:
302302
return ",".join(flags)
303303

304304

305+
def generate_cargo_build_command(
306+
bins: List[str],
307+
examples: List[str],
308+
rd: RepositoryDetails,
309+
) -> List[str]:
310+
rustflags = rustc_flags.coverage if rd.coverage else []
311+
312+
cargo_build = [*rd.cargo("build", channel=None, rustflags=rustflags)]
313+
314+
for bin in bins:
315+
cargo_build.extend(["--bin", bin])
316+
for example in examples:
317+
cargo_build.extend(["--example", example])
318+
319+
if rd.release_mode:
320+
cargo_build.append("--release")
321+
322+
return cargo_build
323+
324+
305325
class CargoBuild(CargoPreImage):
306-
"""A pre-image action that builds a single binary with Cargo."""
326+
"""A pre-image action that builds individual binaries with Cargo."""
307327

308328
def __init__(self, rd: RepositoryDetails, path: Path, config: Dict[str, Any]):
309329
super().__init__(rd, path)
@@ -314,26 +334,10 @@ def __init__(self, rd: RepositoryDetails, path: Path, config: Dict[str, Any]):
314334
self.strip = config.pop("strip", True)
315335
self.split_debuginfo = config.pop("split_debuginfo", False)
316336
self.extract = config.pop("extract", {})
317-
self.rustflags = config.pop("rustflags", [])
318-
self.channel = None
319-
if rd.coverage:
320-
self.rustflags += rustc_flags.coverage
321337
if len(self.bins) == 0 and len(self.examples) == 0:
322338
raise ValueError("mzbuild config is missing pre-build target")
323339

324340
def build(self) -> None:
325-
cargo_build = [
326-
*self.rd.cargo("build", channel=self.channel, rustflags=self.rustflags)
327-
]
328-
329-
for bin in self.bins:
330-
cargo_build.extend(["--bin", bin])
331-
for example in self.examples:
332-
cargo_build.extend(["--example", example])
333-
334-
if self.rd.release_mode:
335-
cargo_build.append("--release")
336-
spawn.runv(cargo_build, cwd=self.rd.root)
337341
cargo_profile = "release" if self.rd.release_mode else "debug"
338342

339343
def copy(exe: Path) -> None:
@@ -392,6 +396,10 @@ def copy(exe: Path) -> None:
392396
copy(Path("examples") / example)
393397

394398
if self.extract:
399+
cargo_build = generate_cargo_build_command(
400+
self.bins, self.examples, self.rd
401+
)
402+
395403
output = spawn.capture(
396404
cargo_build + ["--message-format=json"],
397405
cwd=self.rd.root,
@@ -584,6 +592,16 @@ def build(self) -> None:
584592
for dep in self.dependencies.values():
585593
dep.acquire()
586594
spawn.runv(["git", "clean", "-ffdX", self.image.path])
595+
bins = []
596+
examples = []
597+
for pre_image in self.image.pre_images:
598+
if isinstance(pre_image, CargoBuild):
599+
bins.extend(pre_image.bins)
600+
examples.extend(pre_image.examples)
601+
602+
cargo_build = generate_cargo_build_command(bins, examples, self.image.rd)
603+
spawn.runv(cargo_build, cwd=self.image.rd.root)
604+
587605
for pre_image in self.image.pre_images:
588606
pre_image.run()
589607
build_args = {

0 commit comments

Comments
 (0)