Merge pull request #2 from GuillaumeGomez/rm-build_sysroot-folder

Remove `build_sysroot` folder
This commit is contained in:
antoyo 2024-03-22 16:37:06 -04:00 committed by GitHub
commit eea2f89c80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 193 additions and 428 deletions

View File

@ -103,7 +103,10 @@ jobs:
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} ./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}
- name: Check formatting - name: Check formatting
run: cargo fmt -- --check run: |
cargo fmt -- --check
cd build_system
cargo fmt -- --check
- name: clippy - name: clippy
run: | run: |

View File

@ -62,12 +62,12 @@ jobs:
git config --global user.email "user@example.com" git config --global user.email "user@example.com"
git config --global user.name "User" git config --global user.name "User"
./y.sh prepare ./y.sh prepare
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
echo -n 'lto = "fat"' >> build_sysroot/Cargo.toml
- name: Add more failing tests because of undefined symbol errors (FIXME) - name: Add more failing tests because of undefined symbol errors (FIXME)
run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt
- name: Run tests - name: Run tests
run: | run: |
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

View File

@ -89,12 +89,10 @@ jobs:
- name: Run stdarch tests - name: Run stdarch tests
if: ${{ !matrix.cargo_runner }} if: ${{ !matrix.cargo_runner }}
run: | run: |
cd build_sysroot/sysroot_src/library/stdarch/ CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml
CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../y.sh cargo test
- name: Run stdarch tests - name: Run stdarch tests
if: ${{ matrix.cargo_runner }} if: ${{ matrix.cargo_runner }}
run: | run: |
cd build_sysroot/sysroot_src/library/stdarch/
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro. # FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../y.sh cargo test -- --skip rtm --skip tbm --skip sse4a STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml -- --skip rtm --skip tbm --skip sse4a

4
.gitignore vendored
View File

@ -6,10 +6,6 @@ perf.data
perf.data.old perf.data.old
*.events *.events
*.string* *.string*
/build_sysroot/sysroot
/build_sysroot/sysroot_src
/build_sysroot/Cargo.lock
/build_sysroot/test_target/Cargo.lock
gimple* gimple*
*asm *asm
res res

View File

@ -1,5 +1,5 @@
[package] [package]
authors = ["bjorn3 <bjorn3@users.noreply.github.com>"] authors = ["rustc_codegen_gcc devs"]
name = "sysroot" name = "sysroot"
version = "0.0.0" version = "0.0.0"
resolver = "2" resolver = "2"

View File

