Skip to content

Commit 88ba857

Browse files
committed
Auto merge of #8350 - Mark-Simulacrum:rust-1.44.1, r=ehuss
1.44.1 stable backports Tried to duplicate #8335, though had to manually adjust 3b9e8dc4c1dc6a6ec714acb6a97b4f7cffda1176 (cherry-pick of #8329) as it had a merge conflict. Stable backports for: * #8329 — Don't hash executable filenames on apple platforms. (fix macos backtraces)
2 parents 05d080f + 56d6aad commit 88ba857

File tree

7 files changed

+60
-346
lines changed

7 files changed

+60
-346
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo"
3-
version = "0.45.0"
3+
version = "0.45.1"
44
edition = "2018"
55
authors = ["Yehuda Katz <[email protected]>",
66
"Carl Lerche <[email protected]>",

src/cargo/core/compiler/context/compilation_files.rs

+52-37
Original file line numberDiff line numberDiff line change
@@ -542,43 +542,8 @@ fn compute_metadata<'a, 'cfg>(
542542
cx: &Context<'a, 'cfg>,
543543
metas: &mut HashMap<Unit<'a>, Option<Metadata>>,
544544
) -> Option<Metadata> {
545-
if unit.mode.is_doc_test() {
546-
// Doc tests do not have metadata.
547-
return None;
548-
}
549-
// No metadata for dylibs because of a couple issues:
550-
// - macOS encodes the dylib name in the executable,
551-
// - Windows rustc multiple files of which we can't easily link all of them.
552-
//
553-
// No metadata for bin because of an issue:
554-
// - wasm32 rustc/emcc encodes the `.wasm` name in the `.js` (rust-lang/cargo#4535).
555-
// - msvc: The path to the PDB is embedded in the executable, and we don't
556-
// want the PDB path to include the hash in it.
557-
//
558-
// Two exceptions:
559-
// 1) Upstream dependencies (we aren't exporting + need to resolve name conflict),
560-
// 2) `__CARGO_DEFAULT_LIB_METADATA` env var.
561-
//
562-
// Note, however, that the compiler's build system at least wants
563-
// path dependencies (eg libstd) to have hashes in filenames. To account for
564-
// that we have an extra hack here which reads the
565-
// `__CARGO_DEFAULT_LIB_METADATA` environment variable and creates a
566-
// hash in the filename if that's present.
567-
//
568-
// This environment variable should not be relied on! It's
569-
// just here for rustbuild. We need a more principled method
570-
// doing this eventually.
571545
let bcx = &cx.bcx;
572-
let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
573-
let short_name = bcx.target_data.short_name(&unit.kind);
574-
if !(unit.mode.is_any_test() || unit.mode.is_check())
575-
&& (unit.target.is_dylib()
576-
|| unit.target.is_cdylib()
577-
|| (unit.target.is_executable() && short_name.starts_with("wasm32-"))
578-
|| (unit.target.is_executable() && short_name.contains("msvc")))
579-
&& unit.pkg.package_id().source_id().is_path()
580-
&& __cargo_default_lib_metadata.is_err()
581-
{
546+
if !should_use_metadata(bcx, unit) {
582547
return None;
583548
}
584549

@@ -641,7 +606,7 @@ fn compute_metadata<'a, 'cfg>(
641606

642607
// Seed the contents of `__CARGO_DEFAULT_LIB_METADATA` to the hasher if present.
643608
// This should be the release channel, to get a different hash for each channel.
644-
if let Ok(ref channel) = __cargo_default_lib_metadata {
609+
if let Ok(ref channel) = env::var("__CARGO_DEFAULT_LIB_METADATA") {
645610
channel.hash(&mut hasher);
646611
}
647612

@@ -688,3 +653,53 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut SipHasher) {
688653
// the future when cranelift sees more use, and people want to switch
689654
// between different backends without recompiling.
690655
}
656+
657+
/// Returns whether or not this unit should use a metadata hash.
658+
fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit<'_>) -> bool {
659+
if unit.mode.is_doc_test() {
660+
// Doc tests do not have metadata.
661+
return false;
662+
}
663+
if unit.mode.is_any_test() || unit.mode.is_check() {
664+
// These always use metadata.
665+
return true;
666+
}
667+
// No metadata in these cases:
668+
//
669+
// - dylibs:
670+
// - macOS encodes the dylib name in the executable, so it can't be renamed.
671+
// - TODO: Are there other good reasons? If not, maybe this should be macos specific?
672+
// - Windows MSVC executables: The path to the PDB is embedded in the
673+
// executable, and we don't want the PDB path to include the hash in it.
674+
// - wasm32 executables: When using emscripten, the path to the .wasm file
675+
// is embedded in the .js file, so we don't want the hash in there.
676+
// TODO: Is this necessary for wasm32-unknown-unknown?
677+
// - apple executables: The executable name is used in the dSYM directory
678+
// (such as `target/debug/foo.dSYM/Contents/Resources/DWARF/foo-64db4e4bf99c12dd`).
679+
// Unfortunately this causes problems with our current backtrace
680+
// implementation which looks for a file matching the exe name exactly.
681+
// See https://github.com/rust-lang/rust/issues/72550#issuecomment-638501691
682+
// for more details.
683+
//
684+
// This is only done for local packages, as we don't expect to export
685+
// dependencies.
686+
//
687+
// The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
688+
// force metadata in the hash. This is only used for building libstd. For
689+
// example, if libstd is placed in a common location, we don't want a file
690+
// named /usr/lib/libstd.so which could conflict with other rustc
691+
// installs. TODO: Is this still a realistic concern?
692+
// See https://github.com/rust-lang/cargo/issues/3005
693+
let short_name = bcx.target_data.short_name(&unit.kind);
694+
if (unit.target.is_dylib()
695+
|| unit.target.is_cdylib()
696+
|| (unit.target.is_executable() && short_name.starts_with("wasm32-"))
697+
|| (unit.target.is_executable() && short_name.contains("msvc"))
698+
|| (unit.target.is_executable() && short_name.contains("-apple-")))
699+
&& unit.pkg.package_id().source_id().is_path()
700+
&& env::var("__CARGO_DEFAULT_LIB_METADATA").is_err()
701+
{
702+
return false;
703+
}
704+
true
705+
}

tests/testsuite/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4162,7 +4162,7 @@ fn uplift_dsym_of_bin_on_mac() {
41624162
assert!(p.target_debug_dir().join("foo.dSYM").is_dir());
41634163
assert!(p.target_debug_dir().join("b.dSYM").is_dir());
41644164
assert!(p.target_debug_dir().join("b.dSYM").is_symlink());
4165-
assert!(p.target_debug_dir().join("examples/c.dSYM").is_symlink());
4165+
assert!(p.target_debug_dir().join("examples/c.dSYM").is_dir());
41664166
assert!(!p.target_debug_dir().join("c.dSYM").exists());
41674167
assert!(!p.target_debug_dir().join("d.dSYM").exists());
41684168
}

tests/testsuite/collisions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ This may become a hard error in the future; see <https://github.com/rust-lang/ca
9191
}
9292

9393
#[cargo_test]
94-
// --out-dir and examples are currently broken on MSVC.
94+
// --out-dir and examples are currently broken on MSVC and apple.
9595
// See https://github.com/rust-lang/cargo/issues/7493
96-
#[cfg(not(target_env = "msvc"))]
96+
#[cfg_attr(any(target_env = "msvc", target_vendor = "apple"), ignore)]
9797
fn collision_export() {
9898
// `--out-dir` combines some things which can cause conflicts.
9999
let p = project()

tests/testsuite/cross_compile.rs

+1-91
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! See `cargo_test_support::cross_compile` for more detail.
44
5+
use cargo_test_support::rustc_host;
56
use cargo_test_support::{basic_bin_manifest, basic_manifest, cross_compile, project};
6-
use cargo_test_support::{is_nightly, rustc_host};
77

88
#[cargo_test]
99
fn simple_cross() {
@@ -206,96 +206,6 @@ fn linker() {
206206
.run();
207207
}
208208

209-
#[cargo_test]
210-
fn plugin_with_extra_dylib_dep() {
211-
if cross_compile::disabled() {
212-
return;
213-
}
214-
if !is_nightly() {
215-
// plugins are unstable
216-
return;
217-
}
218-
219-
let foo = project()
220-
.file(
221-
"Cargo.toml",
222-
r#"
223-
[package]
224-
name = "foo"
225-
version = "0.0.1"
226-
authors = []
227-
228-
[dependencies.bar]
229-
path = "../bar"
230-
"#,
231-
)
232-
.file(
233-
"src/main.rs",
234-
r#"
235-
#![feature(plugin)]
236-
#![plugin(bar)]
237-
238-
fn main() {}
239-
"#,
240-
)
241-
.build();
242-
let _bar = project()
243-
.at("bar")
244-
.file(
245-
"Cargo.toml",
246-
r#"
247-
[package]
248-
name = "bar"
249-
version = "0.0.1"
250-
authors = []
251-
252-
[lib]
253-
name = "bar"
254-
plugin = true
255-
256-
[dependencies.baz]
257-
path = "../baz"
258-
"#,
259-
)
260-
.file(
261-
"src/lib.rs",
262-
r#"
263-
#![feature(plugin_registrar, rustc_private)]
264-
265-
extern crate baz;
266-
extern crate rustc_driver;
267-
268-
use rustc_driver::plugin::Registry;
269-
270-
#[plugin_registrar]
271-
pub fn foo(reg: &mut Registry) {
272-
println!("{}", baz::baz());
273-
}
274-
"#,
275-
)
276-
.build();
277-
let _baz = project()
278-
.at("baz")
279-
.file(
280-
"Cargo.toml",
281-
r#"
282-
[package]
283-
name = "baz"
284-
version = "0.0.1"
285-
authors = []
286-
287-
[lib]
288-
name = "baz"
289-
crate_type = ["dylib"]
290-
"#,
291-
)
292-
.file("src/lib.rs", "pub fn baz() -> i32 { 1 }")
293-
.build();
294-
295-
let target = cross_compile::alternate();
296-
foo.cargo("build --target").arg(&target).run();
297-
}
298-
299209
#[cargo_test]
300210
fn cross_tests() {
301211
if !cross_compile::can_run_on_host() {

tests/testsuite/freshness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ fn changing_bin_features_caches_targets() {
501501
/* Targets should be cached from the first build */
502502

503503
let mut e = p.cargo("build");
504-
// MSVC does not include hash in binary filename, so it gets recompiled.
505-
if cfg!(target_env = "msvc") {
504+
// MSVC/apple does not include hash in binary filename, so it gets recompiled.
505+
if cfg!(any(target_env = "msvc", target_vendor = "apple")) {
506506
e.with_stderr("[COMPILING] foo[..]\n[FINISHED] dev[..]");
507507
} else {
508508
e.with_stderr("[FINISHED] dev[..]");
@@ -511,7 +511,7 @@ fn changing_bin_features_caches_targets() {
511511
p.rename_run("foo", "off2").with_stdout("feature off").run();
512512

513513
let mut e = p.cargo("build --features foo");
514-
if cfg!(target_env = "msvc") {
514+
if cfg!(any(target_env = "msvc", target_vendor = "apple")) {
515515
e.with_stderr("[COMPILING] foo[..]\n[FINISHED] dev[..]");
516516
} else {
517517
e.with_stderr("[FINISHED] dev[..]");

0 commit comments

Comments
 (0)