Skip to content

Commit ab1ea40

Browse files
Format code
1 parent 9b17b3d commit ab1ea40

File tree

7 files changed

+99
-353
lines changed

7 files changed

+99
-353
lines changed

build_system/src/build.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,36 +151,19 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
151151
// Copy the source files to the sysroot (Rust for Linux needs this).
152152
let sysroot_src_path = start_dir.join("sysroot/lib/rustlib/src/rust");
153153
create_dir(&sysroot_src_path)?;
154-
run_command(
155-
&[
156-
&"cp",
157-
&"-r",
158-
&start_dir.join("sysroot_src/library/"),
159-
&sysroot_src_path,
160-
],
161-
None,
162-
)?;
154+
run_command(&[&"cp", &"-r", &start_dir.join("sysroot_src/library/"), &sysroot_src_path], None)?;
163155

164156
Ok(())
165157
}
166158

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

170-
env.insert(
171-
"LD_LIBRARY_PATH".to_string(),
172-
args.config_info.gcc_path.clone(),
173-
);
174-
env.insert(
175-
"LIBRARY_PATH".to_string(),
176-
args.config_info.gcc_path.clone(),
177-
);
162+
env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
163+
env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
178164

179165
if args.config_info.no_default_features {
180-
env.insert(
181-
"RUSTFLAGS".to_string(),
182-
"-Csymbol-mangling-version=v0".to_string(),
183-
);
166+
env.insert("RUSTFLAGS".to_string(), "-Csymbol-mangling-version=v0".to_string());
184167
}
185168

186169
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];

