Skip to content

Commit 560e65c

Browse files
authored
Merge pull request #427 from GuillaumeGomez/config-file
Switch to `config.toml` instead of `gcc-path`
2 parents 357cae8 + de9d1b6 commit 560e65c

18 files changed

+227
-90
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ jobs:
5555
- name: Setup path to libgccjit
5656
run: |
5757
sudo dpkg --force-overwrite -i gcc-13.deb
58-
echo /usr/lib/ > gcc_path
58+
echo 'gcc-path = "/usr/lib/"' > config.toml
5959
6060
- name: Set env
6161
run: |
62-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
63-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
6462
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
63+
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
64+
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
6565
6666
#- name: Cache rust repository
6767
## We only clone the rust repository for rustc tests

.github/workflows/failures.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ jobs:
5252

5353
- name: Setup path to libgccjit
5454
if: matrix.libgccjit_version.gcc == 'libgccjit12.so'
55-
run: echo /usr/lib/gcc/x86_64-linux-gnu/12 > gcc_path
55+
run: |
56+
echo 'gcc-path = "/usr/lib/gcc/x86_64-linux-gnu/12"' > config.toml
57+
echo "LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
58+
echo "LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
5659
5760
- name: Download artifact
5861
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
@@ -62,12 +65,12 @@ jobs:
6265
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
6366
run: |
6467
sudo dpkg --force-overwrite -i gcc-13.deb
65-
echo /usr/lib/ > gcc_path
68+
echo 'gcc-path = "/usr/lib"' > config.toml
69+
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
70+
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
6671
6772
- name: Set env
6873
run: |
69-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
70-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
7174
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
7275
7376
#- name: Cache rust repository

.github/workflows/gcc12.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ jobs:
4747
run: sudo apt-get install ninja-build ripgrep llvm-14-tools libgccjit-12-dev
4848

4949
- name: Setup path to libgccjit
50-
run: echo /usr/lib/gcc/x86_64-linux-gnu/12 > gcc_path
50+
run: echo 'gcc-path = "/usr/lib/gcc/x86_64-linux-gnu/12"' > config.toml
5151

5252
- name: Set env
5353
run: |
54-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
55-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
5654
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
55+
echo "LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
56+
echo "LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
5757
5858
#- name: Cache rust repository
5959
## We only clone the rust repository for rustc tests

.github/workflows/m68k.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ jobs:
6565
- name: Setup path to libgccjit
6666
run: |
6767
sudo dpkg -i gcc-m68k-13.deb
68-
echo /usr/lib/ > gcc_path
68+
echo 'gcc-path = "/usr/lib/"' > config.toml
6969
7070
- name: Set env
7171
run: |
72-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
73-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
7472
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
73+
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
74+
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
7575
7676
#- name: Cache rust repository
7777
## We only clone the rust repository for rustc tests

.github/workflows/release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242
- name: Setup path to libgccjit
4343
run: |
4444
sudo dpkg --force-overwrite -i gcc-13.deb
45-
echo /usr/lib/ > gcc_path
45+
echo 'gcc-path = "/usr/lib/"' > config.toml
4646
4747
- name: Set env
4848
run: |
49-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
50-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
5149
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
50+
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
51+
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
5252
5353
- name: Build
5454
run: |

.github/workflows/stdarch.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ jobs:
5656
- name: Setup path to libgccjit
5757
run: |
5858
sudo dpkg --force-overwrite -i gcc-13.deb
59-
echo /usr/lib/ > gcc_path
59+
echo 'gcc-path = "/usr/lib/"' > config.toml
6060
6161
- name: Set env
6262
run: |
63-
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
64-
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
6563
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
64+
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
65+
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
6666
6767
- name: Build
6868
run: |

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ tools/llvmint-2
2828
# The `llvm` folder is generated by the `tools/generate_intrinsics.py` script to update intrinsics.
2929
llvm
3030
build_system/target
31+
config.toml

Cargo.lock

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

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tempfile = "3.7.1"
3737
[dev-dependencies]
3838
lang_tester = "0.3.9"
3939
tempfile = "3.1.0"
40+
boml = "0.3.1"
4041

4142
[profile.dev]
4243
# By compiling dependencies with optimizations, performing tests gets much faster.

