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

RFC: Handle custom targets #158

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ appveyor = { repository = "alexcrichton/gcc-rs" }

[dependencies]
rayon = { version = "0.7", optional = true }
serde_json = "1.0"

[features]
parallel = ["rayon"]
Expand Down
39 changes: 38 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#[cfg(feature = "parallel")]
extern crate rayon;
extern crate serde_json;

use std::env;
use std::ffi::{OsString, OsStr};
Expand Down Expand Up @@ -163,6 +164,42 @@ pub fn compile_library(output: &str, files: &[&str]) {
c.compile(output);
}

fn get_possibly_custom_target() -> Option<String> {
// Try to open this as a file (custom target), if it fails then
// assume it's a built in target and just return that
env::var("TARGET").ok().map_or(None, |env| {
// XXX This is a puzzle for later:
let pwd = env::var("PWD").unwrap();
println!("here, env is {}", env);
println!("and PWD is {}", pwd);
println!("yet this will fail: {:?}", fs::File::open(&env));
let fullpath = Path::new(&pwd).join(&env);
println!("and this will work: {:?}", fs::File::open(&fullpath));

// Working around the above
match fs::File::open(&fullpath) {
Ok(file) => {
let work_around_carrier_trait: Result<serde_json::Value, serde_json::Error> = serde_json::from_reader(file);
match work_around_carrier_trait {
Ok(specs) => {
let llvm_target = specs["llvm-target"].clone();
match llvm_target {
serde_json::Value::String(s) => Some(s),
_ => None,
}
}
Err(_) => None
}
}
Err(e) => {
println!("Err: {}", e);
None
}
}
})
}


impl Config {
/// Construct a new instance of a blank set of configuration.
///
Expand All @@ -177,7 +214,7 @@ impl Config {
cpp: false,
cpp_link_stdlib: None,
cpp_set_stdlib: None,
target: None,
target: get_possibly_custom_target(),
host: None,
out_dir: None,
opt_level: None,
Expand Down