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

Support absolute target JSON paths #205

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
16 changes: 10 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ impl CompilationMode {
Ok(())
}

/// Returns the condensed target triple (removes any `.json` extension and path components).
fn triple(&self) -> &str {
match *self {
CompilationMode::Cross(ref target) => target.triple(),
CompilationMode::Native(ref triple) => triple,
}
}

/// Returns the original target triple passed to xargo (perhaps with `.json` extension).
fn orig_triple(&self) -> &str {
match *self {
CompilationMode::Cross(ref target) => target.orig_triple(),
CompilationMode::Native(ref triple) => triple,
}
}

fn is_native(&self) -> bool {
match *self {
CompilationMode::Native(_) => true,
Expand Down Expand Up @@ -151,12 +160,7 @@ fn run() -> Result<ExitStatus> {
};

let cmode = if let Some(triple) = args.target() {
if Path::new(triple).is_file() {
bail!(
"Xargo doesn't support files as an argument to --target. \
Use `--target foo` instead of `--target foo.json`."
)
} else if triple == meta.host {
if triple == meta.host {
Some(CompilationMode::Native(meta.host.clone()))
} else {
Target::new(triple, &cd, verbose)?.map(CompilationMode::Cross)
Expand Down
27 changes: 24 additions & 3 deletions src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Sysroot {
#[derive(Debug)]
pub enum Target {
Builtin { triple: String },
Custom { json: PathBuf, triple: String },
Custom { json: PathBuf, triple: String, orig_triple: String },
}

impl Target {
Expand All @@ -121,13 +121,24 @@ impl Target {
if rustc::targets(verbose)?.iter().any(|t| t == &triple) {
Ok(Some(Target::Builtin { triple: triple }))
} else {
let json = PathBuf::from(&triple);
if json.exists() {
let file_stem = match json.file_stem().and_then(|stem| stem.to_str()) {
Some(stem) => stem.into(),
None => {
bail!("target file name {:?} is empty or contains invalid unicode", json)
}
};
return Ok(Some(Target::Custom { json, triple: file_stem, orig_triple: triple }))
}
let mut json = cd.path().join(&triple);
json.set_extension("json");

if json.exists() {
return Ok(Some(Target::Custom {
json: json,
triple: triple,
triple: triple.clone(),
orig_triple: triple,
}));
} else {
if let Some(p) = env::var_os("RUST_TARGET_PATH") {
Expand All @@ -138,7 +149,8 @@ impl Target {
if json.exists() {
return Ok(Some(Target::Custom {
json: json,
triple: triple,
triple: triple.clone(),
orig_triple: triple,
}));
}
}
Expand All @@ -148,13 +160,22 @@ impl Target {
}
}

/// Returns the condensed target triple (removes any `.json` extension and path components).
pub fn triple(&self) -> &str {
match *self {
Target::Builtin { ref triple } => triple,
Target::Custom { ref triple, .. } => triple,
}
}

/// Returns the original target triple passed to xargo (perhaps with `.json` extension).
pub fn orig_triple(&self) -> &str {
match *self {
Target::Builtin { ref triple } => triple,
Target::Custom { ref orig_triple, .. } => orig_triple,
}
}

pub fn hash<H>(&self, hasher: &mut H) -> Result<()>
where
H: Hasher,
Expand Down
2 changes: 1 addition & 1 deletion src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ version = "0.0.0"
}
cmd.arg("--manifest-path");
cmd.arg(td.join("Cargo.toml"));
cmd.args(&["--target", cmode.triple()]);
cmd.args(&["--target", cmode.orig_triple()]);

if verbose {
cmd.arg("-v");
Expand Down