Skip to content

Commit 706905b

Browse files
authored
Merge pull request #669 from FractalFir/y_cargo_tests
modifed y.sh to allow for running cargo tests.
2 parents 967fc29 + ea03697 commit 706905b

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ jobs:
6464
- name: Set env
6565
run: |
6666
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
67-
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
68-
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
6967
7068
#- name: Cache rust repository
7169
## We only clone the rust repository for rustc tests
@@ -80,8 +78,7 @@ jobs:
8078
run: |
8179
./y.sh prepare --only-libcore
8280
./y.sh build --sysroot
83-
./y.sh test --mini-tests
84-
cargo test
81+
./y.sh test --cargo-tests
8582
8683
- name: Run y.sh cargo build
8784
run: |

.github/workflows/failures.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666
run: |
6767
sudo dpkg --force-overwrite -i gcc-15.deb
6868
echo 'gcc-path = "/usr/lib"' > config.toml
69-
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
70-
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
69+
70+
7171
7272
- name: Set env
7373
run: |

.github/workflows/m68k.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ jobs:
6565
- name: Set env
6666
run: |
6767
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
68-
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
69-
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
68+
69+
7070
7171
#- name: Cache rust repository
7272
## We only clone the rust repository for rustc tests
@@ -95,7 +95,7 @@ jobs:
9595
./y.sh prepare --only-libcore --cross
9696
./y.sh build --sysroot --features compiler_builtins/no-f16-f128 --target-triple m68k-unknown-linux-gnu
9797
./y.sh test --mini-tests
98-
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
98+
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu ./y.sh test --cargo-tests
9999
./y.sh clean all
100100
101101
- name: Prepare dependencies

.github/workflows/release.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ jobs:
4949
- name: Set env
5050
run: |
5151
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
52-
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
53-
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
52+
53+
5454
5555
- name: Build
5656
run: |
5757
./y.sh prepare --only-libcore
5858
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
59-
./y.sh test --mini-tests
60-
cargo test
59+
./y.sh test --cargo-tests
6160
./y.sh clean all
6261
6362
- name: Prepare dependencies

.github/workflows/stdarch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
if: ${{ !matrix.cargo_runner }}
9191
run: |
9292
./y.sh test --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore
93-
cargo test
93+
./y.sh test --cargo-tests
9494
9595
- name: Run stdarch tests
9696
if: ${{ !matrix.cargo_runner }}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To run specific tests, use appropriate flags such as:
3333

3434
- `./y.sh test --test-libcore`
3535
- `./y.sh test --std-tests`
36-
- `cargo test -- <name of test>`
36+
- `./y.sh test --cargo-tests -- <name of test>`
3737

3838
Additionally, you can run the tests of `libgccjit`:
3939

build_system/src/test.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn get_runners() -> Runners {
4242
);
4343
runners.insert("--extended-regex-tests", ("Run extended regex tests", extended_regex_tests));
4444
runners.insert("--mini-tests", ("Run mini tests", mini_tests));
45-
45+
runners.insert("--cargo-tests", ("Run cargo tests", cargo_tests));
4646
runners
4747
}
4848

@@ -88,6 +88,8 @@ struct TestArg {
8888
use_system_gcc: bool,
8989
runners: Vec<String>,
9090
flags: Vec<String>,
91+
/// Additional arguments, to be passed to commands like `cargo test`.
92+
test_args: Vec<String>,
9193
nb_parts: Option<usize>,
9294
current_part: Option<usize>,
9395
sysroot_panic_abort: bool,
@@ -144,6 +146,7 @@ impl TestArg {
144146
show_usage();
145147
return Ok(None);
146148
}
149+
"--" => test_arg.test_args.extend(&mut args),
147150
x if runners.contains_key(x)
148151
&& !test_arg.runners.iter().any(|runner| runner == x) =>
149152
{
@@ -203,6 +206,33 @@ fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
203206
create_dir(&path)
204207
}
205208

209+
fn cargo_tests(test_env: &Env, test_args: &TestArg) -> Result<(), String> {
210+
// First, we call `mini_tests` to build minicore for us. This ensures we are testing with a working `minicore`,
211+
// and that any changes we have made affect `minicore`(since it would get rebuilt).
212+
mini_tests(test_env, test_args)?;
213+
// Then, we copy some of the env vars from `test_env`
214+
// We don't want to pass things like `RUSTFLAGS`, since they contain the -Zcodegen-backend flag.
215+
// That would force `cg_gcc` to *rebuild itself* and only then run tests, which is undesirable.
216+
let mut env = HashMap::new();
217+
env.insert(
218+
"LD_LIBRARY_PATH".into(),
219+
test_env.get("LD_LIBRARY_PATH").expect("LD_LIBRARY_PATH missing!").to_string(),
220+
);
221+
env.insert(
222+
"LIBRARY_PATH".into(),
223+
test_env.get("LIBRARY_PATH").expect("LIBRARY_PATH missing!").to_string(),
224+
);
225+
env.insert(
226+
"CG_RUSTFLAGS".into(),
227+
test_env.get("CG_RUSTFLAGS").map(|s| s.as_str()).unwrap_or("").to_string(),
228+
);
229+
// Pass all the default args + the user-specified ones.
230+
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"test"];
231+
args.extend(test_args.test_args.iter().map(|s| s as &dyn AsRef<OsStr>));
232+
run_command_with_output_and_env(&args, None, Some(&env))?;
233+
Ok(())
234+
}
235+
206236
fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
207237
// FIXME: create a function "display_if_not_quiet" or something along the line.
208238
println!("[BUILD] mini_core");
@@ -1217,7 +1247,9 @@ fn run_all(env: &Env, args: &TestArg) -> Result<(), String> {
12171247
// asm_tests(env, args)?;
12181248
test_libcore(env, args)?;
12191249
extended_sysroot_tests(env, args)?;
1250+
cargo_tests(env, args)?;
12201251
test_rustc(env, args)?;
1252+
12211253
Ok(())
12221254
}
12231255

0 commit comments

Comments
 (0)