Repository navigation
Description
- Repository:
pingdotgg/ts-rust - Target commit:
3cd5898eae9a932a102f2fa769249ed1ce215c6a - File:
scripts/wasm/build.sh:29
Summary
scripts/wasm/build.sh collects --remap-path-prefix entries from CARGO_HOME registry paths and then exports them through RUSTFLAGS. The collection filters out paths containing whitespace instead of quoting them, so a CARGO_HOME under e.g. /tmp/cargo home contributes no remap. The build proceeds (exit 0) with the host path embedded in panic locations; a later panic in the wasm module can disclose the build-host path, and builds from such a cache are not reproducible. The filter was a shortcut for word-splitting the flags, not a deliberate rejection.
Affected code
scripts/wasm/build.sh:
21 profile="${WASM_PROFILE:-wasm}"
22 # --flatten --rereloop builds the control flow of each function again from
23 # its basic blocks, and the two -Oz runs then shrink it: 0.8% smaller raw,
24 # gzip and brotli than "-Oz --converge", at the same speed.
25 opt="${WASM_OPT:---flatten --rereloop -Oz -Oz}"
26
27 # At opt-level "s", LLVM inlines `#[inline]` functions up to cost 325; the
28 # faster build above lowers that to 150.
29 rustflags="${WASM_RUSTFLAGS:-}"
30 # The module keeps the source path of each panic location. Map the paths
31 # that name the build host, as cargo's trim-paths does: the repo to
32 # relative paths, a registry crate to `<name>-<version>/...`, and the
33 # toolchain's library source to `/rustc/<commit>`. RUSTFLAGS splits at
34 # spaces, so a path with a space keeps its name.
35 sysroot="$(rustc --print sysroot)"
36 commit="$(rustc -vV | sed -n 's/^commit-hash: //p')"
37 remaps=("$repo/=" "$sysroot/lib/rustlib/src/rust=/rustc/$commit")
38 for registry in "${CARGO_HOME:-$HOME/.cargo}"/registry/src/*/; do
39 [[ -d "$registry" ]] && remaps+=("$registry=")
40 done
41 for remap in "${remaps[@]}"; do
42 [[ "$remap" == *[[:space:]]* ]] || rustflags="${rustflags:+$rustflags }--remap-path-prefix=$remap"
43 done
44 export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }$rustflags"
45
46 cargo_cmd=(cargo)
47 # The capped runner needs a systemd user session (Linux hosts such as
48 # zbook). CI runners have systemd-run but no user session.
49 if [[ -z "${CI:-}" ]] && command -v systemd-run >/dev/null; then
50 cargo_cmd=("$repo/scripts/run-cargo-capped.sh")
Expected behavior
A legal repository, sysroot, or cargo-registry path containing whitespace is either remapped through an encoding that preserves spaces or rejected explicitly, so host paths are not retained in wasm panic locations.
Actual behavior
At scripts/wasm/build.sh lines 41-42, a remap prefix containing whitespace is skipped, so a legal checkout, sysroot, or registry path is not propagated to rustc; crates/ts_wasm/src/lib.rs lines 192-196 then formats the unremapped file path into panic output.
How to reproduce
Run scripts/wasm/build.sh with CARGO_HOME under a path containing a space; the exported RUSTFLAGS omit the remap for that path.
Root cause
scripts/wasm/build.sh collects --remap-path-prefix entries from CARGO_HOME registry paths and then exports them through RUSTFLAGS. The collection filters out paths containing whitespace instead of quoting them, so a CARGO_HOME under e.g. /tmp/cargo home contributes no remap. The build proceeds (exit 0) with the host path embedded in panic locations; a later panic in the wasm module can disclose the build-host path, and builds from such a cache are not reproducible. The filter was a shortcut for word-splitting the flags, not a deliberate rejection.
Suggested fix
Stop silently dropping whitespace paths:
case "$path" in
*[[:space:]]*) remap="--remap-path-prefix=$path=$target/" ;;
esac
If the build tooling truly cannot accept the space, fail with a clear error instead of exporting RUSTFLAGS without the remap, and add a test with CARGO_HOME under a directory whose name contains a space.
Activity