Skip to content

Commit cde105a

Browse files
Move build_sysroot folder into build_system
1 parent ab1ea40 commit cde105a

File tree

12 files changed

+73
-37
lines changed

12 files changed

+73
-37
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
git config --global user.email "[email protected]"
6363
git config --global user.name "User"
6464
./y.sh prepare
65-
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
66-
echo -n 'lto = "fat"' >> build_sysroot/Cargo.toml
6765
6866
- name: Add more failing tests because of undefined symbol errors (FIXME)
6967
run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt
7068

7169
- name: Run tests
7270
run: |
71+
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
72+
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
7373
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

.github/workflows/stdarch.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ jobs:
8989
- name: Run stdarch tests
9090
if: ${{ !matrix.cargo_runner }}
9191
run: |
92-
cd build_sysroot/sysroot_src/library/stdarch/
93-
CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../y.sh cargo test
92+
cd build/build_sysroot/sysroot_src/library/stdarch/
93+
CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../../y.sh cargo test
9494
9595
- name: Run stdarch tests
9696
if: ${{ matrix.cargo_runner }}
9797
run: |
98-
cd build_sysroot/sysroot_src/library/stdarch/
98+
cd build/build_sysroot/sysroot_src/library/stdarch/
9999
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
100-
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
100+
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

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ perf.data
66
perf.data.old
77
*.events
88
*.string*
9-
/build_sysroot/sysroot
10-
/build_sysroot/sysroot_src
11-
/build_sysroot/Cargo.lock
12-
/build_sysroot/test_target/Cargo.lock
139
gimple*
1410
*asm
1511
res

build_sysroot/Cargo.toml renamed to build_system/build_sysroot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
authors = ["bjorn3 <[email protected]>"]
2+
authors = ["rustc_codegen_gcc devs"]
33
name = "sysroot"
44
version = "0.0.0"
55
resolver = "2"
File renamed without changes.

build_system/src/build.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::config::{Channel, ConfigInfo};
2-
use crate::utils::{create_dir, run_command, run_command_with_output_and_env, walk_dir};
2+
use crate::utils::{
3+
copy_file, create_dir, get_sysroot_dir, run_command, run_command_with_output_and_env, walk_dir,
4+
};
35
use std::collections::HashMap;
46
use std::ffi::OsStr;
57
use std::fs;
@@ -101,10 +103,24 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
101103
let _ = fs::remove_dir_all(start_dir.join("sysroot"));
102104
}
103105

106+
pub fn create_build_sysroot_content(start_dir: &Path) -> Result<(), String> {
107+
if !start_dir.is_dir() {
108+
create_dir(start_dir)?;
109+
}
110+
copy_file("build_system/build_sysroot/Cargo.toml", &start_dir.join("Cargo.toml"))?;
111+
112+
let src_dir = start_dir.join("src");
113+
if !src_dir.is_dir() {
114+
create_dir(&src_dir)?;
115+
}
116+
copy_file("build_system/build_sysroot/lib.rs", &start_dir.join("src/lib.rs"))
117+
}
118+
104119
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
105-
let start_dir = Path::new("build_sysroot");
120+
let start_dir = get_sysroot_dir();
106121

107122
cleanup_sysroot_previous_build(&start_dir);
123+
create_build_sysroot_content(&start_dir)?;
108124

109125
// Builds libs
110126
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
@@ -115,7 +131,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
115131
if config.no_default_features {
116132
rustflags.push_str(" -Csymbol-mangling-version=v0");
117133
}
118-
let mut env = env.clone();
119134

120135
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
121136

@@ -132,8 +147,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
132147
"debug"
133148
};
134149

150+
let mut env = env.clone();
135151
env.insert("RUSTFLAGS".to_string(), rustflags);
136-
run_command_with_output_and_env(&args, Some(start_dir), Some(&env))?;
152+
run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?;
137153

138154
// Copy files to sysroot
139155
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));

