Skip to content

Commit 4ffa425

Browse files
authored
Merge pull request #319 from GuillaumeGomez/build-system
Rustify prepare.sh command
2 parents 186320a + 08eb006 commit 4ffa425

File tree

17 files changed

+413
-82
lines changed

17 files changed

+413
-82
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ jobs:
119119

120120
- name: Build
121121
run: |
122-
./prepare_build.sh
122+
./y.sh prepare --only-libcore
123123
${{ matrix.libgccjit_version.env_extra }} ./build.sh ${{ matrix.libgccjit_version.extra }}
124124
${{ matrix.libgccjit_version.env_extra }} cargo test ${{ matrix.libgccjit_version.extra }}
125125
./clean_all.sh
@@ -128,7 +128,7 @@ jobs:
128128
run: |
129129
git config --global user.email "user@example.com"
130130
git config --global user.name "User"
131-
./prepare.sh
131+
./y.sh prepare
132132
133133
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
134134
- name: Compile

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888

8989
- name: Build
9090
run: |
91-
./prepare_build.sh
91+
./y.sh prepare --only-libcore
9292
./build.sh --release --release-sysroot
9393
cargo test
9494
./clean_all.sh
@@ -97,7 +97,7 @@ jobs:
9797
run: |
9898
git config --global user.email "user@example.com"
9999
git config --global user.name "User"
100-
./prepare.sh
100+
./y.sh prepare
101101
102102
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
103103
- name: Compile

.github/workflows/stdarch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102

103103
- name: Build
104104
run: |
105-
./prepare_build.sh
105+
./y.sh prepare --only-libcore
106106
./build.sh --release --release-sysroot
107107
cargo test
108108
@@ -115,7 +115,7 @@ jobs:
115115
run: |
116116
git config --global user.email "user@example.com"
117117
git config --global user.name "User"
118-
./prepare.sh
118+
./y.sh prepare
119119
120120
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
121121
- name: Compile

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ tools/llvmint
2525
tools/llvmint-2
2626
# The `llvm` folder is generated by the `tools/generate_intrinsics.py` script to update intrinsics.
2727
llvm
28+
build_system/target

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $ export RUST_COMPILER_RT_ROOT="$PWD/llvm/compiler-rt"
6565
Then you can run commands like this:
6666

6767
```bash
68-
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
68+
$ ./y.sh prepare # download and patch sysroot src and install hyperfine for benchmarking
6969
$ LIBRARY_PATH=$(cat gcc_path) LD_LIBRARY_PATH=$(cat gcc_path) ./build.sh --release
7070
```
7171

build_sysroot/prepare_sysroot_src.sh

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

build_system/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_system/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "y"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "y"
8+
path = "src/main.rs"

build_system/src/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn run() -> Result<(), String> {
2+
Ok(())
3+
}

build_system/src/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::env;
2+
use std::process;
3+
4+
mod build;
5+
mod prepare;
6+
mod rustc_info;
7+
mod utils;
8+
9+
macro_rules! arg_error {
10+
($($err:tt)*) => {{
11+
eprintln!($($err)*);
12+
usage();
13+
std::process::exit(1);
14+
}};
15+
}
16+
17+
fn usage() {
18+
// println!("{}", include_str!("usage.txt"));
19+
}
20+
21+
pub enum Command {
22+
Prepare,
23+
Build,
24+
}
25+
26+
fn main() {
27+
if env::var("RUST_BACKTRACE").is_err() {
28+
env::set_var("RUST_BACKTRACE", "1");
29+
}
30+
31+
let command = match env::args().nth(1).as_deref() {
32+
Some("prepare") => Command::Prepare,
33+
Some("build") => Command::Build,
34+
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
35+
Some(command) => arg_error!("Unknown command {}", command),
36+
None => {
37+
usage();
38+
process::exit(0);
39+
}
40+
};
41+
42+
if let Err(e) = match command {
43+
Command::Prepare => prepare::run(),
44+
Command::Build => build::run(),
45+
} {
46+
eprintln!("Command failed to run: {e:?}");
47+
process::exit(1);
48+
}
49+
}

0 commit comments

Comments
 (0)