Skip to content

Commit b33a3ec

Browse files
authored
Merge pull request #1180 from bjorn3/rust_build_system
Rewrite part of the build system in rust
2 parents 0ddb937 + 03c9ecf commit b33a3ec

33 files changed

+803
-274
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ task:
1414
- . $HOME/.cargo/env
1515
- git config --global user.email "[email protected]"
1616
- git config --global user.name "User"
17-
- ./prepare.sh
17+
- ./y.rs prepare
1818
test_script:
1919
- . $HOME/.cargo/env
2020
- # Enable backtraces for easier debugging

.github/workflows/main.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: |
5454
git config --global user.email "[email protected]"
5555
git config --global user.name "User"
56-
./prepare.sh
56+
./y.rs prepare
5757
5858
- name: Test
5959
env:
@@ -87,3 +87,63 @@ jobs:
8787
with:
8888
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
8989
path: cg_clif.tar.xz
90+
91+
build_windows:
92+
runs-on: windows-latest
93+
timeout-minutes: 60
94+
95+
steps:
96+
- uses: actions/checkout@v2
97+
98+
#- name: Cache cargo installed crates
99+
# uses: actions/cache@v2
100+
# with:
101+
# path: ~/.cargo/bin
102+
# key: ${{ runner.os }}-cargo-installed-crates
103+
104+
#- name: Cache cargo registry and index
105+
# uses: actions/cache@v2
106+
# with:
107+
# path: |
108+
# ~/.cargo/registry
109+
# ~/.cargo/git
110+
# key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }}
111+
112+
#- name: Cache cargo target dir
113+
# uses: actions/cache@v2
114+
# with:
115+
# path: target
116+
# key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
117+
118+
- name: Prepare dependencies
119+
run: |
120+
git config --global user.email "[email protected]"
121+
git config --global user.name "User"
122+
git config --global core.autocrlf false
123+
rustup set default-host x86_64-pc-windows-gnu
124+
rustc y.rs -o y.exe -g
125+
./y.exe prepare
126+
127+
- name: Build
128+
#name: Test
129+
run: |
130+
# Enable backtraces for easier debugging
131+
#export RUST_BACKTRACE=1
132+
133+
# Reduce amount of benchmark runs as they are slow
134+
#export COMPILE_RUNS=2
135+
#export RUN_RUNS=2
136+
137+
# Enable extra checks
138+
#export CG_CLIF_ENABLE_VERIFIER=1
139+
140+
./y.exe build
141+
142+
#- name: Package prebuilt cg_clif
143+
# run: tar cvfJ cg_clif.tar.xz build
144+
145+
#- name: Upload prebuilt cg_clif
146+
# uses: actions/upload-artifact@v2
147+
# with:
148+
# name: cg_clif-${{ runner.os }}
149+
# path: cg_clif.tar.xz

.github/workflows/rustc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: |
3535
git config --global user.email "[email protected]"
3636
git config --global user.name "User"
37-
./prepare.sh
37+
./y.rs prepare
3838
3939
- name: Test
4040
run: |
@@ -72,7 +72,7 @@ jobs:
7272
run: |
7373
git config --global user.email "[email protected]"
7474
git config --global user.name "User"
75-
./prepare.sh
75+
./y.rs prepare
7676
7777
- name: Test
7878
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ perf.data
66
perf.data.old
77
*.events
88
*.string*
9+
/y.bin
910
/build
1011
/build_sysroot/sysroot_src
1112
/build_sysroot/compiler-builtins

.vscode/settings.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
// source for rustc_* is not included in the rust-src component; disable the errors about this
33
"rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"],
4-
"rust-analyzer.assist.importMergeBehavior": "last",
4+
"rust-analyzer.assist.importGranularity": "module",
5+
"rust-analyzer.assist.importEnforceGranularity": true,
6+
"rust-analyzer.assist.importPrefix": "by_crate",
57
"rust-analyzer.cargo.runBuildScripts": true,
68
"rust-analyzer.linkedProjects": [
79
"./Cargo.toml",
@@ -49,6 +51,23 @@
4951
"cfg": [],
5052
},
5153
]
54+
},
55+
{
56+
"roots": ["./y.rs"],
57+
"crates": [
58+
{
59+
"root_module": "./y.rs",
60+
"edition": "2018",
61+
"deps": [{ "crate": 1, "name": "std" }],
62+
"cfg": [],
63+
},
64+
{
65+
"root_module": "./build_sysroot/sysroot_src/library/std/src/lib.rs",
66+
"edition": "2018",
67+
"deps": [],
68+
"cfg": [],
69+
},
70+
]
5271
}
5372
]
5473
}

Readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ If not please open an issue.
1010
```bash
1111
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
1212
$ cd rustc_codegen_cranelift
13-
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
14-
$ ./build.sh
13+
$ ./y.rs prepare # download and patch sysroot src and install hyperfine for benchmarking
14+
$ ./y.rs build
1515
```
1616

1717
To run the test suite replace the last command with:
@@ -20,7 +20,7 @@ To run the test suite replace the last command with:
2020
$ ./test.sh
2121
```
2222

23-
This will implicitly build cg_clif too. Both `build.sh` and `test.sh` accept a `--debug` argument to
23+
This will implicitly build cg_clif too. Both `y.rs build` and `test.sh` accept a `--debug` argument to
2424
build in debug mode.
2525

2626
Alternatively you can download a pre built version from [GHA]. It is listed in the artifacts section
@@ -32,12 +32,12 @@ of workflow runs. Unfortunately due to GHA restrictions you need to be logged in
3232

3333
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
3434

35-
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`).
35+
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`).
3636

3737
In the directory with your project (where you can do the usual `cargo build`), run:
3838

3939
```bash
40-
$ $cg_clif_dir/build/cargo.sh build
40+
$ $cg_clif_dir/build/cargo build
4141
```
4242

4343
This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.

build.sh

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

build_sysroot/build_sysroot.sh

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

build_sysroot/prepare_sysroot_src.sh

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

build_system/build_backend.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::env;
2+
use std::process::Command;
3+
4+
pub(crate) fn build_backend(channel: &str) -> String {
5+
let mut cmd = Command::new("cargo");
6+
cmd.arg("build");
7+
8+
match channel {
9+
"debug" => {}
10+
"release" => {
11+
cmd.arg("--release");
12+
}
13+
_ => unreachable!(),
14+
}
15+
16+
if cfg!(unix) {
17+
if cfg!(target_os = "macos") {
18+
cmd.env(
19+
"RUSTFLAGS",
20+
"-Csplit-debuginfo=unpacked \
21+
-Clink-arg=-Wl,-rpath,@loader_path/../lib \
22+
-Zosx-rpath-install-name"
23+
.to_string()
24+
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
25+
);
26+
} else {
27+
cmd.env(
28+
"RUSTFLAGS",
29+
"-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string()
30+
+ env::var("RUSTFLAGS").as_deref().unwrap_or(""),
31+
);
32+
}
33+
}
34+
35+
eprintln!("[BUILD] rustc_codegen_cranelift");
36+
crate::utils::spawn_and_wait(cmd);
37+
38+
crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
39+
}

0 commit comments

Comments
 (0)