build_system/src/clean.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{remove_file, run_command};
1+
use crate::utils::{get_sysroot_dir, remove_file, run_command};
22

33
use std::fs::remove_dir_all;
44
use std::path::Path;
@@ -42,8 +42,13 @@ fn usage() {
4242
}
4343

4444
fn clean_all() -> Result<(), String> {
45-
let dirs_to_remove =
46-
["target", "build_sysroot/sysroot", "build_sysroot/sysroot_src", "build_sysroot/target"];
45+
let build_sysroot = get_sysroot_dir();
46+
let dirs_to_remove = [
47+
"target".into(),
48+
build_sysroot.join("sysroot"),
49+
build_sysroot.join("sysroot_src"),
50+
build_sysroot.join("target"),
51+
];
4752
for dir in dirs_to_remove {
4853
let _ = remove_dir_all(dir);
4954
}
@@ -52,10 +57,11 @@ fn clean_all() -> Result<(), String> {
5257
let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir));
5358
}
5459

55-
let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"];
60+
let files_to_remove =
61+
[build_sysroot.join("Cargo.lock"), "perf.data".into(), "perf.data.old".into()];
5662

5763
for file in files_to_remove {
58-
let _ = remove_file(file);
64+
let _ = remove_file(&file);
5965
}
6066

6167
println!("Successfully ran `clean all`");