Readme.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,27 @@ $ make check-jit
4949
$ make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-asm.cc"
5050
```
5151

52-
**Put the path to your custom build of libgccjit in the file `gcc_path`.**
52+
**Put the path to your custom build of libgccjit in the file `config.toml`.**
53+
54+
If you followed the instructions exactly as written (ie, you have created a `gcc-build` folder
55+
where gcc is built), the only thing you need to do is:
56+
57+
```bash
58+
$ cp config.example.toml config.toml
59+
```
60+
61+
But if you did something different, you also need to set the `gcc-path` value in `config.toml` with
62+
the result of this command:
5363

5464
```bash
55-
$ dirname $(readlink -f `find . -name libgccjit.so`) > gcc_path
65+
$ dirname $(readlink -f `find . -name libgccjit.so`)
5666
```
5767

5868
Then you can run commands like this:
5969

6070
```bash
6171
$ ./y.sh prepare # download and patch sysroot src and install hyperfine for benchmarking
62-
$ LIBRARY_PATH=$(cat gcc_path) LD_LIBRARY_PATH=$(cat gcc_path) ./y.sh build --release --features master
72+
$ ./y.sh build --release --features master
6373
```
6474

6575
To run the tests:
@@ -100,7 +110,7 @@ error: failed to copy bitcode to object file: No such file or directory (os erro
100110
> You should prefer using the Cargo method.
101111
102112
```bash
103-
$ LIBRARY_PATH=$(cat gcc_path) LD_LIBRARY_PATH=$(cat gcc_path) rustc +$(cat $CG_GCCJIT_DIR/rust-toolchain | grep 'channel' | cut -d '=' -f 2 | sed 's/"//g' | sed 's/ //g') -Cpanic=abort -Zcodegen-backend=$CG_GCCJIT_DIR/target/release/librustc_codegen_gcc.so --sysroot $CG_GCCJIT_DIR/build_sysroot/sysroot my_crate.rs
113+
$ LIBRARY_PATH="[gcc-path value]" LD_LIBRARY_PATH="[gcc-path value]" rustc +$(cat $CG_GCCJIT_DIR/rust-toolchain | grep 'channel' | cut -d '=' -f 2 | sed 's/"//g' | sed 's/ //g') -Cpanic=abort -Zcodegen-backend=$CG_GCCJIT_DIR/target/release/librustc_codegen_gcc.so --sysroot $CG_GCCJIT_DIR/build_sysroot/sysroot my_crate.rs
104114
```
105115

106116
## Env vars
@@ -322,7 +332,7 @@ generate it in [gimple.md](./doc/gimple.md).
322332
#### Configuring rustc_codegen_gcc
323333

324334
* Run `./y.sh prepare --cross` so that the sysroot is patched for the cross-compiling case.
325-
* Set the path to the cross-compiling libgccjit in `gcc_path`.
335+
* Set the path to the cross-compiling libgccjit in `gcc-path` (in `config.toml`).
326336
* Make sure you have the linker for your target (for instance `m68k-unknown-linux-gnu-gcc`) in your `$PATH`. Currently, the linker name is hardcoded as being `$TARGET-gcc`. Specify the target when building the sysroot: `./y.sh build --target-triple m68k-unknown-linux-gnu`.
327337
* Build your project by specifying the target: `OVERWRITE_TARGET_TRIPLE=m68k-unknown-linux-gnu ../y.sh cargo build --target m68k-unknown-linux-gnu`.
328338

@@ -338,4 +348,4 @@ If you get the following error:
338348
/usr/bin/ld: unrecognised emulation mode: m68kelf
339349
```
340350

341-
Make sure you set `gcc_path` to the install directory.
351+
Make sure you set `gcc-path` (in `config.toml`) to the install directory.

build_system/Cargo.lock

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

build_system/Cargo.toml

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

6+
[dependencies]
7+
boml = "0.3.1"
8+
69
[[bin]]
710
name = "y"
811
path = "src/main.rs"

build_system/src/build.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::config::{Channel, ConfigInfo};
2-
use crate::utils::{get_gcc_path, run_command, run_command_with_output_and_env, walk_dir};
2+
use crate::utils::{run_command, run_command_with_output_and_env, walk_dir};
33
use std::collections::HashMap;
44
use std::ffi::OsStr;
55
use std::fs;
@@ -8,17 +8,12 @@ use std::path::Path;
88
#[derive(Default)]
99
struct BuildArg {
1010
flags: Vec<String>,
11-
gcc_path: String,
1211
config_info: ConfigInfo,
1312
}
1413

1514
impl BuildArg {
1615
fn new() -> Result<Option<Self>, String> {
17-
let gcc_path = get_gcc_path()?;
18-
let mut build_arg = Self {
19-
gcc_path,
20-
..Default::default()
21-
};
16+
let mut build_arg = Self::default();
2217
// We skip binary name and the `build` command.
2318
let mut args = std::env::args().skip(2);
2419

@@ -169,7 +164,8 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
169164
fs::create_dir_all(&sysroot_src_path).map_err(|error| {
170165
format!(
171166
"Failed to create directory `{}`: {:?}",
172-
sysroot_src_path.display(), error
167+
sysroot_src_path.display(),
168+
error
173169
)
174170
})?;
175171
run_command(
@@ -188,8 +184,14 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
188184
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
189185
let mut env = HashMap::new();
190186

191-
env.insert("LD_LIBRARY_PATH".to_string(), args.gcc_path.clone());
192-
env.insert("LIBRARY_PATH".to_string(), args.gcc_path.clone());
187+
env.insert(
188+
"LD_LIBRARY_PATH".to_string(),
189+
args.config_info.gcc_path.clone(),
190+
);
191+
env.insert(
192+
"LIBRARY_PATH".to_string(),
193+
args.config_info.gcc_path.clone(),
194+
);
193195

194196
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
195197
if args.config_info.channel == Channel::Release {
@@ -205,7 +207,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
205207
}
206208
run_command_with_output_and_env(&command, None, Some(&env))?;
207209

208-
args.config_info.setup(&mut env, Some(&args.gcc_path))?;
210+
args.config_info.setup(&mut env, None)?;
209211

210212
// We voluntarily ignore the error.
211213
let _ = fs::remove_dir_all("target/out");
@@ -227,6 +229,7 @@ pub fn run() -> Result<(), String> {
227229
Some(args) => args,
228230
None => return Ok(()),
229231
};
232+
args.config_info.setup_gcc_path(None)?;
230233
build_codegen(&mut args)?;
231234
Ok(())
232235
}

0 commit comments

Comments
 (0)