Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions doc/book/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,8 @@ It takes the following values:

It also takes an array with the combinations of `"macro"`, `"diagnostics"`, and `"object"`.

It is defaulted to `none` for the `dev` profile, and `object` for the `release` profile.
You can manually override it by specifying this option in `Cargo.toml`:
By default, `trim-paths` is not set and path sanitization is disabled for all profiles.
You can enable it by specifying this option in `Cargo.toml`:

```toml
[profile.dev]
Expand All @@ -1539,7 +1539,7 @@ trim-paths = "all"
trim-paths = ["object", "diagnostics"]
```

The default `release` profile setting (`object`) sanitizes only the paths in emitted executable or library files.
The `object` setting sanitizes only the paths in emitted executable or library files.
It always affects paths from macros such as panic messages, and in debug information only if they will be embedded together with the binary
(the default on platforms with ELF binaries, such as Linux and windows-gnu),
but will not touch them if they are in separate files (the default on Windows MSVC and macOS).
Expand Down
18 changes: 4 additions & 14 deletions src/workspace/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ use crate::resolver::features::FeaturesFor;
use crate::util::data_structures::{HashMap, HashSet};
use crate::util::interning::InternedString;
use crate::util::{CargoResult, GlobalContext, closest_msg};
use crate::workspace::Feature;
use crate::workspace::dependency::Artifact;
use crate::workspace::parser::validate_profile;
use crate::workspace::{PackageId, PackageIdSpec, PackageIdSpecQuery, Target, Workspace};
use anyhow::{Context as _, bail};
use cargo_util::is_ci;
use cargo_util_schemas::manifest::TomlTrimPaths;
use cargo_util_schemas::manifest::TomlTrimPathsValue;
use cargo_util_schemas::manifest::{
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
};
Expand Down Expand Up @@ -92,9 +90,7 @@ impl Profiles {
rustc_host,
};

let trim_paths_enabled = ws.unstable_features().is_enabled(Feature::trim_paths())
|| gctx.cli_unstable().trim_paths;
Self::add_root_profiles(&mut profile_makers, &profiles, trim_paths_enabled);
Self::add_root_profiles(&mut profile_makers, &profiles);

// Merge with predefined profiles.
use std::collections::btree_map::Entry;
Expand Down Expand Up @@ -136,7 +132,6 @@ impl Profiles {
fn add_root_profiles(
profile_makers: &mut Profiles,
profiles: &BTreeMap<InternedString, TomlProfile>,
trim_paths_enabled: bool,
) {
profile_makers.by_name.insert(
"dev".into(),
Expand All @@ -145,10 +140,7 @@ impl Profiles {

profile_makers.by_name.insert(
"release".into(),
ProfileMaker::new(
Profile::default_release(trim_paths_enabled),
profiles.get("release").cloned(),
),
ProfileMaker::new(Profile::default_release(), profiles.get("release").cloned()),
);
}

Expand Down Expand Up @@ -676,7 +668,7 @@ compact_debug! {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (default, default_name) = match self.name.as_str() {
"dev" => (Profile::default_dev(), "default_dev()"),
"release" => (Profile::default_release(false), "default_release()"),
"release" => (Profile::default_release(), "default_release()"),
_ => (Profile::default(), "default()"),
};
[debug_the_fields(
Expand Down Expand Up @@ -738,13 +730,11 @@ impl Profile {
}

/// Returns a built-in `release` profile.
fn default_release(trim_paths_enabled: bool) -> Profile {
let trim_paths = trim_paths_enabled.then(|| TomlTrimPathsValue::Object.into());
fn default_release() -> Profile {
Profile {
name: "release".into(),
root: ProfileRoot::Release,
opt_level: "3".into(),
trim_paths,
..Profile::default()
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ fn remap_path_scope() {
"
[profile.release]
debug = \"line-tables-only\"
trim-paths = \"object\"
",
)
.build();
Expand Down
19 changes: 12 additions & 7 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Caused by:
}

#[cargo_test]
fn release_profile_default_to_object() {
fn release_profile_default() {
let p = project()
.file(
"Cargo.toml",
Expand All @@ -79,17 +79,22 @@ fn release_profile_default_to_object() {
"#,
)
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
fn main() {
assert!(std::env::var_os("CARGO_TRIM_PATHS_SCOPE").is_none());
assert!(std::env::var_os("CARGO_TRIM_PATHS_REMAP").is_none());
}
"#,
)
.build();

p.cargo("build --release --verbose")
.arg("-Ztrim-paths")
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc [..]--remap-path-scope=object --remap-path-prefix=[ROOT]/foo=. --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s

"#]])
.with_stderr_does_not_contain("[..]--remap-path-scope=[..]")
.with_stderr_does_not_contain("[..]--remap-path-prefix=[..]")
.run();
}

Expand Down