build_system/src/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
create_dir, create_symlink, get_os_name, run_command_with_output, rustc_version_info,
3-
split_args,
2+
create_dir, create_symlink, get_os_name, get_sysroot_dir, run_command_with_output,
3+
rustc_version_info, split_args,
44
};
55
use std::collections::HashMap;
66
use std::env as std_env;
@@ -363,7 +363,8 @@ impl ConfigInfo {
363363
.join(&format!("librustc_codegen_gcc.{}", self.dylib_ext))
364364
.display()
365365
.to_string();
366-
self.sysroot_path = current_dir.join("build_sysroot/sysroot").display().to_string();
366+
self.sysroot_path =
367+
current_dir.join(&get_sysroot_dir()).join("sysroot").display().to_string();
367368
if let Some(backend) = &self.backend {
368369
// This option is only used in the rust compiler testsuite. The sysroot is handled
369370
// by its build system directly so no need to set it ourselves.
@@ -392,8 +393,6 @@ impl ConfigInfo {
392393
rustflags.push("-Csymbol-mangling-version=v0".to_string());
393394
}
394395

395-
396-
397396
// Since we don't support ThinLTO, disable LTO completely when not trying to do LTO.
398397
// TODO(antoyo): remove when we can handle ThinLTO.
399398
if !env.contains_key(&"FAT_LTO".to_string()) {
@@ -411,7 +410,8 @@ impl ConfigInfo {
411410
env.insert("RUSTC_LOG".to_string(), "warn".to_string());
412411

413412
let sysroot = current_dir
414-
.join(&format!("build_sysroot/sysroot/lib/rustlib/{}/lib", self.target_triple,));
413+
.join(&get_sysroot_dir())
414+
.join(&format!("sysroot/lib/rustlib/{}/lib", self.target_triple));
415415
let ld_library_path = format!(
416416
"{target}:{sysroot}:{gcc_path}",
417417
target = self.cargo_target_dir,

build_system/src/prepare.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::rustc_info::get_rustc_path;
22
use crate::utils::{
3-
cargo_install, create_dir, git_clone_root_dir, remove_file, run_command,
3+
cargo_install, create_dir, get_sysroot_dir, git_clone_root_dir, remove_file, run_command,
44
run_command_with_output, walk_dir,
55
};
66

@@ -89,7 +89,7 @@ fn prepare_libcore(
8989
patches.sort();
9090
for file_path in patches {
9191
println!("[GIT] apply `{}`", file_path.display());
92-
let path = Path::new("../..").join(file_path);
92+
let path = Path::new("../../..").join(file_path);
9393
run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
9494
run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
9595
run_command_with_output(
@@ -192,8 +192,8 @@ pub fn run() -> Result<(), String> {
192192
Some(a) => a,
193193
None => return Ok(()),
194194
};
195-
let sysroot_path = Path::new("build_sysroot");
196-
prepare_libcore(sysroot_path, args.libgccjit12_patches, args.cross_compile)?;
195+
let sysroot_path = get_sysroot_dir();
196+
prepare_libcore(&sysroot_path, args.libgccjit12_patches, args.cross_compile)?;
197197

198198
if !args.only_libcore {
199199
cargo_install("hyperfine")?;

build_system/src/test.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::build;
22
use crate::config::{Channel, ConfigInfo};
33
use crate::utils::{
4-
create_dir, get_toolchain, git_clone, git_clone_root_dir, remove_file, run_command,
5-
run_command_with_env, run_command_with_output_and_env, rustc_version_info, split_args,
6-
walk_dir,
4+
create_dir, get_sysroot_dir, get_toolchain, git_clone, git_clone_root_dir, remove_file,
5+
run_command, run_command_with_env, run_command_with_output_and_env, rustc_version_info,
6+
split_args, walk_dir,
77
};
88

99
use std::collections::{BTreeSet, HashMap};
@@ -535,12 +535,13 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
535535
let rustc_args = &format!(
536536
r#"-Zpanic-abort-tests \
537537
-Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
538-
--sysroot "{pwd}/build_sysroot/sysroot" -Cpanic=abort{extra}"#,
538+
--sysroot "{pwd}/{sysroot_dir}" -Cpanic=abort{extra}"#,
539539
pwd = std::env::current_dir()
540540
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
541541
.display(),
542542
channel = args.config_info.channel.as_str(),
543543
dylib_ext = args.config_info.dylib_ext,
544+
sysroot_dir = args.config_info.sysroot_path,
544545
extra = extra,
545546
);
546547

@@ -671,9 +672,9 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
671672
fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
672673
// FIXME: create a function "display_if_not_quiet" or something along the line.
673674
println!("[TEST] libcore");
674-
let path = Path::new("build_sysroot/sysroot_src/library/core/tests");
675+
let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
675676
let _ = remove_dir_all(path.join("target"));
676-
run_cargo_command(&[&"test"], Some(path), env, args)?;
677+
run_cargo_command(&[&"test"], Some(&path), env, args)?;
677678
Ok(())
678679
}
679680

build_system/src/utils.rs

+17
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<(), String> {
296296
})
297297
}
298298

299+
pub fn copy_file<F: AsRef<Path>, T: AsRef<Path>>(from: F, to: T) -> Result<(), String> {
300+
fs::copy(&from, &to)
301+
.map_err(|error| {
302+
format!(
303+
"Failed to copy file `{}` into `{}`: {:?}",
304+
from.as_ref().display(),
305+
to.as_ref().display(),
306+
error
307+
)
308+
})
309+
.map(|_| ())
310+
}
311+
299312
/// This function differs from `git_clone` in how it handles *where* the repository will be cloned.
300313
/// In `git_clone`, it is cloned in the provided path. In this function, the path you provide is
301314
/// the parent folder. So if you pass "a" as folder and try to clone "b.git", it will be cloned into
@@ -403,6 +416,10 @@ pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> R
403416
})
404417
}
405418

419+
pub fn get_sysroot_dir() -> PathBuf {
420+
Path::new(crate::BUILD_DIR).join("build_sysroot")
421+
}
422+
406423
#[cfg(test)]
407424
mod tests {
408425
use super::*;

tests/lang_tests_common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn main_inner(profile: Profile) {
7979
compiler.args([
8080
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
8181
"--sysroot",
82-
&format!("{}/build_sysroot/sysroot/", current_dir),
82+
&format!("{}/build/build_sysroot/sysroot/", current_dir),
8383
"-Zno-parallel-llvm",
8484
"-C",
8585
"link-arg=-lc",

0 commit comments

Comments
 (0)