Skip to content

Commit 4fe28b7

Browse files
Add --gcc-path option
1 parent 8d0eb87 commit 4fe28b7

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

build_system/src/build.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
184184
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
185185
let mut env = HashMap::new();
186186

187-
env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
188-
env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
187+
let gcc_path = args.config_info.gcc_path.clone().unwrap();
188+
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path.clone());
189+
env.insert("LIBRARY_PATH".to_string(), gcc_path);
189190

190191
if args.config_info.no_default_features {
191192
env.insert("RUSTFLAGS".to_string(), "-Csymbol-mangling-version=v0".to_string());

build_system/src/config.rs

+26-12
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct ConfigInfo {
112112
pub sysroot_panic_abort: bool,
113113
pub cg_backend_path: String,
114114
pub sysroot_path: String,
115-
pub gcc_path: String,
115+
pub gcc_path: Option<String>,
116116
config_file: Option<String>,
117117
// This is used in particular in rust compiler bootstrap because it doesn't run at the root
118118
// of the `cg_gcc` folder, making it complicated for us to get access to local files we need
@@ -173,6 +173,14 @@ impl ConfigInfo {
173173
"--release-sysroot" => self.sysroot_release_channel = true,
174174
"--release" => self.channel = Channel::Release,
175175
"--sysroot-panic-abort" => self.sysroot_panic_abort = true,
176+
"--gcc-path" => match args.next() {
177+
Some(arg) if !arg.is_empty() => {
178+
self.gcc_path = Some(arg.into());
179+
}
180+
_ => {
181+
return Err("Expected a value after `--gcc-path`, found nothing".to_string());
182+
}
183+
},
176184
"--cg_gcc-path" => match args.next() {
177185
Some(arg) if !arg.is_empty() => {
178186
self.cg_gcc_path = Some(arg.into());
@@ -260,8 +268,9 @@ impl ConfigInfo {
260268
create_symlink(&libgccjit_so, output_dir.join(&format!("{}.0", libgccjit_so_name)))?;
261269
}
262270

263-
self.gcc_path = output_dir.display().to_string();
264-
println!("Using `{}` as path for libgccjit", self.gcc_path);
271+
let gcc_path = output_dir.display().to_string();
272+
println!("Using `{}` as path for libgccjit", gcc_path);
273+
self.gcc_path = Some(gcc_path);
265274
Ok(())
266275
}
267276

@@ -273,6 +282,11 @@ impl ConfigInfo {
273282
}
274283

275284
pub fn setup_gcc_path(&mut self) -> Result<(), String> {
285+
// If the user used the `--gcc-path` option, no need to look at `config.toml` content
286+
// since we already have everything we need.
287+
if self.gcc_path.is_some() {
288+
return Ok(());
289+
}
276290
let config_file = match self.config_file.as_deref() {
277291
Some(config_file) => config_file.into(),
278292
None => self.compute_path("config.toml"),
@@ -283,12 +297,10 @@ impl ConfigInfo {
283297
self.download_gccjit_if_needed()?;
284298
return Ok(());
285299
}
286-
self.gcc_path = match gcc_path {
287-
Some(path) => path,
288-
None => {
289-
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),));
290-
}
291-
};
300+
if gcc_path.is_none() {
301+
return Err(format!("missing `gcc-path` value from `{}`", config_file.display()));
302+
}
303+
self.gcc_path = gcc_path;
292304
Ok(())
293305
}
294306

@@ -299,10 +311,11 @@ impl ConfigInfo {
299311
) -> Result<(), String> {
300312
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
301313

302-
if self.gcc_path.is_empty() && !use_system_gcc {
314+
if self.gcc_path.is_none() && !use_system_gcc {
303315
self.setup_gcc_path()?;
304316
}
305-
env.insert("GCC_PATH".to_string(), self.gcc_path.clone());
317+
let gcc_path = self.gcc_path.clone().expect("GCC path wasn't provided");
318+
env.insert("GCC_PATH".to_string(), gcc_path.clone());
306319

307320
if self.cargo_target_dir.is_empty() {
308321
match env.get("CARGO_TARGET_DIR").filter(|dir| !dir.is_empty()) {
@@ -414,7 +427,7 @@ impl ConfigInfo {
414427
"{target}:{sysroot}:{gcc_path}",
415428
target = self.cargo_target_dir,
416429
sysroot = sysroot.display(),
417-
gcc_path = self.gcc_path,
430+
gcc_path = gcc_path,
418431
);
419432
env.insert("LIBRARY_PATH".to_string(), ld_library_path.clone());
420433
env.insert("LD_LIBRARY_PATH".to_string(), ld_library_path.clone());
@@ -459,6 +472,7 @@ impl ConfigInfo {
459472
--release-sysroot : Build sysroot in release mode
460473
--sysroot-panic-abort : Build the sysroot without unwinding support
461474
--config-file : Location of the config file to be used
475+
--gcc-path : Location of the GCC root folder
462476
--cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
463477
when ran from another directory)
464478
--no-default-features : Add `--no-default-features` flag to cargo commands

build_system/src/info.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub fn run() -> Result<(), String> {
1414
}
1515
config.no_download = true;
1616
config.setup_gcc_path()?;
17-
println!("{}", config.gcc_path);
17+
if let Some(gcc_path) = config.gcc_path {
18+
println!("{}", gcc_path);
19+
}
1820
Ok(())
1921
}

build_system/src/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,9 @@ pub fn run() -> Result<(), String> {
12551255

12561256
if !args.use_system_gcc {
12571257
args.config_info.setup_gcc_path()?;
1258-
env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
1259-
env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
1258+
let gcc_path = args.config_info.gcc_path.clone().expect("GCC path wasn't provided");
1259+
env.insert("LIBRARY_PATH".to_string(), gcc_path.clone());
1260+
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path);
12601261
}
12611262

12621263
build_if_no_backend(&env, &args)?;

0 commit comments

Comments
 (0)