Skip to content

Commit 1a76dad

Browse files
committed
Add support for (absolut) target JSON paths
1 parent e06560b commit 1a76dad

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ fn run() -> Result<ExitStatus> {
151151
};
152152

153153
let cmode = if let Some(triple) = args.target() {
154-
if Path::new(triple).is_file() {
155-
bail!(
156-
"Xargo doesn't support files as an argument to --target. \
157-
Use `--target foo` instead of `--target foo.json`."
158-
)
159-
} else if triple == meta.host {
154+
if triple == meta.host {
160155
Some(CompilationMode::Native(meta.host.clone()))
161156
} else {
162157
Target::new(triple, &cd, verbose)?.map(CompilationMode::Cross)

src/rustc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ impl Target {
121121
if rustc::targets(verbose)?.iter().any(|t| t == &triple) {
122122
Ok(Some(Target::Builtin { triple: triple }))
123123
} else {
124+
if Path::new(&triple).exists() {
125+
let path = match Path::new(&triple).canonicalize() {
126+
Ok(path) => path,
127+
Err(_) => bail!("target path {:?} is invalid", triple),
128+
};
129+
let file_stem = match path.file_stem().and_then(|stem| stem.to_str()) {
130+
Some(stem) => stem.into(),
131+
None => {
132+
bail!("target file name {:?} is empty or contains invalid unicode", path)
133+
}
134+
};
135+
return Ok(Some(Target::Custom { json: path, triple: file_stem }))
136+
}
124137
let mut json = cd.path().join(&triple);
125138
json.set_extension("json");
126139

0 commit comments

Comments
 (0)