Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e02f8bd
chore(deps): update actions/checkout action to v6.1.0
renovate[bot] Aug 1, 2026
46ab602
Remove unnecessary return at end of functions
gkamathe Aug 1, 2026
8d0c67a
make __CARGO_TEST_FORCE_ARGFILE available in distributed builds
RalfJung Aug 1, 2026
ee45672
make __CARGO_TEST_FORCE_ARGFILE available in distributed builds (#17293)
weihanglo Aug 1, 2026
965260a
Remove unnecessary return at end of functions (#17292)
weihanglo Aug 1, 2026
9db6ed9
chore(deps): update actions/checkout action to v6.1.0 (#17290)
epage Aug 1, 2026
34a4d22
chore(deps): update embarkstudios/cargo-deny-action action to v2.1.1
renovate[bot] Aug 1, 2026
a3e60bf
Remove unnecessary to_path_buf
gkamathe Aug 1, 2026
ae4012a
chore(deps): update cargo-semver-checks to v0.50.0
renovate[bot] Aug 1, 2026
b0fce7a
chore(deps): update cargo-semver-checks to v0.50.0 (#17297)
epage Aug 1, 2026
f6e9c90
test(build-script): cover empty `package.build`
raushan728 Jul 30, 2026
65f2ce9
fix(manifest): prevent panic on empty `package.build`
raushan728 Jul 28, 2026
5727d3b
Remove unnecessary to_path_buf (#17295)
ranger-ross Aug 2, 2026
e3dfce8
Avoid parsing unchanged lockfiles
charliermarsh Aug 2, 2026
614ec56
Avoid parsing unchanged lockfiles (#17301)
weihanglo Aug 3, 2026
5ca823a
fix(trim-paths): unambiguous and reversible remap rules (#17302)
epage Aug 3, 2026
936fb92
refactor: move the sysroot path to the GlobalContext
adamgemmell Jul 30, 2026
9f3c326
refactor: update all users of the sysroot path
adamgemmell Jul 30, 2026
4c20b84
test(cfg): use the gctx sysroot when building TargetInfo
adamgemmell Aug 3, 2026
73d6ebe
test: Add a test for workspace fields that may produce suggestions
Aug 3, 2026
5211c74
fix: Add a suggestion when adding `[lints]` to a workspace to use `[w…
Aug 3, 2026
fee70b3
refactor: move sysroot lookup to GlobalContext (#17276)
epage Aug 3, 2026
e0c3d7c
chore(deps): update embarkstudios/cargo-deny-action action to v2.1.1 …
epage Aug 3, 2026
983b566
Add a suggestion when adding `[lints]` to a workspace to use `[worksp…
epage Aug 3, 2026
88e0ae8
fix: prevent panic when `package.build` is empty (#17268)
epage Aug 3, 2026
f97d6b1
test(trim-paths): cover unremap file scenarios
weihanglo Jul 31, 2026
a14b303
refactor(trim-paths): return remap pairs from rules
weihanglo Jul 31, 2026
f29201b
feat(trim-paths): emit unremap files for final artifacts
weihanglo Jul 31, 2026
9db4a63
docs(trim-paths): emit unremap files for final artifacts
weihanglo Jul 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- advisories
- bans licenses sources
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: EmbarkStudios/cargo-deny-action@bb137d7af7e4fb67e5f82a49c4fce4fad40782fe # v2.0.20
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1
# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Install mdbook
run: |
mkdir mdbook
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: rustup component add rustfmt
- run: cargo fmt --all --check
Expand All @@ -79,30 +79,30 @@ jobs:
env:
CARGO_BUILD_WARNINGS: deny
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: rustup component add clippy
- run: cargo clippy --workspace --all-targets --no-deps --keep-going

stale-label:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: cargo stale-label

lint-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: cargo lint-docs --check

# Ensure Cargo.lock is up-to-date
lockfile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: cargo update -p cargo --locked

Expand All @@ -113,14 +113,14 @@ jobs:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha != '' && github.event.pull_request.head.sha || github.sha }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
- run: rustup update stable && rustup default stable
- name: Install cargo-semver-checks
run: |
mkdir installed-bins
curl -Lf https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.49.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz \
curl -Lf https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.50.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz \
| tar -xz --directory=./installed-bins
echo `pwd`/installed-bins >> $GITHUB_PATH
- run: ci/validate-version-bump.sh
Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
other: i686-pc-windows-gnu
name: Tests ${{ matrix.name }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Dump Environment
run: ci/dump-environment.sh
# Some tests require stable. Make sure it is set to the most recent stable
Expand Down Expand Up @@ -274,21 +274,21 @@ jobs:
schema:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: cargo test -p cargo-util-schemas -F unstable-schema

resolver:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update stable && rustup default stable
- run: cargo test -p resolver-tests

test_gitoxide:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update --no-self-update stable && rustup default stable
- run: rustup target add i686-unknown-linux-gnu
- run: rustup target add wasm32-unknown-unknown
Expand All @@ -301,7 +301,7 @@ jobs:
build_std:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update nightly && rustup default nightly
- run: rustup component add rust-src
- run: cargo build
Expand All @@ -311,7 +311,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update nightly && rustup default nightly
- run: rustup update stable
- run: rustup component add rust-docs
Expand Down Expand Up @@ -339,7 +339,7 @@ jobs:
msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- uses: taiki-e/install-action@16b05812d776ae1dfaabc8277e421fb6d2506419 # v2.82.7
with:
tool: cargo-hack
Expand All @@ -350,15 +350,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Spell Check Repo
uses: crate-ci/typos@bee27e3a4fd1ea2111cf90ab89cd076c870fce14 # v1.48.0

report-timings:
name: Timing HTML report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- run: rustup update nightly && rustup default nightly
- run: cargo build
- name: Generate timing report for rustfix
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

steps:
- name: Checkout the source code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Publish Cargo to crates.io
run: ./publish.py
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-util/src/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl ProcessBuilder {
///
/// You should set `__CARGO_TEST_FORCE_ARGFILE` to enable this.
fn debug_force_argfile(retry_enabled: bool) -> bool {
cfg!(debug_assertions) && env::var("__CARGO_TEST_FORCE_ARGFILE").is_ok() && retry_enabled
retry_enabled && env::var("__CARGO_TEST_FORCE_ARGFILE").is_ok()
}

/// Creates new pipes for stderr, stdout, and optionally stdin.
Expand Down
38 changes: 38 additions & 0 deletions doc/book/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,44 @@ Paths to all other source files will not be affected.

This will not affect any hard-coded paths in the source code, such as in strings.

##### Unremap files

When the `object` scope is active and debuginfo is enabled,
Cargo writes an unremap file beside each final artifact.
The file is aimed at helping debuggers substitute sanitized paths back to local ones,
e.g., via GDB's `set substitute-path` or LLDB's `target.source-map`.

The unremap file name ends with `.trim-paths.jsonl`.
For example,
your `my-app` executable would come with an unremap file named
`my-app.trim-paths.jsonl` beside it.

The unremap file is in JSONL format:

* The first record carries the format version.
* The second record is file-level metadata,
such as the toolchain version and the workspace root.
* Each following record maps a sanitized path prefix in the artifact
(`from`) back to the local path it replaced (`to`),
ordered by the `from` prefix.
Note that this follows the debugger substitution direction,
which is the inverse of `--remap-path-prefix`.

An example of the unremap file:

```json
{"v":1}
{"rust_version":"1.96.0-nightly","workspace_root":"/home/me/app"}
{"from":"/cargo/build-dir","to":"/home/me/app/target"}
{"from":"/cargo/registry/6f17d22d3f0a95d1","to":"/home/me/.cargo/registry/src/index.crates.io-6f17d22d3f0a95d1"}
{"from":"/rustc/abc123","to":"/home/me/.rustup/toolchains/nightly/lib/rustlib/src/rust"}
```

Since it is meant to be a debugging aid,
it includes absolute paths of your system,
so there is no artifact privacy guarantee.
You might want to exclude `*.trim-paths.jsonl` files when distributing artifacts.

#### Environment variable

*as a new entry of ["Environment variables Cargo sets for build scripts"](./environment-variables.md#environment-variables-cargo-sets-for-crates)*
Expand Down
14 changes: 14 additions & 0 deletions src/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! [`BuildContext`] is a (mostly) static information about a build task.

use std::path::Path;

use crate::compiler::BuildConfig;
use crate::compiler::CompileKind;
use crate::compiler::Unit;
Expand Down Expand Up @@ -162,6 +164,18 @@ impl<'a, 'gctx> BuildContext<'a, 'gctx> {
pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> {
self.extra_compiler_args.get(unit)
}

/// Gets the path to the sysroot.
///
/// Helper function that uses GlobalContext.
pub fn get_sysroot(&self) -> &'gctx Path {
// cfg::bad_cfg_discovery tests that these panics aren't reachable
let rustc = self
.gctx
.load_global_rustc(Some(self.ws))
.expect("rustc load ok");
self.gctx.get_sysroot(&rustc).expect("sysroot fetch ok")
}
}

#[derive(Copy, Clone, Default, Debug)]
Expand Down
40 changes: 17 additions & 23 deletions src/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ pub struct TargetInfo {
pub supports_std: Option<bool>,
/// Supported values for `-Csplit-debuginfo=` flag, queried from rustc
support_split_debuginfo: Vec<String>,
/// Path to the sysroot.
pub sysroot: PathBuf,
/// Path to the "lib" directory in the sysroot which rustc uses for linking
/// target libraries.
pub sysroot_target_libdir: PathBuf,
Expand All @@ -80,6 +78,8 @@ pub enum FileFlavor {
DebugInfo,
/// SBOM (Software Bill of Materials pre-cursor) file (e.g. cargo-sbon.json).
Sbom,
/// Unremap file for `-Ztrim-paths` (e.g. `foo.trim-paths.jsonl`).
Unremap,
/// Cross-crate info JSON files generated by rustdoc.
DocParts,
}
Expand Down Expand Up @@ -165,6 +165,8 @@ impl TargetInfo {
/// invocation is cached by [`Rustc::cached_output`].
///
/// Search `Tricky` to learn why querying `rustc` several times is needed.
///
/// When a Workspace is provided,
#[tracing::instrument(skip_all)]
pub fn new(
gctx: &GlobalContext,
Expand All @@ -174,15 +176,25 @@ impl TargetInfo {
) -> CargoResult<TargetInfo> {
let mut rustflags =
extra_args(gctx, requested_kinds, &rustc.host, None, kind, Flags::Rust)?;

let sysroot = gctx.get_sysroot(rustc)?;
let sysroot_target_libdir = sysroot
.join("lib")
.join("rustlib")
.join(match &kind {
CompileKind::Host => rustc.host.as_str(),
CompileKind::Target(target) => target.short_name(),
})
.join("lib");

let mut turn = 0;
loop {
let extra_fingerprint = kind.fingerprint_hash();

// Query rustc for several kinds of info from each line of output:
// 0) file-names (to determine output file prefix/suffix for given crate type)
// 1) sysroot
// 2) split-debuginfo
// 3) cfg
// 1) split-debuginfo
// 2) cfg
//
// Search `--print` to see what we query so far.
let mut process = rustc.workspace_process();
Expand Down Expand Up @@ -216,7 +228,6 @@ impl TargetInfo {
process.arg("--crate-type").arg(crate_type.as_str());
}

process.arg("--print=sysroot");
process.arg("--print=split-debuginfo");
process.arg("--print=crate-name"); // `___` as a delimiter.
process.arg("--print=cfg");
Expand All @@ -238,22 +249,6 @@ impl TargetInfo {
map.insert(crate_type.clone(), out);
}

let Some(line) = lines.next() else {
return error_missing_print_output("sysroot", &process, &output, &error);
};
let sysroot = PathBuf::from(line);
let sysroot_target_libdir = {
let mut libdir = sysroot.clone();
libdir.push("lib");
libdir.push("rustlib");
libdir.push(match &kind {
CompileKind::Host => rustc.host.as_str(),
CompileKind::Target(target) => target.short_name(),
});
libdir.push("lib");
libdir
};

let support_split_debuginfo = {
// HACK: abuse `--print=crate-name` to use `___` as a delimiter.
let mut res = Vec::new();
Expand Down Expand Up @@ -352,7 +347,6 @@ impl TargetInfo {
return Ok(TargetInfo {
crate_type_process,
crate_types: RefCell::new(map),
sysroot,
sysroot_target_libdir,
rustflags: rustflags.into(),
rustdocflags: extra_args(
Expand Down
25 changes: 24 additions & 1 deletion src/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::Arc;
use tracing::debug;

use super::{BuildContext, BuildRunner, CompileKind, FileFlavor, Layout};
use crate::compiler::trim_paths;
use crate::compiler::{CompileMode, CompileTarget, CrateType, FileType, Unit};
use crate::util::{self, CargoResult, OnceExt, StableHasher};
use crate::workspace::{Target, TargetKind, Workspace};
Expand Down Expand Up @@ -612,6 +613,28 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
.collect();
outputs.extend(sbom_files.into_iter());
}

// Only generates unremap files for root units.
// FIXME: might need to consider artifact dependencies?
if bcx.roots.contains(unit) && trim_paths::should_emit_unremap_file(unit) {
let unremap_files: Vec<_> = outputs
.iter()
.filter(|o| matches!(o.flavor, FileFlavor::Normal | FileFlavor::Linkable))
.map(|output| OutputFile {
path: trim_paths::append_unremap_suffix(&output.path),
hardlink: output
.hardlink
.as_ref()
.map(trim_paths::append_unremap_suffix),
export_path: output
.export_path
.as_ref()
.map(trim_paths::append_unremap_suffix),
flavor: FileFlavor::Unremap,
})
.collect();
outputs.extend(unremap_files.into_iter());
}
outputs
}
};
Expand Down Expand Up @@ -735,7 +758,7 @@ fn compute_metadata(
// SourceId for stdlib crates is an absolute path inside the sysroot.
// Pass the sysroot as workspace root so that we hash a relative path.
// This avoids the metadata hash changing depending on where the user installed rustc.
&bcx.target_data.get_info(unit.kind).unwrap().sysroot
&bcx.get_sysroot()
} else {
bcx.ws.root()
};
Expand Down
Loading