Add musl target and cargo config for Rust

This commit is contained in:
Chris Wanstrath 2026-03-15 09:24:27 -07:00
parent 3c6cd05ef7
commit b8c9603c71

View File

@ -161,6 +161,17 @@ async function installPersistentTooling(log?: (msg: string) => void): Promise<vo
await run(
$`container exec --user ${USER} ${CONTAINER_NAME} env ${`RUSTUP_HOME=${CONTAINER_ENV.RUSTUP_HOME}`} ${`CARGO_HOME=${CONTAINER_ENV.CARGO_HOME}`} bash -c ${"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"}`,
"Rust installation")
// Add musl target so Rust can link without a system C linker
await run(
$`container exec --user ${USER} ${CONTAINER_NAME} env ${`RUSTUP_HOME=${CONTAINER_ENV.RUSTUP_HOME}`} ${`CARGO_HOME=${CONTAINER_ENV.CARGO_HOME}`} ${`PATH=${CONTAINER_ENV.CARGO_HOME}/bin:$PATH`} rustup target add aarch64-unknown-linux-musl`,
"Rust musl target")
}
// Ensure cargo config exists for musl target (even if Rust was already installed)
const hasCargoConfig = await $`container exec --user ${USER} ${CONTAINER_NAME} test -f /sandlot/.cargo/config.toml`.nothrow().quiet()
if (hasCargoConfig.exitCode !== 0) {
const cargoConfig = `[target.aarch64-unknown-linux-musl]\nlinker = "rust-lld"\n\n[build]\ntarget = "aarch64-unknown-linux-musl"\n`
await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${`echo -e '${cargoConfig}' > /sandlot/.cargo/config.toml`}`.quiet()
}
// Go — skip if already installed on the persistent mount