repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

build: mold linker gate and nextest config-warning gate

e1a4fab037163c9c8c9973b09ac32fe67b0f0efd

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

+69 / −2 text lines

Diff layout

.cargo/config.toml

Modified

+4 / −0 text lines

3838[registries.crates-io]
3939protocol = "sparse"
41# mold is a build prerequisite on this target; `cargo x check` verifies it.
42[target.x86_64-unknown-linux-gnu]
43rustflags = ["-C", "link-arg=-fuse-ld=mold"]
4145# Native Termux ARM64: vendored LuaJIT needs compiler-rt for __clear_cache.
4246# `latest` is Termux's stable symlink to the installed Clang resource version.
4347[target.aarch64-linux-android]

xtask/src/main.rs

Modified

+65 / −2 text lines

1111 env,
1212 ffi::OsString,
1313 fs,
14 io::Write,
14 io::{BufRead, Write},
1515 path::{Path, PathBuf},
1616 process::Command,
1717 process::ExitCode,
7575fn check() -> ExitCode {
7676 sequence(&[
77 ensure_mold,
7778 cargo_fmt,
7879 cargo_clippy,
7980 arch,
115116fn cargo_nextest() -> ExitCode {
116 cargo(&["nextest", "run", "--workspace", "--all-features"])
117 nextest_run(&["--workspace", "--all-features"])
118}
120/// nextest has no warning-deny flag, so config-drift warnings are turned into
121/// a gate failure by scanning its stderr.
122fn nextest_run(args: &[&str]) -> ExitCode {
123 let mut child = match Command::new("cargo")
124 .arg("nextest")
125 .arg("run")
126 .args(args)
127 .stdout(std::process::Stdio::inherit())
128 .stderr(std::process::Stdio::piped())
129 .spawn()
130 {
131 Ok(child) => child,
132 Err(error) => return fail(&format!("failed to run cargo nextest: {error}\n")),
133 };
134 let mut warned = false;
135 if let Some(stderr) = child.stderr.take() {
136 let reader = std::io::BufReader::new(stderr);
137 for line in reader.lines() {
138 let Ok(line) = line else {
139 break;
140 };
141 if line.contains("warning: in config file") {
142 warned = true;
143 }
144 let _ = std::io::stderr().write_all(format!("{line}\n").as_bytes());
145 }
146 }
147 match child.wait() {
148 Ok(status) if status.success() && !warned => ExitCode::SUCCESS,
149 Ok(status) if status.success() => fail("nextest produced config file warnings\n"),
150 Ok(status) => fail(&format!(
151 "cargo exited with exit status: {}\n",
152 status.code().unwrap_or_default()
153 )),
154 Err(error) => fail(&format!("failed to wait for cargo nextest: {error}\n")),
155 }
119158fn cargo_pup() -> ExitCode {
130169 run("cargo-machete", &[])
172/// mold is a build prerequisite on linux-gnu `x86_64`; xtask verifies it, the
173/// system package manager installs it.
174fn ensure_mold() -> ExitCode {
175 if cfg!(all(
176 target_arch = "x86_64",
177 target_os = "linux",
178 target_env = "gnu"
179 )) {
180 match Command::new("mold")
181 .arg("--version")
182 .stdout(std::process::Stdio::null())
183 .stderr(std::process::Stdio::null())
184 .status()
185 {
186 Ok(status) if status.success() => ExitCode::SUCCESS,
187 _ => fail(
188 "mold linker missing: install it with the system package manager (e.g. pacman -S mold)\n",
189 ),
190 }
191 } else {
192 ExitCode::SUCCESS
193 }
194}
133196/// Install the external gate tools that Cargo cannot ship.
134197///
135198/// `cargo-nextest` arrives as a prebuilt binary through `cargo-binstall`;