From 1a76dad374350a0b6780fbd60be4b4bf9cc0894e Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sat, 24 Mar 2018 20:17:02 +0100 Subject: [PATCH] Add support for (absolut) target JSON paths --- src/main.rs | 7 +------ src/rustc.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2575d16..88a1d33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,12 +151,7 @@ fn run() -> Result { }; 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) diff --git a/src/rustc.rs b/src/rustc.rs index 3e86816..d7dc4a0 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -121,6 +121,19 @@ impl Target { if rustc::targets(verbose)?.iter().any(|t| t == &triple) { Ok(Some(Target::Builtin { triple: triple })) } else { + if Path::new(&triple).exists() { + let path = match Path::new(&triple).canonicalize() { + Ok(path) => path, + Err(_) => bail!("target path {:?} is invalid", triple), + }; + let file_stem = match path.file_stem().and_then(|stem| stem.to_str()) { + Some(stem) => stem.into(), + None => { + bail!("target file name {:?} is empty or contains invalid unicode", path) + } + }; + return Ok(Some(Target::Custom { json: path, triple: file_stem })) + } let mut json = cd.path().join(&triple); json.set_extension("json");