diff options
| author | Sean Cross <sean@xobs.io> | 2021-04-03 13:45:02 +0800 |
|---|---|---|
| committer | Sean Cross <sean@xobs.io> | 2021-04-03 14:39:40 +0800 |
| commit | 6f1ac8d756a7a7c22641020926458058a51d5dd3 (patch) | |
| tree | 33dec669d36e5181d4c02752ed1ad3aac7896988 /compiler/rustc_target | |
| parent | a0d66b54fb3acc2125972b88ff543a2c04d14af5 (diff) | |
| download | rust-6f1ac8d756a7a7c22641020926458058a51d5dd3.tar.gz rust-6f1ac8d756a7a7c22641020926458058a51d5dd3.zip | |
rustc: target: add sysroot to rust_target_path
This enables placing a `target.json` file into the rust sysroot under the target-specific directory. Signed-off-by: Sean Cross <sean@xobs.io>
Diffstat (limited to 'compiler/rustc_target')
| -rw-r--r-- | compiler/rustc_target/src/spec/mod.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 039e9a8b274..27653d3c331 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1747,13 +1747,15 @@ impl Target { } /// Search RUST_TARGET_PATH for a JSON file specifying the given target - /// triple. Note that it could also just be a bare filename already, so also + /// triple. If none is found, look for a file called `target.json` inside + /// the sysroot under the target-triple's `rustlib` directory. + /// Note that it could also just be a bare filename already, so also /// check for that. If one of the hardcoded targets we know about, just /// return it directly. /// /// The error string could come from any of the APIs called, including /// filesystem access and JSON decoding. - pub fn search(target_triple: &TargetTriple) -> Result<Target, String> { + pub fn search(target_triple: &TargetTriple, sysroot: &PathBuf) -> Result<Target, String> { use rustc_serialize::json; use std::env; use std::fs; @@ -1780,14 +1782,24 @@ impl Target { let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default(); - // FIXME 16351: add a sane default search path? - for dir in env::split_paths(&target_path) { let p = dir.join(&path); if p.is_file() { return load_file(&p); } } + + // Additionally look in the sysroot under `lib/rustlib/<triple>/target.json` + // as a fallback. + let p = sysroot + .join("lib") + .join("rustlib") + .join(&target_triple) + .join("target.json"); + if p.is_file() { + return load_file(&p); + } + Err(format!("Could not find specification for target {:?}", target_triple)) } TargetTriple::TargetPath(ref target_path) => { |