@ -1,5 +1,7 @@
use crate::config::{Channel, ConfigInfo}; use crate::config::{Channel, ConfigInfo};
use crate::utils::{run_command, run_command_with_output_and_env, walk_dir}; use crate::utils::{
copy_file, create_dir, get_sysroot_dir, run_command, run_command_with_output_and_env, walk_dir,
};
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs; use std::fs;
@ -55,8 +57,7 @@ impl BuildArg {
} }
} }
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> { fn cleanup_sysroot_previous_build(start_dir: &Path) {
let start_dir = Path::new("build_sysroot");
// Cleanup for previous run // Cleanup for previous run
// Clean target dir except for build scripts and incremental cache // Clean target dir except for build scripts and incremental cache
let _ = walk_dir( let _ = walk_dir(
@ -100,6 +101,26 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
let _ = fs::remove_file(start_dir.join("Cargo.lock")); let _ = fs::remove_file(start_dir.join("Cargo.lock"));
let _ = fs::remove_file(start_dir.join("test_target/Cargo.lock")); let _ = fs::remove_file(start_dir.join("test_target/Cargo.lock"));
let _ = fs::remove_dir_all(start_dir.join("sysroot")); let _ = fs::remove_dir_all(start_dir.join("sysroot"));
}
pub fn create_build_sysroot_content(start_dir: &Path) -> Result<(), String> {
if !start_dir.is_dir() {
create_dir(start_dir)?;
}
copy_file("build_system/build_sysroot/Cargo.toml", &start_dir.join("Cargo.toml"))?;
let src_dir = start_dir.join("src");
if !src_dir.is_dir() {
create_dir(&src_dir)?;
}
copy_file("build_system/build_sysroot/lib.rs", &start_dir.join("src/lib.rs"))
}
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
let start_dir = get_sysroot_dir();
cleanup_sysroot_previous_build(&start_dir);
create_build_sysroot_content(&start_dir)?;
// Builds libs // Builds libs
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default(); let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
@ -110,7 +131,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
if config.no_default_features { if config.no_default_features {
rustflags.push_str(" -Csymbol-mangling-version=v0"); rustflags.push_str(" -Csymbol-mangling-version=v0");
} }
let mut env = env.clone();
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target]; let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
@ -127,18 +147,13 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
"debug" "debug"
}; };
let mut env = env.clone();
env.insert("RUSTFLAGS".to_string(), rustflags); env.insert("RUSTFLAGS".to_string(), rustflags);
run_command_with_output_and_env(&args, Some(start_dir), Some(&env))?; run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?;
// Copy files to sysroot // Copy files to sysroot
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple)); let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
fs::create_dir_all(&sysroot_path).map_err(|error| { create_dir(&sysroot_path)?;
format!(
"Failed to create directory `{}`: {:?}",
sysroot_path.display(),
error
)
})?;
let copier = |dir_to_copy: &Path| { let copier = |dir_to_copy: &Path| {
// FIXME: should not use shell command! // FIXME: should not use shell command!
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ()) run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
@ -151,22 +166,8 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
// Copy the source files to the sysroot (Rust for Linux needs this). // Copy the source files to the sysroot (Rust for Linux needs this).
let sysroot_src_path = start_dir.join("sysroot/lib/rustlib/src/rust"); let sysroot_src_path = start_dir.join("sysroot/lib/rustlib/src/rust");
fs::create_dir_all(&sysroot_src_path).map_err(|error| { create_dir(&sysroot_src_path)?;
format!( run_command(&[&"cp", &"-r", &start_dir.join("sysroot_src/library/"), &sysroot_src_path], None)?;
"Failed to create directory `{}`: {:?}",
sysroot_src_path.display(),
error
)
})?;
run_command(
&[
&"cp",
&"-r",
&start_dir.join("sysroot_src/library/"),
&sysroot_src_path,
],
None,
)?;
Ok(()) Ok(())
} }
@ -174,20 +175,11 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
fn build_codegen(args: &mut BuildArg) -> Result<(), String> { fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
let mut env = HashMap::new(); let mut env = HashMap::new();
env.insert( env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
"LD_LIBRARY_PATH".to_string(), env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
args.config_info.gcc_path.clone(),
);
env.insert(
"LIBRARY_PATH".to_string(),
args.config_info.gcc_path.clone(),
);
if args.config_info.no_default_features { if args.config_info.no_default_features {
env.insert( env.insert("RUSTFLAGS".to_string(), "-Csymbol-mangling-version=v0".to_string());
"RUSTFLAGS".to_string(),
"-Csymbol-mangling-version=v0".to_string(),
);
} }
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"]; let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
@ -212,12 +204,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
// We voluntarily ignore the error. // We voluntarily ignore the error.
let _ = fs::remove_dir_all("target/out"); let _ = fs::remove_dir_all("target/out");
let gccjit_target = "target/out/gccjit"; let gccjit_target = "target/out/gccjit";
fs::create_dir_all(gccjit_target).map_err(|error| { create_dir(gccjit_target)?;
format!(
"Failed to create directory `{}`: {:?}",
gccjit_target, error
)
})?;
println!("[BUILD] sysroot"); println!("[BUILD] sysroot");
build_sysroot(&env, &args.config_info)?; build_sysroot(&env, &args.config_info)?;

View File

@ -16,9 +16,7 @@ fn args() -> Result<Option<Vec<String>>, String> {
} }
let args = std::env::args().skip(2).collect::<Vec<_>>(); let args = std::env::args().skip(2).collect::<Vec<_>>();
if args.is_empty() { if args.is_empty() {
return Err( return Err("Expected at least one argument for `cargo` subcommand, found none".to_string());
"Expected at least one argument for `cargo` subcommand, found none".to_string(),
);
} }
Ok(Some(args)) Ok(Some(args))
} }
@ -48,17 +46,10 @@ pub fn run() -> Result<(), String> {
let current_exe = std::env::current_exe() let current_exe = std::env::current_exe()
.and_then(|path| path.canonicalize()) .and_then(|path| path.canonicalize())
.map_err(|error| format!("Failed to get current exe path: {:?}", error))?; .map_err(|error| format!("Failed to get current exe path: {:?}", error))?;
let mut parent_dir = current_exe let mut parent_dir = current_exe.components().map(|comp| comp.as_os_str()).collect::<Vec<_>>();
.components()
.map(|comp| comp.as_os_str())
.collect::<Vec<_>>();
// We run this script from "build_system/target/release/y", so we need to remove these elements. // We run this script from "build_system/target/release/y", so we need to remove these elements.
for to_remove in &["y", "release", "target", "build_system"] { for to_remove in &["y", "release", "target", "build_system"] {
if parent_dir if parent_dir.last().map(|part| part == to_remove).unwrap_or(false) {
.last()
.map(|part| part == to_remove)
.unwrap_or(false)
{
parent_dir.pop(); parent_dir.pop();
} else { } else {
return Err(format!( return Err(format!(
@ -69,11 +60,7 @@ pub fn run() -> Result<(), String> {
} }
let parent_dir = PathBuf::from(parent_dir.join(&OsStr::new("/"))); let parent_dir = PathBuf::from(parent_dir.join(&OsStr::new("/")));
std::env::set_current_dir(&parent_dir).map_err(|error| { std::env::set_current_dir(&parent_dir).map_err(|error| {
format!( format!("Failed to go to `{}` folder: {:?}", parent_dir.display(), error)
"Failed to go to `{}` folder: {:?}",
parent_dir.display(),
error
)
})?; })?;
let mut env: HashMap<String, String> = std::env::vars().collect(); let mut env: HashMap<String, String> = std::env::vars().collect();
@ -92,11 +79,7 @@ pub fn run() -> Result<(), String> {
// We go back to the original folder since we now have set up everything we needed. // We go back to the original folder since we now have set up everything we needed.
std::env::set_current_dir(&current_dir).map_err(|error| { std::env::set_current_dir(&current_dir).map_err(|error| {
format!( format!("Failed to go back to `{}` folder: {:?}", current_dir.display(), error)
"Failed to go back to `{}` folder: {:?}",
current_dir.display(),
error
)
})?; })?;
let rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default(); let rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();

View File

@ -1,4 +1,4 @@
use crate::utils::{remove_file, run_command}; use crate::utils::{get_sysroot_dir, remove_file, run_command};
use std::fs::remove_dir_all; use std::fs::remove_dir_all;
use std::path::Path; use std::path::Path;
@ -42,11 +42,12 @@ fn usage() {
} }
fn clean_all() -> Result<(), String> { fn clean_all() -> Result<(), String> {
let build_sysroot = get_sysroot_dir();
let dirs_to_remove = [ let dirs_to_remove = [
"target", "target".into(),
"build_sysroot/sysroot", build_sysroot.join("sysroot"),
"build_sysroot/sysroot_src", build_sysroot.join("sysroot_src"),
"build_sysroot/target", build_sysroot.join("target"),
]; ];
for dir in dirs_to_remove { for dir in dirs_to_remove {
let _ = remove_dir_all(dir); let _ = remove_dir_all(dir);
@ -56,10 +57,11 @@ fn clean_all() -> Result<(), String> {
let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir)); let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir));
} }
let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"]; let files_to_remove =
[build_sysroot.join("Cargo.lock"), "perf.data".into(), "perf.data.old".into()];
for file in files_to_remove { for file in files_to_remove {
let _ = remove_file(file); let _ = remove_file(&file);
} }
println!("Successfully ran `clean all`"); println!("Successfully ran `clean all`");

View File

@ -1,5 +1,6 @@
use crate::utils::{ use crate::utils::{
create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args, create_dir, create_symlink, get_os_name, get_sysroot_dir, run_command_with_output,
rustc_version_info, split_args,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use std::env as std_env; use std::env as std_env;
@ -26,11 +27,7 @@ impl Channel {
} }
fn failed_config_parsing(config_file: &Path, err: &str) -> Result<ConfigFile, String> { fn failed_config_parsing(config_file: &Path, err: &str) -> Result<ConfigFile, String> {
Err(format!( Err(format!("Failed to parse `{}`: {}", config_file.display(), err))
"Failed to parse `{}`: {}",
config_file.display(),
err
))
} }
#[derive(Default)] #[derive(Default)]
@ -48,11 +45,7 @@ impl ConfigFile {
) )
})?; })?;
let toml = Toml::parse(&content).map_err(|err| { let toml = Toml::parse(&content).map_err(|err| {
format!( format!("Error occurred around `{}`: {:?}", &content[err.start..=err.end], err.kind)
"Error occurred around `{}`: {:?}",
&content[err.start..=err.end],
err.kind
)
})?; })?;
let mut config = Self::default(); let mut config = Self::default();
for (key, value) in toml.iter() { for (key, value) in toml.iter() {
@ -181,11 +174,7 @@ impl ConfigInfo {
}, },
"--use-backend" => match args.next() { "--use-backend" => match args.next() {
Some(backend) if !backend.is_empty() => self.backend = Some(backend), Some(backend) if !backend.is_empty() => self.backend = Some(backend),
_ => { _ => return Err("Expected an argument after `--use-backend`, found nothing".into()),
return Err(
"Expected an argument after `--use-backend`, found nothing".into()
)
}
}, },
"--no-default-features" => self.no_default_features = true, "--no-default-features" => self.no_default_features = true,
_ => return Ok(false), _ => return Ok(false),
@ -228,20 +217,10 @@ impl ConfigInfo {
let output_dir = output_dir.join(&commit); let output_dir = output_dir.join(&commit);
if !output_dir.is_dir() { if !output_dir.is_dir() {
std::fs::create_dir_all(&output_dir).map_err(|err| { create_dir(&output_dir)?;
format!(
"failed to create folder `{}`: {:?}",
output_dir.display(),
err,
)
})?;
} }
let output_dir = output_dir.canonicalize().map_err(|err| { let output_dir = output_dir.canonicalize().map_err(|err| {
format!( format!("Failed to get absolute path of `{}`: {:?}", output_dir.display(), err)
"Failed to get absolute path of `{}`: {:?}",
output_dir.display(),
err
)
})?; })?;
let libgccjit_so_name = "libgccjit.so"; let libgccjit_so_name = "libgccjit.so";
@ -275,10 +254,7 @@ impl ConfigInfo {
println!("Downloaded libgccjit.so version {} successfully!", commit); println!("Downloaded libgccjit.so version {} successfully!", commit);
// We need to create a link named `libgccjit.so.0` because that's what the linker is // We need to create a link named `libgccjit.so.0` because that's what the linker is
// looking for. // looking for.
create_symlink( create_symlink(&libgccjit_so, output_dir.join(&format!("{}.0", libgccjit_so_name)))?;
&libgccjit_so,
output_dir.join(&format!("{}.0", libgccjit_so_name)),
)?;
} }
self.gcc_path = output_dir.display().to_string(); self.gcc_path = output_dir.display().to_string();
@ -298,10 +274,7 @@ impl ConfigInfo {
Some(config_file) => config_file.into(), Some(config_file) => config_file.into(),
None => self.compute_path("config.toml"), None => self.compute_path("config.toml"),
}; };
let ConfigFile { let ConfigFile { gcc_path, download_gccjit } = ConfigFile::new(&config_file)?;
gcc_path,
download_gccjit,
} = ConfigFile::new(&config_file)?;
if let Some(true) = download_gccjit { if let Some(true) = download_gccjit {
self.download_gccjit_if_needed()?; self.download_gccjit_if_needed()?;
@ -310,10 +283,7 @@ impl ConfigInfo {
self.gcc_path = match gcc_path { self.gcc_path = match gcc_path {
Some(path) => path, Some(path) => path,
None => { None => {
return Err(format!( return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),))
"missing `gcc-path` value from `{}`",
config_file.display(),
))
} }
}; };
Ok(()) Ok(())
@ -393,17 +363,16 @@ impl ConfigInfo {
.join(&format!("librustc_codegen_gcc.{}", self.dylib_ext)) .join(&format!("librustc_codegen_gcc.{}", self.dylib_ext))
.display() .display()
.to_string(); .to_string();
self.sysroot_path = current_dir self.sysroot_path =
.join("build_sysroot/sysroot") current_dir.join(&get_sysroot_dir()).join("sysroot").display().to_string();
.display()
.to_string();
if let Some(backend) = &self.backend { if let Some(backend) = &self.backend {
// This option is only used in the rust compiler testsuite. The sysroot is handled // This option is only used in the rust compiler testsuite. The sysroot is handled
// by its build system directly so no need to set it ourselves. // by its build system directly so no need to set it ourselves.
rustflags.push(format!("-Zcodegen-backend={}", backend)); rustflags.push(format!("-Zcodegen-backend={}", backend));
} else { } else {
rustflags.extend_from_slice(&[ rustflags.extend_from_slice(&[
"--sysroot".to_string(), self.sysroot_path.clone(), "--sysroot".to_string(),
self.sysroot_path.clone(),
format!("-Zcodegen-backend={}", self.cg_backend_path), format!("-Zcodegen-backend={}", self.cg_backend_path),
]); ]);
} }
@ -424,8 +393,6 @@ impl ConfigInfo {
rustflags.push("-Csymbol-mangling-version=v0".to_string()); rustflags.push("-Csymbol-mangling-version=v0".to_string());
} }
// Since we don't support ThinLTO, disable LTO completely when not trying to do LTO. // Since we don't support ThinLTO, disable LTO completely when not trying to do LTO.
// TODO(antoyo): remove when we can handle ThinLTO. // TODO(antoyo): remove when we can handle ThinLTO.
if !env.contains_key(&"FAT_LTO".to_string()) { if !env.contains_key(&"FAT_LTO".to_string()) {
@ -442,10 +409,9 @@ impl ConfigInfo {
// display metadata load errors // display metadata load errors
env.insert("RUSTC_LOG".to_string(), "warn".to_string()); env.insert("RUSTC_LOG".to_string(), "warn".to_string());
let sysroot = current_dir.join(&format!( let sysroot = current_dir
"build_sysroot/sysroot/lib/rustlib/{}/lib", .join(&get_sysroot_dir())
self.target_triple, .join(&format!("sysroot/lib/rustlib/{}/lib", self.target_triple));
));
let ld_library_path = format!( let ld_library_path = format!(
"{target}:{sysroot}:{gcc_path}", "{target}:{sysroot}:{gcc_path}",
target = self.cargo_target_dir, target = self.cargo_target_dir,
@ -523,11 +489,7 @@ fn download_gccjit(
&"--retry", &"--retry",
&"3", &"3",
&"-SRfL", &"-SRfL",
if with_progress_bar { if with_progress_bar { &"--progress-bar" } else { &"-s" },
&"--progress-bar"
} else {
&"-s"
},
&url.as_str(), &url.as_str(),
], ],
Some(&output_dir), Some(&output_dir),

View File

@ -1,6 +1,7 @@
use crate::rustc_info::get_rustc_path; use crate::rustc_info::get_rustc_path;
use crate::utils::{ use crate::utils::{
cargo_install, git_clone_root_dir, remove_file, run_command, run_command_with_output, walk_dir, cargo_install, create_dir, get_sysroot_dir, git_clone_root_dir, remove_file, run_command,
run_command_with_output, walk_dir,
}; };
use std::fs; use std::fs;
@ -32,27 +33,14 @@ fn prepare_libcore(
let sysroot_dir = sysroot_path.join("sysroot_src"); let sysroot_dir = sysroot_path.join("sysroot_src");
if sysroot_dir.is_dir() { if sysroot_dir.is_dir() {
if let Err(error) = fs::remove_dir_all(&sysroot_dir) { if let Err(error) = fs::remove_dir_all(&sysroot_dir) {
return Err(format!( return Err(format!("Failed to remove `{}`: {:?}", sysroot_dir.display(), error,));
"Failed to remove `{}`: {:?}",
sysroot_dir.display(),
error,
));
} }
} }
let sysroot_library_dir = sysroot_dir.join("library"); let sysroot_library_dir = sysroot_dir.join("library");
fs::create_dir_all(&sysroot_library_dir).map_err(|error| { create_dir(&sysroot_library_dir)?;
format!(
"Failed to create folder `{}`: {:?}",
sysroot_library_dir.display(),
error,
)
})?;
run_command( run_command(&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir], None)?;
&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir],
None,
)?;
println!("[GIT] init (cwd): `{}`", sysroot_dir.display()); println!("[GIT] init (cwd): `{}`", sysroot_dir.display());
run_command(&[&"git", &"init"], Some(&sysroot_dir))?; run_command(&[&"git", &"init"], Some(&sysroot_dir))?;
@ -63,26 +51,11 @@ fn prepare_libcore(
// This is needed on systems where nothing is configured. // This is needed on systems where nothing is configured.
// git really needs something here, or it will fail. // git really needs something here, or it will fail.
// Even using --author is not enough. // Even using --author is not enough.
run_command( run_command(&[&"git", &"config", &"user.email", &"none@example.com"], Some(&sysroot_dir))?;
&[&"git", &"config", &"user.email", &"none@example.com"], run_command(&[&"git", &"config", &"user.name", &"None"], Some(&sysroot_dir))?;
Some(&sysroot_dir), run_command(&[&"git", &"config", &"core.autocrlf", &"false"], Some(&sysroot_dir))?;
)?; run_command(&[&"git", &"config", &"commit.gpgSign", &"false"], Some(&sysroot_dir))?;
run_command( run_command(&[&"git", &"commit", &"-m", &"Initial commit", &"-q"], Some(&sysroot_dir))?;
&[&"git", &"config", &"user.name", &"None"],
Some(&sysroot_dir),
)?;
run_command(
&[&"git", &"config", &"core.autocrlf", &"false"],
Some(&sysroot_dir),
)?;
run_command(
&[&"git", &"config", &"commit.gpgSign", &"false"],
Some(&sysroot_dir),
)?;
run_command(
&[&"git", &"commit", &"-m", &"Initial commit", &"-q"],
Some(&sysroot_dir),
)?;
let mut patches = Vec::new(); let mut patches = Vec::new();
walk_dir( walk_dir(
@ -116,17 +89,11 @@ fn prepare_libcore(
patches.sort(); patches.sort();
for file_path in patches { for file_path in patches {
println!("[GIT] apply `{}`", file_path.display()); println!("[GIT] apply `{}`", file_path.display());
let path = Path::new("../..").join(file_path); let path = Path::new("../../..").join(file_path);
run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?; run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?; run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
run_command_with_output( run_command_with_output(
&[ &[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
&"git",
&"commit",
&"--no-gpg-sign",
&"-m",
&format!("Patch {}", path.display()),
],
Some(&sysroot_dir), Some(&sysroot_dir),
)?; )?;
} }
@ -145,13 +112,7 @@ fn prepare_rand() -> Result<(), String> {
run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?; run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?;
run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?; run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?;
run_command_with_output( run_command_with_output(
&[ &[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
&"git",
&"commit",
&"--no-gpg-sign",
&"-m",
&format!("Patch {}", path.display()),
],
Some(rand_dir), Some(rand_dir),
)?; )?;
@ -165,10 +126,7 @@ fn build_raytracer(repo_dir: &Path) -> Result<(), String> {
if mv_target.is_file() { if mv_target.is_file() {
remove_file(&mv_target)?; remove_file(&mv_target)?;
} }
run_command( run_command(&[&"mv", &"target/debug/main", &"raytracer_cg_llvm"], Some(repo_dir))?;
&[&"mv", &"target/debug/main", &"raytracer_cg_llvm"],
Some(repo_dir),
)?;
Ok(()) Ok(())
} }
@ -213,11 +171,7 @@ impl PrepareArg {
a => return Err(format!("Unknown argument `{a}`")), a => return Err(format!("Unknown argument `{a}`")),
} }
} }
Ok(Some(Self { Ok(Some(Self { cross_compile, only_libcore, libgccjit12_patches }))
cross_compile,
only_libcore,
libgccjit12_patches,
}))
} }
fn usage() { fn usage() {
@ -238,8 +192,8 @@ pub fn run() -> Result<(), String> {
Some(a) => a, Some(a) => a,
None => return Ok(()), None => return Ok(()),
}; };
let sysroot_path = Path::new("build_sysroot"); let sysroot_path = get_sysroot_dir();
prepare_libcore(sysroot_path, args.libgccjit12_patches, args.cross_compile)?; prepare_libcore(&sysroot_path, args.libgccjit12_patches, args.cross_compile)?;
if !args.only_libcore { if !args.only_libcore {
cargo_install("hyperfine")?; cargo_install("hyperfine")?;

View File

@ -1,13 +1,14 @@
use crate::build; use crate::build;
use crate::config::{Channel, ConfigInfo}; use crate::config::{Channel, ConfigInfo};
use crate::utils::{ use crate::utils::{
get_toolchain, git_clone, git_clone_root_dir, remove_file, run_command, run_command_with_env, create_dir, get_sysroot_dir, get_toolchain, git_clone, git_clone_root_dir, remove_file,
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir, run_command, run_command_with_env, run_command_with_output_and_env, rustc_version_info,
split_args, walk_dir,
}; };
use std::collections::{BTreeSet, HashMap}; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs::{create_dir_all, remove_dir_all, File}; use std::fs::{remove_dir_all, File};
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
@ -19,46 +20,23 @@ type Runners = HashMap<&'static str, (&'static str, Runner)>;
fn get_runners() -> Runners { fn get_runners() -> Runners {
let mut runners = HashMap::new(); let mut runners = HashMap::new();
runners.insert( runners.insert("--test-rustc", ("Run all rustc tests", test_rustc as Runner));
"--test-rustc", runners
("Run all rustc tests", test_rustc as Runner), .insert("--test-successful-rustc", ("Run successful rustc tests", test_successful_rustc));
); runners.insert("--test-failing-rustc", ("Run failing rustc tests", test_failing_rustc));
runners.insert( runners.insert("--projects", ("Run the tests of popular crates", test_projects));
"--test-successful-rustc",
("Run successful rustc tests", test_successful_rustc),
);
runners.insert(
"--test-failing-rustc",
("Run failing rustc tests", test_failing_rustc),
);
runners.insert(
"--projects",
("Run the tests of popular crates", test_projects),
);
runners.insert("--test-libcore", ("Run libcore tests", test_libcore)); runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
runners.insert("--clean", ("Empty cargo target directory", clean)); runners.insert("--clean", ("Empty cargo target directory", clean));
runners.insert("--build-sysroot", ("Build sysroot", build_sysroot)); runners.insert("--build-sysroot", ("Build sysroot", build_sysroot));
runners.insert("--std-tests", ("Run std tests", std_tests)); runners.insert("--std-tests", ("Run std tests", std_tests));
runners.insert("--asm-tests", ("Run asm tests", asm_tests)); runners.insert("--asm-tests", ("Run asm tests", asm_tests));
runners.insert( runners.insert("--extended-tests", ("Run extended sysroot tests", extended_sysroot_tests));
"--extended-tests", runners.insert("--extended-rand-tests", ("Run extended rand tests", extended_rand_tests));
("Run extended sysroot tests", extended_sysroot_tests),
);
runners.insert(
"--extended-rand-tests",
("Run extended rand tests", extended_rand_tests),
);
runners.insert( runners.insert(
"--extended-regex-example-tests", "--extended-regex-example-tests",
( ("Run extended regex example tests", extended_regex_example_tests),
"Run extended regex example tests",
extended_regex_example_tests,
),
);
runners.insert(
"--extended-regex-tests",
("Run extended regex tests", extended_regex_tests),
); );
runners.insert("--extended-regex-tests", ("Run extended regex tests", extended_regex_tests));
runners.insert("--mini-tests", ("Run mini tests", mini_tests)); runners.insert("--mini-tests", ("Run mini tests", mini_tests));
runners runners
@ -71,15 +49,9 @@ fn get_number_after_arg(
match args.next() { match args.next() {
Some(nb) if !nb.is_empty() => match usize::from_str(&nb) { Some(nb) if !nb.is_empty() => match usize::from_str(&nb) {
Ok(nb) => Ok(nb), Ok(nb) => Ok(nb),
Err(_) => Err(format!( Err(_) => Err(format!("Expected a number after `{}`, found `{}`", option, nb)),
"Expected a number after `{}`, found `{}`",
option, nb
)),
}, },
_ => Err(format!( _ => Err(format!("Expected a number after `{}`, found nothing", option)),
"Expected a number after `{}`, found nothing",
option
)),
} }
} }
@ -110,7 +82,7 @@ fn show_usage() {
struct TestArg { struct TestArg {
build_only: bool, build_only: bool,
use_system_gcc: bool, use_system_gcc: bool,
runners: BTreeSet<String>, runners: Vec<String>,
flags: Vec<String>, flags: Vec<String>,
nb_parts: Option<usize>, nb_parts: Option<usize>,
current_part: Option<usize>, current_part: Option<usize>,
@ -130,9 +102,7 @@ impl TestArg {
match arg.as_str() { match arg.as_str() {
"--features" => match args.next() { "--features" => match args.next() {
Some(feature) if !feature.is_empty() => { Some(feature) if !feature.is_empty() => {
test_arg test_arg.flags.extend_from_slice(&["--features".into(), feature]);
.flags
.extend_from_slice(&["--features".into(), feature]);
} }
_ => { _ => {
return Err("Expected an argument after `--features`, found nothing".into()) return Err("Expected an argument after `--features`, found nothing".into())
@ -157,8 +127,10 @@ impl TestArg {
show_usage(); show_usage();
return Ok(None); return Ok(None);
} }
x if runners.contains_key(x) => { x if runners.contains_key(x)
test_arg.runners.insert(x.into()); && !test_arg.runners.iter().any(|runner| runner == x) =>
{
test_arg.runners.push(x.into());
} }
arg => { arg => {
if !test_arg.config_info.parse_argument(arg, &mut args)? { if !test_arg.config_info.parse_argument(arg, &mut args)? {
@ -211,8 +183,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
fn clean(_env: &Env, args: &TestArg) -> Result<(), String> { fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
let _ = std::fs::remove_dir_all(&args.config_info.cargo_target_dir); let _ = std::fs::remove_dir_all(&args.config_info.cargo_target_dir);
let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit"); let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit");
std::fs::create_dir_all(&path) create_dir(&path)
.map_err(|error| format!("failed to create folder `{}`: {:?}", path.display(), error))
} }
fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> { fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
@ -304,13 +275,8 @@ fn maybe_run_command_in_vm(
let sudo_command: &[&dyn AsRef<OsStr>] = &[&"sudo", &"cp", &exe, &vm_exe_path]; let sudo_command: &[&dyn AsRef<OsStr>] = &[&"sudo", &"cp", &exe, &vm_exe_path];
run_command_with_env(sudo_command, None, Some(env))?; run_command_with_env(sudo_command, None, Some(env))?;
let mut vm_command: Vec<&dyn AsRef<OsStr>> = vec![ let mut vm_command: Vec<&dyn AsRef<OsStr>> =
&"sudo", vec![&"sudo", &"chroot", &vm_dir, &"qemu-m68k-static", &inside_vm_exe_path];
&"chroot",
&vm_dir,
&"qemu-m68k-static",
&inside_vm_exe_path,
];
vm_command.extend_from_slice(command); vm_command.extend_from_slice(command);
run_command_with_output_and_env(&vm_command, Some(&vm_parent_dir), Some(env))?; run_command_with_output_and_env(&vm_command, Some(&vm_parent_dir), Some(env))?;
Ok(()) Ok(())
@ -399,11 +365,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
} }
run_command_with_env(&command, None, Some(env))?; run_command_with_env(&command, None, Some(env))?;
maybe_run_command_in_vm( maybe_run_command_in_vm(
&[ &[&cargo_target_dir.join("std_example"), &"--target", &args.config_info.target_triple],
&cargo_target_dir.join("std_example"),
&"--target",
&args.config_info.target_triple,
],
env, env,
args, args,
)?; )?;
@ -427,11 +389,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
command.push(test_flag); command.push(test_flag);
} }
run_command_with_env(&command, None, Some(env))?; run_command_with_env(&command, None, Some(env))?;
maybe_run_command_in_vm( maybe_run_command_in_vm(&[&cargo_target_dir.join("subslice-patterns-const-eval")], env, args)?;
&[&cargo_target_dir.join("subslice-patterns-const-eval")],
env,
args,
)?;
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[AOT] track-caller-attribute"); println!("[AOT] track-caller-attribute");
@ -447,11 +405,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
command.push(test_flag); command.push(test_flag);
} }
run_command_with_env(&command, None, Some(env))?; run_command_with_env(&command, None, Some(env))?;
maybe_run_command_in_vm( maybe_run_command_in_vm(&[&cargo_target_dir.join("track-caller-attribute")], env, args)?;
&[&cargo_target_dir.join("track-caller-attribute")],
env,
args,
)?;
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[AOT] mod_bench"); println!("[AOT] mod_bench");
@ -477,11 +431,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
); );
let rust_dir_path = Path::new(crate::BUILD_DIR).join("rust"); let rust_dir_path = Path::new(crate::BUILD_DIR).join("rust");
// If the repository was already cloned, command will fail, so doesn't matter. // If the repository was already cloned, command will fail, so doesn't matter.
let _ = git_clone( let _ = git_clone("https://github.com/rust-lang/rust.git", Some(&rust_dir_path), false);
"https://github.com/rust-lang/rust.git",
Some(&rust_dir_path),
false,
);
let rust_dir: Option<&Path> = Some(&rust_dir_path); let rust_dir: Option<&Path> = Some(&rust_dir_path);
run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?; run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?;
run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?; run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?;
@ -511,11 +461,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
} }
})?; })?;
let rustc = String::from_utf8( let rustc = String::from_utf8(
run_command_with_env( run_command_with_env(&[&"rustup", &toolchain, &"which", &"rustc"], rust_dir, Some(env))?
&[&"rustup", &toolchain, &"which", &"rustc"],
rust_dir,
Some(env),
)?
.stdout, .stdout,
) )
.map_err(|error| format!("Failed to retrieve rustc path: {:?}", error)) .map_err(|error| format!("Failed to retrieve rustc path: {:?}", error))
@ -573,13 +519,7 @@ download-ci-llvm = false
llvm_filecheck = llvm_filecheck.trim(), llvm_filecheck = llvm_filecheck.trim(),
), ),
) )
.map_err(|error| { .map_err(|error| format!("Failed to write into `{}`: {:?}", file_path.display(), error))?;
format!(
"Failed to write into `{}`: {:?}",
file_path.display(),
error
)
})?;
Ok(rust_dir_path) Ok(rust_dir_path)
} }
@ -591,21 +531,19 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string()); env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
let extra = if args.is_using_gcc_master_branch() { let extra =
"" if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
} else {
" -Csymbol-mangling-version=v0"
};
let rustc_args = &format!( let rustc_args = &format!(
r#"-Zpanic-abort-tests \ r#"-Zpanic-abort-tests \
-Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \ -Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
--sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort{extra}"#, --sysroot "{sysroot_dir}" -Cpanic=abort{extra}"#,
pwd = std::env::current_dir() pwd = std::env::current_dir()
.map_err(|error| format!("`current_dir` failed: {:?}", error))? .map_err(|error| format!("`current_dir` failed: {:?}", error))?
.display(), .display(),
channel = args.config_info.channel.as_str(), channel = args.config_info.channel.as_str(),
dylib_ext = args.config_info.dylib_ext, dylib_ext = args.config_info.dylib_ext,
sysroot_dir = args.config_info.sysroot_path,
extra = extra, extra = extra,
); );
@ -715,8 +653,7 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
}; };
let projects_path = Path::new("projects"); let projects_path = Path::new("projects");
create_dir_all(projects_path) create_dir(projects_path)?;
.map_err(|err| format!("Failed to create directory `projects`: {}", err))?;
let nb_parts = args.nb_parts.unwrap_or(0); let nb_parts = args.nb_parts.unwrap_or(0);
if nb_parts > 0 { if nb_parts > 0 {
@ -737,9 +674,9 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> { fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] libcore"); println!("[TEST] libcore");
let path = Path::new("build_sysroot/sysroot_src/library/core/tests"); let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
let _ = remove_dir_all(path.join("target")); let _ = remove_dir_all(path.join("target"));
run_cargo_command(&[&"test"], Some(path), env, args)?; run_cargo_command(&[&"test"], Some(&path), env, args)?;
Ok(()) Ok(())
} }
@ -763,10 +700,8 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
} }
let mut env = env.clone(); let mut env = env.clone();
// newer aho_corasick versions throw a deprecation warning // newer aho_corasick versions throw a deprecation warning
let rustflags = format!( let rustflags =
"{} --cap-lints warn", format!("{} --cap-lints warn", env.get("RUSTFLAGS").cloned().unwrap_or_default());
env.get("RUSTFLAGS").cloned().unwrap_or_default()
);
env.insert("RUSTFLAGS".to_string(), rustflags); env.insert("RUSTFLAGS".to_string(), rustflags);
let path = Path::new(crate::BUILD_DIR).join("rand"); let path = Path::new(crate::BUILD_DIR).join("rand");
@ -788,18 +723,11 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
println!("[TEST] rust-lang/regex example shootout-regex-dna"); println!("[TEST] rust-lang/regex example shootout-regex-dna");
let mut env = env.clone(); let mut env = env.clone();
// newer aho_corasick versions throw a deprecation warning // newer aho_corasick versions throw a deprecation warning
let rustflags = format!( let rustflags =
"{} --cap-lints warn", format!("{} --cap-lints warn", env.get("RUSTFLAGS").cloned().unwrap_or_default());
env.get("RUSTFLAGS").cloned().unwrap_or_default()
);
env.insert("RUSTFLAGS".to_string(), rustflags); env.insert("RUSTFLAGS".to_string(), rustflags);
// Make sure `[codegen mono items] start` doesn't poison the diff // Make sure `[codegen mono items] start` doesn't poison the diff
run_cargo_command( run_cargo_command(&[&"build", &"--example", &"shootout-regex-dna"], Some(&path), &env, args)?;
&[&"build", &"--example", &"shootout-regex-dna"],
Some(&path),
&env,
args,
)?;
run_cargo_command_with_callback( run_cargo_command_with_callback(
&[&"run", &"--example", &"shootout-regex-dna"], &[&"run", &"--example", &"shootout-regex-dna"],
@ -810,10 +738,8 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
// FIXME: rewrite this with `child.stdin.write_all()` because // FIXME: rewrite this with `child.stdin.write_all()` because
// `examples/regexdna-input.txt` is very small. // `examples/regexdna-input.txt` is very small.
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"bash", &"-c"]; let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"bash", &"-c"];
let cargo_args = cargo_command let cargo_args =
.iter() cargo_command.iter().map(|s| s.as_ref().to_str().unwrap()).collect::<Vec<_>>();
.map(|s| s.as_ref().to_str().unwrap())
.collect::<Vec<_>>();
let bash_command = format!( let bash_command = format!(
"cat examples/regexdna-input.txt | {} | grep -v 'Spawned thread' > res.txt", "cat examples/regexdna-input.txt | {} | grep -v 'Spawned thread' > res.txt",
cargo_args.join(" "), cargo_args.join(" "),
@ -841,10 +767,8 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
println!("[TEST] rust-lang/regex tests"); println!("[TEST] rust-lang/regex tests");
let mut env = env.clone(); let mut env = env.clone();
// newer aho_corasick versions throw a deprecation warning // newer aho_corasick versions throw a deprecation warning
let rustflags = format!( let rustflags =
"{} --cap-lints warn", format!("{} --cap-lints warn", env.get("RUSTFLAGS").cloned().unwrap_or_default());
env.get("RUSTFLAGS").cloned().unwrap_or_default()
);
env.insert("RUSTFLAGS".to_string(), rustflags); env.insert("RUSTFLAGS".to_string(), rustflags);
let path = Path::new(crate::BUILD_DIR).join("regex"); let path = Path::new(crate::BUILD_DIR).join("regex");
run_cargo_command( run_cargo_command(
@ -899,6 +823,7 @@ fn should_not_remove_test(file: &str) -> bool {
.any(|to_ignore| file.ends_with(to_ignore)) .any(|to_ignore| file.ends_with(to_ignore))
} }
#[rustfmt::skip]
fn should_remove_test(file_path: &Path) -> Result<bool, String> { fn should_remove_test(file_path: &Path) -> Result<bool, String> {
// Tests generating errors. // Tests generating errors.
let file = File::open(file_path) let file = File::open(file_path)
@ -925,11 +850,7 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
return Ok(true); return Ok(true);
} }
} }
if file_path if file_path.display().to_string().contains("ambiguous-4-extern.rs") {
.display()
.to_string()
.contains("ambiguous-4-extern.rs")
{
eprintln!("nothing found for {file_path:?}"); eprintln!("nothing found for {file_path:?}");
} }
Ok(false) Ok(false)
@ -972,21 +893,13 @@ where
// These two functions are used to remove files that are known to not be working currently // These two functions are used to remove files that are known to not be working currently
// with the GCC backend to reduce noise. // with the GCC backend to reduce noise.
fn dir_handling(dir: &Path) -> Result<(), String> { fn dir_handling(dir: &Path) -> Result<(), String> {
if dir if dir.file_name().map(|name| name == "auxiliary").unwrap_or(true) {
.file_name()
.map(|name| name == "auxiliary")
.unwrap_or(true)
{
return Ok(()); return Ok(());
} }
walk_dir(dir, dir_handling, file_handling) walk_dir(dir, dir_handling, file_handling)
} }
fn file_handling(file_path: &Path) -> Result<(), String> { fn file_handling(file_path: &Path) -> Result<(), String> {
if !file_path if !file_path.extension().map(|extension| extension == "rs").unwrap_or(false) {
.extension()
.map(|extension| extension == "rs")
.unwrap_or(false)
{
return Ok(()); return Ok(());
} }
let path_str = file_path.display().to_string().replace("\\", "/"); let path_str = file_path.display().to_string().replace("\\", "/");
@ -1019,10 +932,7 @@ where
if nb_parts > 0 { if nb_parts > 0 {
let current_part = args.current_part.unwrap(); let current_part = args.current_part.unwrap();
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!( println!("Splitting ui_test into {} parts (and running part {})", nb_parts, current_part);
"Splitting ui_test into {} parts (and running part {})",
nb_parts, current_part
);
let out = String::from_utf8( let out = String::from_utf8(
run_command( run_command(
&[ &[
@ -1062,18 +972,15 @@ where
println!("[TEST] rustc test suite"); println!("[TEST] rustc test suite");
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string()); env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
let extra = if args.is_using_gcc_master_branch() { let extra =
"" if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
} else {
" -Csymbol-mangling-version=v0"
};
let rustc_args = format!( let rustc_args = format!(
"{} -Zcodegen-backend={} --sysroot {}{}", "{test_flags} -Zcodegen-backend={backend} --sysroot {sysroot}{extra}",
env.get("TEST_FLAGS").unwrap_or(&String::new()), test_flags = env.get("TEST_FLAGS").unwrap_or(&String::new()),
args.config_info.cg_backend_path, backend = args.config_info.cg_backend_path,
args.config_info.sysroot_path, sysroot = args.config_info.sysroot_path,
extra, extra = extra,
); );
env.get_mut("RUSTFLAGS").unwrap().clear(); env.get_mut("RUSTFLAGS").unwrap().clear();
@ -1120,18 +1027,11 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
// Putting back only the failing ones. // Putting back only the failing ones.
let path = "tests/failing-ui-tests.txt"; let path = "tests/failing-ui-tests.txt";
if let Ok(files) = std::fs::read_to_string(path) { if let Ok(files) = std::fs::read_to_string(path) {
for file in files for file in files.split('\n').map(|line| line.trim()).filter(|line| !line.is_empty()) {
.split('\n')
.map(|line| line.trim())
.filter(|line| !line.is_empty())
{
run_command(&[&"git", &"checkout", &"--", &file], Some(&rust_path))?; run_command(&[&"git", &"checkout", &"--", &file], Some(&rust_path))?;
} }
} else { } else {
println!( println!("Failed to read `{}`, not putting back failing ui tests", path);
"Failed to read `{}`, not putting back failing ui tests",
path
);
} }
Ok(true) Ok(true)
}) })
@ -1142,19 +1042,12 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
// Removing the failing tests. // Removing the failing tests.
let path = "tests/failing-ui-tests.txt"; let path = "tests/failing-ui-tests.txt";
if let Ok(files) = std::fs::read_to_string(path) { if let Ok(files) = std::fs::read_to_string(path) {
for file in files for file in files.split('\n').map(|line| line.trim()).filter(|line| !line.is_empty()) {
.split('\n')
.map(|line| line.trim())
.filter(|line| !line.is_empty())
{
let path = rust_path.join(file); let path = rust_path.join(file);
remove_file(&path)?; remove_file(&path)?;
} }
} else { } else {
println!( println!("Failed to read `{}`, not putting back failing ui tests", path);
"Failed to read `{}`, not putting back failing ui tests",
path
);
} }
Ok(true) Ok(true)
}) })
@ -1181,14 +1074,8 @@ pub fn run() -> Result<(), String> {
if !args.use_system_gcc { if !args.use_system_gcc {
args.config_info.setup_gcc_path()?; args.config_info.setup_gcc_path()?;
env.insert( env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
"LIBRARY_PATH".to_string(), env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
args.config_info.gcc_path.clone(),
);
env.insert(
"LD_LIBRARY_PATH".to_string(),
args.config_info.gcc_path.clone(),
);
} }
build_if_no_backend(&env, &args)?; build_if_no_backend(&env, &args)?;

View File

@ -37,13 +37,8 @@ fn check_exit_status(
} }
let mut error = format!( let mut error = format!(
"Command `{}`{} exited with status {:?}", "Command `{}`{} exited with status {:?}",
input input.iter().map(|s| s.as_ref().to_str().unwrap()).collect::<Vec<_>>().join(" "),
.iter() cwd.map(|cwd| format!(" (running in folder `{}`)", cwd.display())).unwrap_or_default(),
.map(|s| s.as_ref().to_str().unwrap())
.collect::<Vec<_>>()
.join(" "),
cwd.map(|cwd| format!(" (running in folder `{}`)", cwd.display()))
.unwrap_or_default(),
exit_status.code() exit_status.code()
); );
let input = input.iter().map(|i| i.as_ref()).collect::<Vec<&OsStr>>(); let input = input.iter().map(|i| i.as_ref()).collect::<Vec<&OsStr>>();
@ -68,11 +63,7 @@ fn check_exit_status(
fn command_error<D: Debug>(input: &[&dyn AsRef<OsStr>], cwd: &Option<&Path>, error: D) -> String { fn command_error<D: Debug>(input: &[&dyn AsRef<OsStr>], cwd: &Option<&Path>, error: D) -> String {
format!( format!(
"Command `{}`{} failed to run: {error:?}", "Command `{}`{} failed to run: {error:?}",
input input.iter().map(|s| s.as_ref().to_str().unwrap()).collect::<Vec<_>>().join(" "),
.iter()
.map(|s| s.as_ref().to_str().unwrap())
.collect::<Vec<_>>()
.join(" "),
cwd.as_ref() cwd.as_ref()
.map(|cwd| format!(" (running in folder `{}`)", cwd.display(),)) .map(|cwd| format!(" (running in folder `{}`)", cwd.display(),))
.unwrap_or_default(), .unwrap_or_default(),
@ -88,9 +79,8 @@ pub fn run_command_with_env(
cwd: Option<&Path>, cwd: Option<&Path>,
env: Option<&HashMap<String, String>>, env: Option<&HashMap<String, String>>,
) -> Result<Output, String> { ) -> Result<Output, String> {
let output = get_command_inner(input, cwd, env) let output =
.output() get_command_inner(input, cwd, env).output().map_err(|e| command_error(input, &cwd, e))?;
.map_err(|e| command_error(input, &cwd, e))?;
check_exit_status(input, cwd, output.status, Some(&output), true)?; check_exit_status(input, cwd, output.status, Some(&output), true)?;
Ok(output) Ok(output)
} }
@ -164,10 +154,7 @@ pub fn cargo_install(to_install: &str) -> Result<(), String> {
pub fn get_os_name() -> Result<String, String> { pub fn get_os_name() -> Result<String, String> {
let output = run_command(&[&"uname"], None)?; let output = run_command(&[&"uname"], None)?;
let name = std::str::from_utf8(&output.stdout) let name = std::str::from_utf8(&output.stdout).unwrap_or("").trim().to_string();
.unwrap_or("")
.trim()
.to_string();
if !name.is_empty() { if !name.is_empty() {
Ok(name) Ok(name)
} else { } else {
@ -274,11 +261,7 @@ fn git_clone_inner(
command.push(&"1"); command.push(&"1");
} }
run_command_with_output(&command, None)?; run_command_with_output(&command, None)?;
Ok(CloneResult { Ok(CloneResult { ran_clone: true, repo_name, repo_dir: dest.display().to_string() })
ran_clone: true,
repo_name,
repo_dir: dest.display().to_string(),
})
} }
fn get_repo_name(url: &str) -> String { fn get_repo_name(url: &str) -> String {
@ -307,6 +290,25 @@ pub fn git_clone(
git_clone_inner(to_clone, dest, shallow_clone, repo_name) git_clone_inner(to_clone, dest, shallow_clone, repo_name)
} }
pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<(), String> {
fs::create_dir_all(&path).map_err(|error| {
format!("Failed to create directory `{}`: {:?}", path.as_ref().display(), error)
})
}
pub fn copy_file<F: AsRef<Path>, T: AsRef<Path>>(from: F, to: T) -> Result<(), String> {
fs::copy(&from, &to)
.map_err(|error| {
format!(
"Failed to copy file `{}` into `{}`: {:?}",
from.as_ref().display(),
to.as_ref().display(),
error
)
})
.map(|_| ())
}
/// This function differs from `git_clone` in how it handles *where* the repository will be cloned. /// This function differs from `git_clone` in how it handles *where* the repository will be cloned.
/// In `git_clone`, it is cloned in the provided path. In this function, the path you provide is /// In `git_clone`, it is cloned in the provided path. In this function, the path you provide is
/// the parent folder. So if you pass "a" as folder and try to clone "b.git", it will be cloned into /// the parent folder. So if you pass "a" as folder and try to clone "b.git", it will be cloned into
@ -318,12 +320,7 @@ pub fn git_clone_root_dir(
) -> Result<CloneResult, String> { ) -> Result<CloneResult, String> {
let repo_name = get_repo_name(to_clone); let repo_name = get_repo_name(to_clone);
git_clone_inner( git_clone_inner(to_clone, &dest_parent_dir.join(&repo_name), shallow_clone, repo_name)
to_clone,
&dest_parent_dir.join(&repo_name),
shallow_clone,
repo_name,
)
} }
pub fn walk_dir<P, D, F>(dir: P, mut dir_cb: D, mut file_cb: F) -> Result<(), String> pub fn walk_dir<P, D, F>(dir: P, mut dir_cb: D, mut file_cb: F) -> Result<(), String>
@ -383,11 +380,7 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
} }
} }
if !found_end { if !found_end {
return Err(format!( return Err(format!("Didn't find `{}` at the end of `{}`", end, &args[start..]));
"Didn't find `{}` at the end of `{}`",
end,
&args[start..]
));
} }
} else if c == '\\' { } else if c == '\\' {
// We skip the escaped character. // We skip the escaped character.
@ -403,11 +396,7 @@ pub fn split_args(args: &str) -> Result<Vec<String>, String> {
pub fn remove_file<P: AsRef<Path> + ?Sized>(file_path: &P) -> Result<(), String> { pub fn remove_file<P: AsRef<Path> + ?Sized>(file_path: &P) -> Result<(), String> {
std::fs::remove_file(file_path).map_err(|error| { std::fs::remove_file(file_path).map_err(|error| {
format!( format!("Failed to remove `{}`: {:?}", file_path.as_ref().display(), error)
"Failed to remove `{}`: {:?}",
file_path.as_ref().display(),
error
)
}) })
} }
@ -427,6 +416,10 @@ pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> R
}) })
} }
pub fn get_sysroot_dir() -> PathBuf {
Path::new(crate::BUILD_DIR).join("build_sysroot")
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -79,7 +79,7 @@ pub fn main_inner(profile: Profile) {
compiler.args([ compiler.args([
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir), &format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
"--sysroot", "--sysroot",
&format!("{}/build_sysroot/sysroot/", current_dir), &format!("{}/build/build_sysroot/sysroot/", current_dir),
"-Zno-parallel-llvm", "-Zno-parallel-llvm",
"-C", "-C",
"link-arg=-lc", "link-arg=-lc",