diff --git a/src/main.rs b/src/main.rs index 2575d16..7181962 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,6 +56,7 @@ 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(), @@ -63,6 +64,14 @@ impl CompilationMode { } } + /// 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, @@ -151,12 +160,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..4ad1ccc 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -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 { @@ -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") { @@ -138,7 +149,8 @@ impl Target { if json.exists() { return Ok(Some(Target::Custom { json: json, - triple: triple, + triple: triple.clone(), + orig_triple: triple, })); } } @@ -148,6 +160,7 @@ 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, @@ -155,6 +168,14 @@ impl Target { } } + /// 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(&self, hasher: &mut H) -> Result<()> where H: Hasher, diff --git a/src/sysroot.rs b/src/sysroot.rs index eaea330..1d37bc3 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -131,7 +131,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");