Skip to content

Commit 7c57254

Browse files
committed
Allow building the build system using cargo
Rust's build system only handles cargo, not rustc.
1 parent 8ae1721 commit 7c57254

20 files changed

+74
-79
lines changed

.cirrus.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ task:
1010
folder: target
1111
prepare_script:
1212
- . $HOME/.cargo/env
13-
- ./y.rs prepare
13+
- ./y.sh prepare
1414
test_script:
1515
- . $HOME/.cargo/env
16-
- ./y.rs test
16+
- ./y.sh test

.github/workflows/abi-cafe.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ jobs:
4646
run: rustup set default-host x86_64-pc-windows-gnu
4747

4848
- name: Prepare dependencies
49-
run: ./y.rs prepare
49+
run: ./y.sh prepare
5050

5151
- name: Build
52-
run: ./y.rs build --sysroot none
52+
run: ./y.sh build --sysroot none
5353

5454
- name: Test abi-cafe
5555
env:
5656
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
57-
run: ./y.rs abi-cafe
57+
run: ./y.sh abi-cafe

.github/workflows/main.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Rustfmt
2020
run: |
2121
cargo fmt --check
22-
rustfmt --check build_system/mod.rs
22+
rustfmt --check build_system/main.rs
2323
rustfmt --check example/*
2424
2525
@@ -91,21 +91,21 @@ jobs:
9191
sudo apt-get install -y gcc-s390x-linux-gnu qemu-user
9292
9393
- name: Prepare dependencies
94-
run: ./y.rs prepare
94+
run: ./y.sh prepare
9595

9696
- name: Build without unstable features
9797
env:
9898
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
9999
# This is the config rust-lang/rust uses for builds
100-
run: ./y.rs build --no-unstable-features
100+
run: ./y.sh build --no-unstable-features
101101

102102
- name: Build
103-
run: ./y.rs build --sysroot none
103+
run: ./y.sh build --sysroot none
104104

105105
- name: Test
106106
env:
107107
TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }}
108-
run: ./y.rs test
108+
run: ./y.sh test
109109

110110

111111
bench:
@@ -135,13 +135,13 @@ jobs:
135135
run: cargo install hyperfine || true
136136

137137
- name: Prepare dependencies
138-
run: ./y.rs prepare
138+
run: ./y.sh prepare
139139

140140
- name: Build
141-
run: CI_OPT=1 ./y.rs build --sysroot none
141+
run: CI_OPT=1 ./y.sh build --sysroot none
142142

143143
- name: Benchmark
144-
run: CI_OPT=1 ./y.rs bench
144+
run: CI_OPT=1 ./y.sh bench
145145

146146

147147
dist:
@@ -194,13 +194,13 @@ jobs:
194194
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
195195
196196
- name: Prepare dependencies
197-
run: ./y.rs prepare
197+
run: ./y.sh prepare
198198

199199
- name: Build backend
200-
run: CI_OPT=1 ./y.rs build --sysroot none
200+
run: CI_OPT=1 ./y.sh build --sysroot none
201201

202202
- name: Build sysroot
203-
run: CI_OPT=1 ./y.rs build
203+
run: CI_OPT=1 ./y.sh build
204204

205205
- name: Package prebuilt cg_clif
206206
run: tar cvfJ cg_clif.tar.xz dist

.github/workflows/rustc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
1919

2020
- name: Prepare dependencies
21-
run: ./y.rs prepare
21+
run: ./y.sh prepare
2222

2323
- name: Test
2424
run: ./scripts/test_bootstrap.sh
@@ -38,7 +38,7 @@ jobs:
3838
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
3939

4040
- name: Prepare dependencies
41-
run: ./y.rs prepare
41+
run: ./y.sh prepare
4242

4343
- name: Test
4444
run: ./scripts/test_rustc_tests.sh

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
/build_system/target
23
**/*.rs.bk
34
*.rlib
45
*.o

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"rust-analyzer.imports.granularity.enforce": true,
77
"rust-analyzer.imports.granularity.group": "module",
88
"rust-analyzer.imports.prefix": "crate",
9-
"rust-analyzer.cargo.features": ["unstable-features", "__check_build_system_using_ra"],
9+
"rust-analyzer.cargo.features": ["unstable-features"],
1010
"rust-analyzer.linkedProjects": [
1111
"./Cargo.toml",
12+
"./build_system/Cargo.toml",
1213
{
1314
"crates": [
1415
{

Cargo.toml

-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ name = "rustc_codegen_cranelift"
33
version = "0.1.0"
44
edition = "2021"
55

6-
[[bin]]
7-
# This is used just to teach rust-analyzer how to check the build system. required-features is used
8-
# to disable it for regular builds.
9-
name = "y"
10-
path = "./y.rs"
11-
required-features = ["__check_build_system_using_ra"]
12-
136
[lib]
147
crate-type = ["dylib"]
158

@@ -45,7 +38,6 @@ smallvec = "1.8.1"
4538
unstable-features = ["jit", "inline_asm"]
4639
jit = ["cranelift-jit", "libloading"]
4740
inline_asm = []
48-
__check_build_system_using_ra = []
4941

5042
[package.metadata.rust-analyzer]
5143
rustc_private = true

Readme.md

+4-4
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
1212
$ cd rustc_codegen_cranelift
13-
$ ./y.rs prepare
14-
$ ./y.rs build
13+
$ ./y.sh prepare
14+
$ ./y.sh 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-
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.rs`.
23+
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`.
2424

2525
## Precompiled builds
2626

@@ -35,7 +35,7 @@ If you want to use `cargo clif build` instead of having to specify the full path
3535

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

38-
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`).
38+
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`).
3939

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

build_system/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_system/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "y"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "y"
8+
path = "main.rs"
9+
10+
[features]
11+
unstable-features = [] # for rust-analyzer
12+
13+
# Do not add any dependencies

build_system/build_sysroot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn build_clif_sysroot_for_triple(
216216
match fs::read_to_string(SYSROOT_RUSTC_VERSION.to_path(dirs)) {
217217
Err(e) => {
218218
eprintln!("Failed to get rustc version for patched sysroot source: {}", e);
219-
eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source");
219+
eprintln!("Hint: Try `./y.sh prepare` to patch the sysroot source");
220220
process::exit(1);
221221
}
222222
Ok(source_version) => {
@@ -225,7 +225,7 @@ fn build_clif_sysroot_for_triple(
225225
eprintln!("The patched sysroot source is outdated");
226226
eprintln!("Source version: {}", source_version.trim());
227227
eprintln!("Rustc version: {}", rustc_version.trim());
228-
eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source");
228+
eprintln!("Hint: Try `./y.sh prepare` to update the patched sysroot source");
229229
process::exit(1);
230230
}
231231
}

build_system/mod.rs renamed to build_system/main.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![warn(rust_2018_idioms)]
2+
#![warn(unused_lifetimes)]
3+
#![warn(unreachable_pub)]
4+
15
use std::env;
26
use std::path::PathBuf;
37
use std::process;
@@ -37,13 +41,13 @@ enum Command {
3741
}
3842

3943
#[derive(Copy, Clone, Debug)]
40-
pub(crate) enum SysrootKind {
44+
enum SysrootKind {
4145
None,
4246
Clif,
4347
Llvm,
4448
}
4549

46-
pub(crate) fn main() {
50+
fn main() {
4751
if env::var("RUST_BACKTRACE").is_err() {
4852
env::set_var("RUST_BACKTRACE", "1");
4953
}

build_system/usage.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
The build system of cg_clif.
22

33
USAGE:
4-
./y.rs prepare [--out-dir DIR] [--download-dir DIR]
5-
./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
6-
./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
7-
./y.rs abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
8-
./y.rs bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
4+
./y.sh prepare [--out-dir DIR] [--download-dir DIR]
5+
./y.sh build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
6+
./y.sh test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
7+
./y.sh abi-cafe [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
8+
./y.sh bench [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--download-dir DIR] [--no-unstable-features] [--frozen]
99

1010
OPTIONS:
1111
--debug
@@ -36,7 +36,7 @@ REQUIREMENTS:
3636
* Rustup: By default rustup is used to install the right nightly version. If you don't want to
3737
use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
3838
point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
39-
* Git: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos.
40-
* Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for
39+
* Git: `./y.sh prepare` uses git for applying patches and on Windows for downloading test repos.
40+
* Curl and tar (non-Windows only): Used by `./y.sh prepare` to download a single commit for
4141
repos. Git will be used to clone the whole repo when using Windows.
42-
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.rs bench`.
42+
* [Hyperfine](https://github.com/sharkdp/hyperfine/): Used for benchmarking with `./y.sh bench`.

clean_all.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
rm -rf target/ download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
4+
rm -rf target/ build_system/target download/ build/ dist/ y.bin y.bin.dSYM y.exe y.pdb
55

66
# Kept for now in case someone updates their checkout of cg_clif before running clean_all.sh
77
# FIXME remove at some point in the future

docs/usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
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`).
5+
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.sh prepare` and `y.sh build` or `test.sh`).
66

77
## Cargo
88

scripts/rustup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ case $1 in
3232

3333
./clean_all.sh
3434

35-
./y.rs prepare
35+
./y.sh prepare
3636

3737
(cd download/sysroot && cargo update && cargo fetch && cp Cargo.lock ../../build_sysroot/)
3838
;;

scripts/setup_rust_fork.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
./y.rs build --no-unstable-features
4+
./y.sh build --no-unstable-features
55

66
echo "[SETUP] Rust fork"
77
git clone https://github.com/rust-lang/rust.git || true

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
exec ./y.rs test "$@"
2+
exec ./y.sh test "$@"

y.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
#!/usr/bin/env bash
22
#![deny(unsafe_code)] /*This line is ignored by bash
33
# This block is ignored by rustc
4-
set -e
5-
echo "[BUILD] y.rs" 1>&2
6-
rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 --edition 2021
7-
exec ${0/.rs/.bin} $@
4+
echo "Warning: y.rs is a deprecated alias for y.sh" 1>&2
5+
exec ./y.sh "$@"
86
*/
9-
10-
#![warn(rust_2018_idioms)]
11-
#![warn(unused_lifetimes)]
12-
#![warn(unreachable_pub)]
13-
14-
//! The build system for cg_clif
15-
//!
16-
//! # Manual compilation
17-
//!
18-
//! If your system doesn't support shell scripts you can manually compile and run this file using
19-
//! for example:
20-
//!
21-
//! ```shell
22-
//! $ rustc y.rs -o y.bin
23-
//! $ ./y.bin
24-
//! ```
25-
//!
26-
//! # Naming
27-
//!
28-
//! The name `y.rs` was chosen to not conflict with rustc's `x.py`.
29-
30-
#[path = "build_system/mod.rs"]
31-
mod build_system;
32-
33-
fn main() {
34-
build_system::main();
35-
}

y.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
echo "[BUILD] build system" 1>&2
5+
rustc build_system/main.rs -o y.bin -Cdebuginfo=1 --edition 2021
6+
exec ./y.bin "$@"

0 commit comments

Comments
 (0)