Skip to content

Commit 3ce83dc

Browse files
committed
Move test.sh to y.rs test
1 parent 6fd1660 commit 3ce83dc

File tree

11 files changed

+605
-238
lines changed

11 files changed

+605
-238
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ task:
2222
- # Reduce amount of benchmark runs as they are slow
2323
- export COMPILE_RUNS=2
2424
- export RUN_RUNS=2
25-
- ./test.sh
25+
- ./y.rs test

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
# Enable extra checks
104104
export CG_CLIF_ENABLE_VERIFIER=1
105105
106-
./test.sh
106+
./y.rs test
107107
108108
- name: Package prebuilt cg_clif
109109
run: tar cvfJ cg_clif.tar.xz build

build_system/build_backend.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::env;
2-
use std::path::{Path, PathBuf};
32
use std::process::Command;
43

54
pub(crate) fn build_backend(
65
channel: &str,
76
host_triple: &str,
87
use_unstable_features: bool,
9-
) -> PathBuf {
8+
) {
109
let mut cmd = Command::new("cargo");
1110
cmd.arg("build").arg("--target").arg(host_triple);
1211

@@ -38,6 +37,4 @@ pub(crate) fn build_backend(
3837

3938
eprintln!("[BUILD] rustc_codegen_cranelift");
4039
super::utils::spawn_and_wait(cmd);
41-
42-
Path::new("target").join(host_triple).join(channel)
4340
}

build_system/build_sysroot.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ pub(crate) fn build_sysroot(
1010
channel: &str,
1111
sysroot_kind: SysrootKind,
1212
target_dir: &Path,
13-
cg_clif_build_dir: PathBuf,
13+
cg_clif_build_dir: &Path,
1414
host_triple: &str,
1515
target_triple: &str,
1616
) {
17+
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
18+
1719
if target_dir.exists() {
1820
fs::remove_dir_all(target_dir).unwrap();
1921
}
@@ -35,11 +37,17 @@ pub(crate) fn build_sysroot(
3537

3638
// Build and copy rustc and cargo wrappers
3739
for wrapper in ["rustc-clif", "cargo-clif"] {
40+
let wrapper_name = if cfg!(windows) {
41+
format!("{wrapper}.exe")
42+
} else {
43+
wrapper.to_string()
44+
};
45+
3846
let mut build_cargo_wrapper_cmd = Command::new("rustc");
3947
build_cargo_wrapper_cmd
4048
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
4149
.arg("-o")
42-
.arg(target_dir.join(wrapper))
50+
.arg(target_dir.join(wrapper_name))
4351
.arg("-g");
4452
spawn_and_wait(build_cargo_wrapper_cmd);
4553
}

build_system/mod.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::path::PathBuf;
2+
use std::path::{PathBuf, Path};
33
use std::process;
44

55
mod build_backend;
@@ -8,13 +8,17 @@ mod config;
88
mod prepare;
99
mod rustc_info;
1010
mod utils;
11+
mod tests;
1112

1213
fn usage() {
1314
eprintln!("Usage:");
1415
eprintln!(" ./y.rs prepare");
1516
eprintln!(
1617
" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
1718
);
19+
eprintln!(
20+
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
21+
);
1822
}
1923

2024
macro_rules! arg_error {
@@ -25,11 +29,13 @@ macro_rules! arg_error {
2529
}};
2630
}
2731

32+
#[derive(PartialEq, Debug)]
2833
enum Command {
2934
Build,
35+
Test,
3036
}
3137

32-
#[derive(Copy, Clone)]
38+
#[derive(Copy, Clone, Debug)]
3339
pub(crate) enum SysrootKind {
3440
None,
3541
Clif,
@@ -52,6 +58,7 @@ pub fn main() {
5258
process::exit(0);
5359
}
5460
Some("build") => Command::Build,
61+
Some("test") => Command::Test,
5562
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
5663
Some(command) => arg_error!("Unknown command {}", command),
5764
None => {
@@ -115,14 +122,27 @@ pub fn main() {
115122
process::exit(1);
116123
}
117124

118-
let cg_clif_build_dir =
125+
let cg_clif_build_dir = Path::new("target").join(&host_triple).join(&channel);
126+
127+
if command == Command::Test {
128+
// TODO: Should we also build_backend here?
129+
tests::run_tests(
130+
channel,
131+
sysroot_kind,
132+
&target_dir,
133+
&cg_clif_build_dir,
134+
&host_triple,
135+
&target_triple,
136+
).expect("Failed to run tests");
137+
} else {
119138
build_backend::build_backend(channel, &host_triple, use_unstable_features);
120-
build_sysroot::build_sysroot(
121-
channel,
122-
sysroot_kind,
123-
&target_dir,
124-
cg_clif_build_dir,
125-
&host_triple,
126-
&target_triple,
127-
);
139+
build_sysroot::build_sysroot(
140+
channel,
141+
sysroot_kind,
142+
&target_dir,
143+
&cg_clif_build_dir,
144+
&host_triple,
145+
&target_triple,
146+
);
147+
}
128148
}

build_system/prepare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ pub(crate) fn prepare() {
5050
spawn_and_wait(build_cmd);
5151
fs::copy(
5252
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
53-
// FIXME use get_file_name here too once testing is migrated to rust
54-
"simple-raytracer/raytracer_cg_llvm",
53+
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
5554
)
5655
.unwrap();
5756
}

0 commit comments

Comments
 (0)