build_system/src/cargo.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ fn args() -> Result<Option<Vec<String>>, String> {
1616
}
1717
let args = std::env::args().skip(2).collect::<Vec<_>>();
1818
if args.is_empty() {
19-
return Err(
20-
"Expected at least one argument for `cargo` subcommand, found none".to_string(),
21-
);
19+
return Err("Expected at least one argument for `cargo` subcommand, found none".to_string());
2220
}
2321
Ok(Some(args))
2422
}
@@ -48,17 +46,10 @@ pub fn run() -> Result<(), String> {
4846
let current_exe = std::env::current_exe()
4947
.and_then(|path| path.canonicalize())
5048
.map_err(|error| format!("Failed to get current exe path: {:?}", error))?;
51-
let mut parent_dir = current_exe
52-
.components()
53-
.map(|comp| comp.as_os_str())
54-
.collect::<Vec<_>>();
49+
let mut parent_dir = current_exe.components().map(|comp| comp.as_os_str()).collect::<Vec<_>>();
5550
// We run this script from "build_system/target/release/y", so we need to remove these elements.
5651
for to_remove in &["y", "release", "target", "build_system"] {
57-
if parent_dir
58-
.last()
59-
.map(|part| part == to_remove)
60-
.unwrap_or(false)
61-
{
52+
if parent_dir.last().map(|part| part == to_remove).unwrap_or(false) {
6253
parent_dir.pop();
6354
} else {
6455
return Err(format!(
@@ -69,11 +60,7 @@ pub fn run() -> Result<(), String> {
6960
}
7061
let parent_dir = PathBuf::from(parent_dir.join(&OsStr::new("/")));
7162
std::env::set_current_dir(&parent_dir).map_err(|error| {
72-
format!(
73-
"Failed to go to `{}` folder: {:?}",
74-
parent_dir.display(),
75-
error
76-
)
63+
format!("Failed to go to `{}` folder: {:?}", parent_dir.display(), error)
7764
})?;
7865

7966
let mut env: HashMap<String, String> = std::env::vars().collect();
@@ -92,11 +79,7 @@ pub fn run() -> Result<(), String> {
9279

9380
// We go back to the original folder since we now have set up everything we needed.
9481
std::env::set_current_dir(&current_dir).map_err(|error| {
95-
format!(
96-
"Failed to go back to `{}` folder: {:?}",
97-
current_dir.display(),
98-
error
99-
)
82+
format!("Failed to go back to `{}` folder: {:?}", current_dir.display(), error)
10083
})?;
10184

10285
let rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();

build_system/src/clean.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,8 @@ fn usage() {
4242
}
4343

4444
fn clean_all() -> Result<(), String> {
45-
let dirs_to_remove = [
46-
"target",
47-
"build_sysroot/sysroot",
48-
"build_sysroot/sysroot_src",
49-
"build_sysroot/target",
50-
];
45+
let dirs_to_remove =
46+
["target", "build_sysroot/sysroot", "build_sysroot/sysroot_src", "build_sysroot/target"];
5147
for dir in dirs_to_remove {
5248
let _ = remove_dir_all(dir);
5349
}

build_system/src/config.rs

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::utils::{
2-
create_dir, create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args,
2+
create_dir, create_symlink, get_os_name, run_command_with_output, rustc_version_info,
3+
split_args,
34
};
45
use std::collections::HashMap;
56
use std::env as std_env;
@@ -26,11 +27,7 @@ impl Channel {
2627
}
2728

2829
fn failed_config_parsing(config_file: &Path, err: &str) -> Result<ConfigFile, String> {
29-
Err(format!(
30-
"Failed to parse `{}`: {}",
31-
config_file.display(),
32-
err
33-
))
30+
Err(format!("Failed to parse `{}`: {}", config_file.display(), err))
3431
}
3532

3633
#[derive(Default)]
@@ -48,11 +45,7 @@ impl ConfigFile {
4845
)
4946
})?;
5047
let toml = Toml::parse(&content).map_err(|err| {
51-
format!(
52-
"Error occurred around `{}`: {:?}",
53-
&content[err.start..=err.end],
54-
err.kind
55-
)
48+
format!("Error occurred around `{}`: {:?}", &content[err.start..=err.end], err.kind)
5649
})?;
5750
let mut config = Self::default();
5851
for (key, value) in toml.iter() {
@@ -181,11 +174,7 @@ impl ConfigInfo {
181174
},
182175
"--use-backend" => match args.next() {
183176
Some(backend) if !backend.is_empty() => self.backend = Some(backend),
184-
_ => {
185-
return Err(
186-
"Expected an argument after `--use-backend`, found nothing".into()
187-
)
188-
}
177+
_ => return Err("Expected an argument after `--use-backend`, found nothing".into()),
189178
},
190179
"--no-default-features" => self.no_default_features = true,
191180
_ => return Ok(false),
@@ -231,11 +220,7 @@ impl ConfigInfo {
231220
create_dir(&output_dir)?;
232221
}
233222
let output_dir = output_dir.canonicalize().map_err(|err| {
234-
format!(
235-
"Failed to get absolute path of `{}`: {:?}",
236-
output_dir.display(),
237-
err
238-
)
223+
format!("Failed to get absolute path of `{}`: {:?}", output_dir.display(), err)
239224
})?;
240225

241226
let libgccjit_so_name = "libgccjit.so";
@@ -269,10 +254,7 @@ impl ConfigInfo {
269254
println!("Downloaded libgccjit.so version {} successfully!", commit);
270255
// We need to create a link named `libgccjit.so.0` because that's what the linker is
271256
// looking for.
272-
create_symlink(
273-
&libgccjit_so,
274-
output_dir.join(&format!("{}.0", libgccjit_so_name)),
275-
)?;
257+
create_symlink(&libgccjit_so, output_dir.join(&format!("{}.0", libgccjit_so_name)))?;
276258
}
277259

278260
self.gcc_path = output_dir.display().to_string();
@@ -292,10 +274,7 @@ impl ConfigInfo {
292274
Some(config_file) => config_file.into(),
293275
None => self.compute_path("config.toml"),
294276
};
295-
let ConfigFile {
296-
gcc_path,
297-
download_gccjit,
298-
} = ConfigFile::new(&config_file)?;
277+
let ConfigFile { gcc_path, download_gccjit } = ConfigFile::new(&config_file)?;
299278

300279
if let Some(true) = download_gccjit {
301280
self.download_gccjit_if_needed()?;
@@ -304,10 +283,7 @@ impl ConfigInfo {
304283
self.gcc_path = match gcc_path {
305284
Some(path) => path,
306285
None => {
307-
return Err(format!(
308-
"missing `gcc-path` value from `{}`",
309-
config_file.display(),
310-
))
286+
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),))
311287
}
312288
};
313289
Ok(())
@@ -387,17 +363,15 @@ impl ConfigInfo {
387363
.join(&format!("librustc_codegen_gcc.{}", self.dylib_ext))
388364
.display()
389365
.to_string();
390-
self.sysroot_path = current_dir
391-
.join("build_sysroot/sysroot")
392-
.display()
393-
.to_string();
366+
self.sysroot_path = current_dir.join("build_sysroot/sysroot").display().to_string();
394367
if let Some(backend) = &self.backend {
395368
// This option is only used in the rust compiler testsuite. The sysroot is handled
396369
// by its build system directly so no need to set it ourselves.
397370
rustflags.push(format!("-Zcodegen-backend={}", backend));
398371
} else {
399372
rustflags.extend_from_slice(&[
400-
"--sysroot".to_string(), self.sysroot_path.clone(),
373+
"--sysroot".to_string(),
374+
self.sysroot_path.clone(),
401375
format!("-Zcodegen-backend={}", self.cg_backend_path),
402376
]);
403377
}
@@ -436,10 +410,8 @@ impl ConfigInfo {
436410
// display metadata load errors
437411
env.insert("RUSTC_LOG".to_string(), "warn".to_string());
438412

439-
let sysroot = current_dir.join(&format!(
440-
"build_sysroot/sysroot/lib/rustlib/{}/lib",
441-
self.target_triple,
442-
));
413+
let sysroot = current_dir
414+
.join(&format!("build_sysroot/sysroot/lib/rustlib/{}/lib", self.target_triple,));
443415
let ld_library_path = format!(
444416
"{target}:{sysroot}:{gcc_path}",
445417
target = self.cargo_target_dir,
@@ -517,11 +489,7 @@ fn download_gccjit(
517489
&"--retry",
518490
&"3",
519491
&"-SRfL",
520-
if with_progress_bar {
521-
&"--progress-bar"
522-
} else {
523-
&"-s"
524-
},
492+
if with_progress_bar { &"--progress-bar" } else { &"-s" },
525493
&url.as_str(),
526494
],
527495
Some(&output_dir),

build_system/src/prepare.rs

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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, run_command_with_output, walk_dir,
3+
cargo_install, create_dir, git_clone_root_dir, remove_file, run_command,
4+
run_command_with_output, walk_dir,
45
};
56

67
use std::fs;
@@ -32,21 +33,14 @@ fn prepare_libcore(
3233
let sysroot_dir = sysroot_path.join("sysroot_src");
3334
if sysroot_dir.is_dir() {
3435
if let Err(error) = fs::remove_dir_all(&sysroot_dir) {
35-
return Err(format!(
36-
"Failed to remove `{}`: {:?}",
37-
sysroot_dir.display(),
38-
error,
39-
));
36+
return Err(format!("Failed to remove `{}`: {:?}", sysroot_dir.display(), error,));
4037
}
4138
}
4239

4340
let sysroot_library_dir = sysroot_dir.join("library");
4441
create_dir(&sysroot_library_dir)?;
4542

46-
run_command(
47-
&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir],
48-
None,
49-
)?;
43+
run_command(&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir], None)?;
5044

5145
println!("[GIT] init (cwd): `{}`", sysroot_dir.display());
5246
run_command(&[&"git", &"init"], Some(&sysroot_dir))?;
@@ -57,26 +51,11 @@ fn prepare_libcore(
5751
// This is needed on systems where nothing is configured.
5852
// git really needs something here, or it will fail.
5953
// Even using --author is not enough.
60-
run_command(
61-
&[&"git", &"config", &"user.email", &"[email protected]"],
62-
Some(&sysroot_dir),
63-
)?;
64-
run_command(
65-
&[&"git", &"config", &"user.name", &"None"],
66-
Some(&sysroot_dir),
67-
)?;
68-
run_command(
69-
&[&"git", &"config", &"core.autocrlf", &"false"],
70-
Some(&sysroot_dir),
71-
)?;
72-
run_command(
73-
&[&"git", &"config", &"commit.gpgSign", &"false"],
74-
Some(&sysroot_dir),
75-
)?;
76-
run_command(
77-
&[&"git", &"commit", &"-m", &"Initial commit", &"-q"],
78-
Some(&sysroot_dir),
79-
)?;
54+
run_command(&[&"git", &"config", &"user.email", &"[email protected]"], Some(&sysroot_dir))?;
55+
run_command(&[&"git", &"config", &"user.name", &"None"], Some(&sysroot_dir))?;
56+
run_command(&[&"git", &"config", &"core.autocrlf", &"false"], Some(&sysroot_dir))?;
57+
run_command(&[&"git", &"config", &"commit.gpgSign", &"false"], Some(&sysroot_dir))?;
58+
run_command(&[&"git", &"commit", &"-m", &"Initial commit", &"-q"], Some(&sysroot_dir))?;
8059

8160
let mut patches = Vec::new();
8261
walk_dir(
@@ -114,13 +93,7 @@ fn prepare_libcore(
11493
run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
11594
run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
11695
run_command_with_output(
117-
&[
118-
&"git",
119-
&"commit",
120-
&"--no-gpg-sign",
121-
&"-m",
122-
&format!("Patch {}", path.display()),
123-
],
96+
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
12497
Some(&sysroot_dir),
12598
)?;
12699
}
@@ -139,13 +112,7 @@ fn prepare_rand() -> Result<(), String> {
139112
run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?;
140113
run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?;
141114
run_command_with_output(
142-
&[
143-
&"git",
144-
&"commit",
145-
&"--no-gpg-sign",
146-
&"-m",
147-
&format!("Patch {}", path.display()),
148-
],
115+
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
149116
Some(rand_dir),
150117
)?;
151118

@@ -159,10 +126,7 @@ fn build_raytracer(repo_dir: &Path) -> Result<(), String> {
159126
if mv_target.is_file() {
160127
remove_file(&mv_target)?;
161128
}
162-
run_command(
163-
&[&"mv", &"target/debug/main", &"raytracer_cg_llvm"],
164-
Some(repo_dir),
165-
)?;
129+
run_command(&[&"mv", &"target/debug/main", &"raytracer_cg_llvm"], Some(repo_dir))?;
166130
Ok(())
167131
}
168132

@@ -207,11 +171,7 @@ impl PrepareArg {
207171
a => return Err(format!("Unknown argument `{a}`")),
208172
}
209173
}
210-
Ok(Some(Self {
211-
cross_compile,
212-
only_libcore,
213-
libgccjit12_patches,
214-
}))
174+
Ok(Some(Self { cross_compile, only_libcore, libgccjit12_patches }))
215175
}
216176

217177
fn usage() {

0 commit comments

Comments
 (0)