Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustify test.sh #384

Merged
merged 34 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
04f32f2
Allow rustfmt to run on `build_system`
GuillaumeGomez Nov 13, 2023
7b76ac4
Rustify `test.sh`
GuillaumeGomez Nov 8, 2023
84ca4f5
Remove `test.sh`, `config.sh` and all calls and documentation pointin…
GuillaumeGomez Nov 16, 2023
d3e14a4
Display stdout and stderr if a command failed to run
GuillaumeGomez Nov 21, 2023
8cc024c
Fix invalid path in `build_sysroot_inner`
GuillaumeGomez Nov 21, 2023
694a80d
Add missing `--build-sysroot` option
GuillaumeGomez Nov 21, 2023
c27fe3e
Correctly handle channel in config
GuillaumeGomez Nov 22, 2023
9d104a0
Clone rust repository before modifying it
GuillaumeGomez Nov 22, 2023
87c284c
Only read rust test files
GuillaumeGomez Nov 22, 2023
23c97b5
Replace `xargs` command with pure Rust
GuillaumeGomez Nov 22, 2023
673661d
Remove newline for llvm FileCheck binary path
GuillaumeGomez Nov 22, 2023
d793f80
Correctly pass `cfg` option
GuillaumeGomez Nov 23, 2023
4bed89f
Correctly pass toolchain to cargo command
GuillaumeGomez Nov 23, 2023
3c6bae7
Use the correct folder when deleting rust UI tests
GuillaumeGomez Nov 23, 2023
7013ecc
Add missing code comment
GuillaumeGomez Nov 23, 2023
ad1d541
Set RUSTDOCFLAGS environment variable in `run_cargo_command_with_call…
GuillaumeGomez Nov 23, 2023
7d71b87
Correctly set `--cap-lints` when running regex tests
GuillaumeGomez Nov 23, 2023
970b2c7
Fix `build_sysroot` by adding missing `RUSTFLAGS` environment variable
GuillaumeGomez Nov 24, 2023
ff04316
Remove `--target` option
GuillaumeGomez Nov 24, 2023
53b2759
Show command which failed
GuillaumeGomez Nov 24, 2023
2ec8d46
Correctly handle `OVERWRITE_TARGET_TRIPLE` env variable
GuillaumeGomez Nov 24, 2023
996635b
Fix chroot command
GuillaumeGomez Nov 24, 2023
ebb7aa0
Apply suggestions
GuillaumeGomez Dec 1, 2023
867ea12
Fix non-running rustc ui tests
GuillaumeGomez Dec 5, 2023
db9b932
Fix sysroot build
GuillaumeGomez Dec 13, 2023
95dfe5e
Simplify `split_args` code, add a unit test for it and run it into CI
GuillaumeGomez Dec 16, 2023
9882d7c
Apply suggestions
GuillaumeGomez Dec 16, 2023
a8b0e30
Error earlier if the rustc host cannot be found
GuillaumeGomez Dec 18, 2023
f516c96
Add comment about why `-Cpanic=abort` option is needed
GuillaumeGomez Dec 19, 2023
bb4fd2c
Simplify code by removing unneeded pattern matching
GuillaumeGomez Dec 19, 2023
984e045
Show output of `--mini-tests` and `--std-tests` commands
GuillaumeGomez Dec 19, 2023
a46066c
Remove ignored commands from gcc12 CI
GuillaumeGomez Dec 19, 2023
6e53832
Simplify `Runner` type alias
GuillaumeGomez Dec 19, 2023
8e870c7
Remove unused `TestArgs::use_backend` and display messages in case a …
GuillaumeGomez Dec 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,19 @@ jobs:
- name: Run tests
run: |
# TODO: remove --features master when it is back to the default.
./test.sh --features master --release --clean --build-sysroot ${{ matrix.commands }}
./y.sh test --features master --release --clean --build-sysroot ${{ matrix.commands }}

duplicates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: python tools/check_intrinsics_duplicates.py

build_system:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Test build system
run: |
cd build_system
cargo test
2 changes: 1 addition & 1 deletion .github/workflows/failures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ jobs:
- name: Run tests
id: tests
run: |
${{ matrix.libgccjit_version.env_extra }} ./test.sh --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
rg --text "test result" output_log >> $GITHUB_STEP_SUMMARY
5 changes: 1 addition & 4 deletions .github/workflows/gcc12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
# FIXME: re-enable asm tests when GCC can emit in the right syntax.
# "--asm-tests",
"--test-libcore",
"--extended-rand-tests",
"--extended-regex-example-tests",
"--extended-regex-tests",
"--test-successful-rustc --nb-parts 2 --current-part 0",
"--test-successful-rustc --nb-parts 2 --current-part 1",
]
Expand Down Expand Up @@ -112,4 +109,4 @@ jobs:

- name: Run tests
run: |
./test.sh --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features
2 changes: 1 addition & 1 deletion .github/workflows/m68k.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ jobs:
- name: Run tests
run: |
# TODO: remove --features master when it is back to the default.
./test.sh --release --features master --clean --build-sysroot ${{ matrix.commands }}
./y.sh test --release --features master --clean --build-sysroot ${{ matrix.commands }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ jobs:
- name: Run tests
run: |
# TODO: remove --features master when it is back to the default.
EMBED_LTO_BITCODE=1 ./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} --features master
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} --features master
2 changes: 1 addition & 1 deletion .github/workflows/stdarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
if: ${{ !matrix.cargo_runner }}
run: |
# TODO: remove `--features master` when it is back to the default.
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore --features master
./y.sh test --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore --features master
antoyo marked this conversation as resolved.
Show resolved Hide resolved

- name: Run stdarch tests
if: ${{ !matrix.cargo_runner }}
Expand Down
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
disable_all_formatting = true
ignore = ["/src", "/tests"]
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $ LIBRARY_PATH=$(cat gcc_path) LD_LIBRARY_PATH=$(cat gcc_path) ./y.sh build --re
To run the tests:

```bash
$ ./test.sh --release --features master
$ ./y.sh test --release --features master
```

## Usage
Expand All @@ -82,7 +82,7 @@ export CG_GCCJIT_DIR=[the full path to rustc_codegen_gcc]
$ CHANNEL="release" $CG_GCCJIT_DIR/cargo.sh run
```

