Skip to content

Commit 2e65a8f

Browse files
committed
Use -Zcodegen-backend instead of a rustc replacement in cargo-clif
1 parent 617171e commit 2e65a8f

File tree

10 files changed

+60
-152
lines changed

10 files changed

+60
-152
lines changed

build_system/build_backend.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ pub(crate) fn build_backend(
3434
_ => unreachable!(),
3535
}
3636

37-
// Set the rpath to make the cg_clif executable find librustc_codegen_cranelift without changing
38-
// LD_LIBRARY_PATH
39-
if cfg!(unix) {
40-
if cfg!(target_os = "macos") {
41-
rustflags += " -Csplit-debuginfo=unpacked \
42-
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
43-
-Zosx-rpath-install-name";
44-
} else {
45-
rustflags += " -Clink-arg=-Wl,-rpath=$ORIGIN/../lib ";
46-
}
47-
}
48-
4937
cmd.env("RUSTFLAGS", rustflags);
5038

5139
eprintln!("[BUILD] rustc_codegen_cranelift");

build_system/build_sysroot.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@ pub(crate) fn build_sysroot(
3333
.join(&cg_clif_dylib);
3434
try_hard_link(cg_clif_build_dir.join(cg_clif_dylib), &cg_clif_dylib_path);
3535

36-
try_hard_link(
37-
cg_clif_build_dir.join(get_file_name("cg_clif", "bin")),
38-
target_dir.join("bin").join(get_file_name("cg_clif", "bin")),
39-
);
40-
41-
// Build and copy cargo wrapper
42-
let mut build_cargo_wrapper_cmd = Command::new("rustc");
43-
build_cargo_wrapper_cmd
44-
.arg("scripts/cargo-clif.rs")
45-
.arg("-o")
46-
.arg(target_dir.join("cargo-clif"))
47-
.arg("-g");
48-
spawn_and_wait(build_cargo_wrapper_cmd);
36+
// Build and copy rustc and cargo wrappers
37+
for wrapper in ["rustc-clif", "cargo-clif"] {
38+
let mut build_cargo_wrapper_cmd = Command::new("rustc");
39+
build_cargo_wrapper_cmd
40+
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
41+
.arg("-o")
42+
.arg(target_dir.join(wrapper))
43+
.arg("-g");
44+
spawn_and_wait(build_cargo_wrapper_cmd);
45+
}
4946

5047
let default_sysroot = super::rustc_info::get_default_sysroot();
5148

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This will build your project with rustc_codegen_cranelift instead of the usual L
1919
> You should prefer using the Cargo method.
2020
2121
```bash
22-
$ $cg_clif_dir/build/bin/cg_clif my_crate.rs
22+
$ $cg_clif_dir/build/rustc-clif my_crate.rs
2323
```
2424

2525
## Jit mode
@@ -38,7 +38,7 @@ $ $cg_clif_dir/build/cargo-clif jit
3838
or
3939

4040
```bash
41-
$ $cg_clif_dir/build/bin/cg_clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
41+
$ $cg_clif_dir/build/rustc-clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs
4242
```
4343

4444
There is also an experimental lazy jit mode. In this mode functions are only compiled once they are
@@ -54,7 +54,7 @@ These are a few functions that allow you to easily run rust code from the shell
5454

5555
```bash
5656
function jit_naked() {
57-
echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
57+
echo "$@" | $cg_clif_dir/build/rustc-clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic
5858
}
5959

6060
function jit() {

scripts/cargo-clif.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@ use std::path::PathBuf;
55
use std::process::Command;
66

77
fn main() {
8-
if env::var("RUSTC_WRAPPER").map_or(false, |wrapper| wrapper.contains("sccache")) {
9-
eprintln!(
10-
"\x1b[1;93m=== Warning: Unsetting RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m"
11-
);
12-
env::remove_var("RUSTC_WRAPPER");
13-
}
14-
158
let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
169

17-
env::set_var("RUSTC", sysroot.join("bin/cg_clif".to_string() + env::consts::EXE_SUFFIX));
18-
19-
let mut rustdoc_flags = env::var("RUSTDOCFLAGS").unwrap_or(String::new());
20-
rustdoc_flags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
21-
rustdoc_flags.push_str(
10+
let mut rustflags = String::new();
11+
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
12+
rustflags.push_str(
2213
sysroot
2314
.join(if cfg!(windows) { "bin" } else { "lib" })
2415
.join(
@@ -29,9 +20,10 @@ fn main() {
2920
.to_str()
3021
.unwrap(),
3122
);
32-
rustdoc_flags.push_str(" --sysroot ");
33-
rustdoc_flags.push_str(sysroot.to_str().unwrap());
34-
env::set_var("RUSTDOCFLAGS", rustdoc_flags);
23+
rustflags.push_str(" --sysroot ");
24+
rustflags.push_str(sysroot.to_str().unwrap());
25+
env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
26+
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
3527

3628
// Ensure that the right toolchain is used
3729
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));

scripts/config.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/filter_profile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#![forbid(unsafe_code)]/* This line is ignored by bash
33
# This block is ignored by rustc
44
pushd $(dirname "$0")/../
5-
source scripts/config.sh
6-
RUSTC="$(pwd)/build/bin/cg_clif"
5+
RUSTC="$(pwd)/build/rustc-clif"
76
popd
87
PROFILE=$1 OUTPUT=$2 exec $RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic $0
98
#*/

scripts/rustc-clif.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::env;
2+
use std::ffi::OsString;
3+
#[cfg(unix)]
4+
use std::os::unix::process::CommandExt;
5+
use std::path::PathBuf;
6+
use std::process::Command;
7+
8+
fn main() {
9+
let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
10+
11+
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
12+
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
13+
);
14+
15+
let mut args = std::env::args_os().skip(1).collect::<Vec<_>>();
16+
args.push(OsString::from("-Cpanic=abort"));
17+
args.push(OsString::from("-Zpanic-abort-tests"));
18+
let mut codegen_backend_arg = OsString::from("-Zcodegen-backend=");
19+
codegen_backend_arg.push(cg_clif_dylib_path);
20+
args.push(codegen_backend_arg);
21+
if !args.contains(&OsString::from("--sysroot")) {
22+
args.push(OsString::from("--sysroot"));
23+
args.push(OsString::from(sysroot.to_str().unwrap()));
24+
}
25+
26+
// Ensure that the right toolchain is used
27+
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
28+
29+
#[cfg(unix)]
30+
Command::new("rustc").args(args).exec();
31+
32+
#[cfg(not(unix))]
33+
std::process::exit(
34+
Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
35+
);
36+
}

scripts/setup_rust_fork.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -e
33

44
./y.rs build --no-unstable-features
5-
source scripts/config.sh
65

76
echo "[SETUP] Rust fork"
87
git clone https://github.com/rust-lang/rust.git || true
@@ -52,7 +51,7 @@ changelog-seen = 2
5251
ninja = false
5352
5453
[build]
55-
rustc = "$(pwd)/../build/bin/cg_clif"
54+
rustc = "$(pwd)/../build/rustc-clif"
5655
cargo = "$(rustup which cargo)"
5756
full-bootstrap = true
5857
local-rebuild = true

scripts/tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
set -e
44

5-
source scripts/config.sh
6-
75
export CG_CLIF_DISPLAY_CG_TIME=1
86
export CG_CLIF_DISABLE_INCR_CACHE=1
97

@@ -31,8 +29,7 @@ if [[ "$(uname)" == 'Darwin' ]]; then
3129
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
3230
fi
3331

34-
export RUSTC=false # ensure that cg_llvm isn't accidentally used
35-
MY_RUSTC="$(pwd)/build/bin/cg_clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
32+
MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
3633

3734
function no_sysroot_tests() {
3835
echo "[BUILD] mini_core"
@@ -124,7 +121,7 @@ function extended_sysroot_tests() {
124121
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
125122
echo "[BENCH COMPILE] ebobby/simple-raytracer"
126123
hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
127-
"RUSTC=rustc RUSTFLAGS='' cargo build" \
124+
"RUSTFLAGS='' cargo build" \
128125
"../build/cargo-clif build"
129126

130127
echo "[BENCH RUN] ebobby/simple-raytracer"

src/bin/cg_clif.rs

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)