summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs80
1 files changed, 47 insertions, 33 deletions
diff --git a/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs b/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
index 99b97be24..1e14f41d4 100644
--- a/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
+++ b/compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
@@ -3,6 +3,8 @@ use std::env;
use std::os::unix::process::CommandExt;
use std::process::Command;
+include!("../build_system/shared_utils.rs");
+
fn main() {
let current_exe = env::current_exe().unwrap();
let mut sysroot = current_exe.parent().unwrap();
@@ -10,27 +12,19 @@ fn main() {
sysroot = sysroot.parent().unwrap();
}
- let mut rustflags = String::new();
- rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
+ let mut rustflags = vec!["-Cpanic=abort".to_owned(), "-Zpanic-abort-tests".to_owned()];
if let Some(name) = option_env!("BUILTIN_BACKEND") {
- rustflags.push_str(name);
+ rustflags.push(format!("-Zcodegen-backend={name}"));
} else {
- rustflags.push_str(
- sysroot
- .join(if cfg!(windows) { "bin" } else { "lib" })
- .join(
- env::consts::DLL_PREFIX.to_string()
- + "rustc_codegen_cranelift"
- + env::consts::DLL_SUFFIX,
- )
- .to_str()
- .unwrap(),
+ let dylib = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
+ env::consts::DLL_PREFIX.to_string()
+ + "rustc_codegen_cranelift"
+ + env::consts::DLL_SUFFIX,
);
+ rustflags.push(format!("-Zcodegen-backend={}", dylib.to_str().unwrap()));
}
- rustflags.push_str(" --sysroot ");
- rustflags.push_str(sysroot.to_str().unwrap());
- env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
- env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
+ rustflags.push("--sysroot".to_owned());
+ rustflags.push(sysroot.to_str().unwrap().to_owned());
let cargo = if let Some(cargo) = option_env!("CARGO") {
cargo
@@ -40,14 +34,19 @@ fn main() {
"cargo"
};
- let args: Vec<_> = match env::args().nth(1).as_deref() {
+ let mut args = env::args().skip(1).collect::<Vec<_>>();
+ if args.get(0).map(|arg| &**arg) == Some("clif") {
+ // Avoid infinite recursion when invoking `cargo-clif` as cargo subcommand using
+ // `cargo clif`.
+ args.remove(0);
+ }
+
+ let args: Vec<_> = match args.get(0).map(|arg| &**arg) {
Some("jit") => {
- env::set_var(
- "RUSTFLAGS",
- env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
- );
+ rustflags.push("-Cprefer-dynamic".to_owned());
+ args.remove(0);
IntoIterator::into_iter(["rustc".to_string()])
- .chain(env::args().skip(2))
+ .chain(args)
.chain([
"--".to_string(),
"-Zunstable-options".to_string(),
@@ -56,12 +55,10 @@ fn main() {
.collect()
}
Some("lazy-jit") => {
- env::set_var(
- "RUSTFLAGS",
- env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
- );
+ rustflags.push("-Cprefer-dynamic".to_owned());
+ args.remove(0);
IntoIterator::into_iter(["rustc".to_string()])
- .chain(env::args().skip(2))
+ .chain(args)
.chain([
"--".to_string(),
"-Zunstable-options".to_string(),
@@ -69,14 +66,31 @@ fn main() {
])
.collect()
}
- _ => env::args().skip(1).collect(),
+ _ => args,
};
+ let mut cmd = Command::new(cargo);
+ cmd.args(args);
+ rustflags_to_cmd_env(
+ &mut cmd,
+ "RUSTFLAGS",
+ &rustflags_from_env("RUSTFLAGS")
+ .into_iter()
+ .chain(rustflags.iter().map(|flag| flag.clone()))
+ .collect::<Vec<_>>(),
+ );
+ rustflags_to_cmd_env(
+ &mut cmd,
+ "RUSTDOCFLAGS",
+ &rustflags_from_env("RUSTDOCFLAGS")
+ .into_iter()
+ .chain(rustflags.iter().map(|flag| flag.clone()))
+ .collect::<Vec<_>>(),
+ );
+
#[cfg(unix)]
- panic!("Failed to spawn cargo: {}", Command::new(cargo).args(args).exec());
+ panic!("Failed to spawn cargo: {}", cmd.exec());
#[cfg(not(unix))]
- std::process::exit(
- Command::new(cargo).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
- );
+ std::process::exit(cmd.spawn().unwrap().wait().unwrap().code().unwrap_or(1));
}