Skip to content

Commit e119a63

Browse files
committed
Add metadata suffix, close rust-lang/cargo#4028
1 parent 0e79b97 commit e119a63

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/bootstrap/bin/rustc.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,24 @@ use std::path::PathBuf;
3838
use std::process::{Command, ExitStatus};
3939

4040
fn main() {
41-
let args = env::args_os().skip(1).collect::<Vec<_>>();
41+
let mut args = env::args_os().skip(1).collect::<Vec<_>>();
42+
43+
// Append metadata suffix for internal crates. See the corresponding entry
44+
// in bootstrap/lib.rs for details.
45+
if let Ok(s) = env::var("RUSTC_METADATA_SUFFIX") {
46+
for i in 1..args.len() {
47+
// Dirty code for borrowing issues
48+
let mut new = None;
49+
if let Some(current_as_str) = args[i].to_str() {
50+
if (&*args[i - 1] == "-C" && current_as_str.starts_with("metadata")) ||
51+
current_as_str.starts_with("-Cmetadata") {
52+
new = Some(format!("{}-{}", current_as_str, s));
53+
}
54+
}
55+
if let Some(new) = new { args[i] = new.into(); }
56+
}
57+
}
58+
4259
// Detect whether or not we're a build script depending on whether --target
4360
// is passed (a bit janky...)
4461
let target = args.windows(2)

src/bootstrap/lib.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,30 @@ impl Build {
475475
.env("RUSTDOC_REAL", self.rustdoc(compiler))
476476
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
477477

478-
// Tools don't get debuginfo right now, e.g. cargo and rls don't get
479-
// compiled with debuginfo.
480478
if mode != Mode::Tool {
481-
cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
482-
.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string())
483-
.env("RUSTC_FORCE_UNSTABLE", "1");
479+
// Tools don't get debuginfo right now, e.g. cargo and rls don't
480+
// get compiled with debuginfo.
481+
cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
482+
.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string())
483+
.env("RUSTC_FORCE_UNSTABLE", "1");
484+
485+
// Currently the compiler depends on crates from crates.io, and
486+
// then other crates can depend on the compiler (e.g. proc-macro
487+
// crates). Let's say, for example that rustc itself depends on the
488+
// bitflags crate. If an external crate then depends on the
489+
// bitflags crate as well, we need to make sure they don't
490+
// conflict, even if they pick the same verison of bitflags. We'll
491+
// want to make sure that e.g. a plugin and rustc each get their
492+
// own copy of bitflags.
493+
494+
// Cargo ensures that this works in general through the -C metadata
495+
// flag. This flag will frob the symbols in the binary to make sure
496+
// they're different, even though the source code is the exact
497+
// same. To solve this problem for the compiler we extend Cargo's
498+
// already-passed -C metadata flag with our own. Our rustc.rs
499+
// wrapper around the actual rustc will detect -C metadata being
500+
// passed and frob it with this extra string we're passing in.
501+
cargo.env("RUSTC_METADATA_SUFFIX", "rustc");
484502
}
485503

486504
// Enable usage of unstable features

0 commit comments

Comments
 (0)