If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./test.sh`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.
If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y.sh test`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.

### LTO

Expand Down
148 changes: 63 additions & 85 deletions build_system/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use crate::config::{set_config, ConfigInfo};
use crate::utils::{
get_gcc_path, run_command, run_command_with_output_and_env, walk_dir,
};
use crate::config::{Channel, ConfigInfo};
use crate::utils::{get_gcc_path, run_command, run_command_with_output_and_env, walk_dir};
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs;
use std::path::Path;

#[derive(Default)]
struct BuildArg {
codegen_release_channel: bool,
sysroot_release_channel: bool,
sysroot_panic_abort: bool,
flags: Vec<String>,
gcc_path: String,
config_info: ConfigInfo,
}

impl BuildArg {
Expand All @@ -28,14 +24,9 @@ impl BuildArg {

while let Some(arg) = args.next() {
match arg.as_str() {
"--release" => build_arg.codegen_release_channel = true,
"--release-sysroot" => build_arg.sysroot_release_channel = true,
"--no-default-features" => {
build_arg.flags.push("--no-default-features".to_string());
}
"--sysroot-panic-abort" => {
build_arg.sysroot_panic_abort = true;
},
"--features" => {
if let Some(arg) = args.next() {
build_arg.flags.push("--features".to_string());
Expand All @@ -50,25 +41,11 @@ impl BuildArg {
Self::usage();
return Ok(None);
}
"--target-triple" => {
if args.next().is_some() {
// Handled in config.rs.
} else {
return Err(
"Expected a value after `--target-triple`, found nothing".to_string()
);
}
}
"--target" => {
if args.next().is_some() {
antoyo marked this conversation as resolved.
Show resolved Hide resolved
// Handled in config.rs.
} else {
return Err(
"Expected a value after `--target`, found nothing".to_string()
);
arg => {
if !build_arg.config_info.parse_argument(arg, &mut args)? {
return Err(format!("Unknown argument `{}`", arg));
}
}
arg => return Err(format!("Unknown argument `{}`", arg)),
}
}
Ok(Some(build_arg))
Expand All @@ -79,29 +56,20 @@ impl BuildArg {
r#"
`build` command help:

--release : Build codegen in release mode
--release-sysroot : Build sysroot in release mode
--sysroot-panic-abort : Build the sysroot without unwinding support.
--no-default-features : Add `--no-default-features` flag
--features [arg] : Add a new feature [arg]
--target-triple [arg] : Set the target triple to [arg]
--help : Show this help
"#
)
--features [arg] : Add a new feature [arg]"#
);
ConfigInfo::show_usage();
println!(" --help : Show this help");
}
}

fn build_sysroot(
env: &mut HashMap<String, String>,
args: &BuildArg,
config: &ConfigInfo,
) -> Result<(), String> {
std::env::set_current_dir("build_sysroot")
.map_err(|error| format!("Failed to go to `build_sysroot` directory: {:?}", error))?;
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
let start_dir = Path::new("build_sysroot");
// Cleanup for previous run
// Clean target dir except for build scripts and incremental cache
let _ = walk_dir(
"target",
start_dir.join("target"),
|dir: &Path| {
for top in &["debug", "release"] {
let _ = fs::remove_dir_all(dir.join(top).join("build"));
Expand Down Expand Up @@ -138,79 +106,93 @@ fn build_sysroot(
|_| Ok(()),
);

let _ = fs::remove_file("Cargo.lock");
let _ = fs::remove_file("test_target/Cargo.lock");
let _ = fs::remove_dir_all("sysroot");
let _ = fs::remove_file(start_dir.join("Cargo.lock"));
let _ = fs::remove_file(start_dir.join("test_target/Cargo.lock"));
let _ = fs::remove_dir_all(start_dir.join("sysroot"));

// Builds libs
let mut rustflags = env
.get("RUSTFLAGS")
.cloned()
.unwrap_or_default();
if args.sysroot_panic_abort {
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
if config.sysroot_panic_abort {
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
}
env.insert(
"RUSTFLAGS".to_string(),
format!("{} -Zmir-opt-level=3", rustflags),
);
let channel = if args.sysroot_release_channel {
rustflags.push_str(" -Z force-unstable-if-unmarked");
let mut env = env.clone();
antoyo marked this conversation as resolved.
Show resolved Hide resolved
let channel = if config.sysroot_release_channel {
env.insert(
"RUSTFLAGS".to_string(),
format!("{} -Zmir-opt-level=3", rustflags),
);
run_command_with_output_and_env(
&[
&"cargo",
&"build",
&"--release",
&"--target",
&config.target,
&"--release",
],
None,
Some(start_dir),
Some(&env),
)?;
"release"
} else {
env.insert("RUSTFLAGS".to_string(), rustflags);

run_command_with_output_and_env(
&[
&"cargo",
&"build",
&"--target",
&config.target,
],
None,
Some(env),
&[&"cargo", &"build", &"--target", &config.target],
Some(start_dir),
Some(&env),
)?;
"debug"
};

// Copy files to sysroot
let sysroot_path = format!("sysroot/lib/rustlib/{}/lib/", config.target_triple);
fs::create_dir_all(&sysroot_path)
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_path, error))?;
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
fs::create_dir_all(&sysroot_path).map_err(|error| {
format!(
"Failed to create directory `{}`: {:?}",
sysroot_path.display(),
error
)
})?;
let copier = |dir_to_copy: &Path| {
// FIXME: should not use shell command!
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
};
walk_dir(
&format!("target/{}/{}/deps", config.target_triple, channel),
start_dir.join(&format!("target/{}/{}/deps", config.target_triple, channel)),
copier,
copier,
)?;

// Copy the source files to the sysroot (Rust for Linux needs this).
let sysroot_src_path = "sysroot/lib/rustlib/src/rust";
fs::create_dir_all(&sysroot_src_path)
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_src_path, error))?;
run_command(&[&"cp", &"-r", &"sysroot_src/library/", &sysroot_src_path], None)?;
fs::create_dir_all(&sysroot_src_path).map_err(|error| {
format!(
"Failed to create directory `{}`: {:?}",
sysroot_src_path, error
)
})?;
run_command(
&[
&"cp",
&"-r",
&start_dir.join("sysroot_src/library/"),
&sysroot_src_path,
],
None,
)?;

Ok(())
}

fn build_codegen(args: &BuildArg) -> Result<(), String> {
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
let mut env = HashMap::new();

env.insert("LD_LIBRARY_PATH".to_string(), args.gcc_path.clone());
env.insert("LIBRARY_PATH".to_string(), args.gcc_path.clone());

let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
if args.codegen_release_channel {
if args.config_info.channel == Channel::Release {
command.push(&"--release");
env.insert("CHANNEL".to_string(), "release".to_string());
env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
Expand All @@ -223,7 +205,7 @@ fn build_codegen(args: &BuildArg) -> Result<(), String> {
}
run_command_with_output_and_env(&command, None, Some(&env))?;

let config = set_config(&mut env, &[], Some(&args.gcc_path))?;
args.config_info.setup(&mut env, Some(&args.gcc_path))?;

// We voluntarily ignore the error.
let _ = fs::remove_dir_all("target/out");
Expand All @@ -236,19 +218,15 @@ fn build_codegen(args: &BuildArg) -> Result<(), String> {
})?;

println!("[BUILD] sysroot");
build_sysroot(
&mut env,
args,
&config,
)?;
build_sysroot(&env, &args.config_info)?;
Ok(())
}

pub fn run() -> Result<(), String> {
let args = match BuildArg::new()? {
let mut args = match BuildArg::new()? {
Some(args) => args,
None => return Ok(()),
};
build_codegen(&args)?;
build_codegen(&mut args)?;
Ok(())
}
Loading
Loading