diff options
author | 2021-01-08 16:01:12 +0000 | |
---|---|---|
committer | 2021-01-08 16:01:12 +0000 | |
commit | 2dfbe1127f681dba9d3fc49c92fcbad0867a9987 (patch) | |
tree | ff9014b5771df23e1277605125e33b055f27dbaf | |
parent | 47987f6a85508f99173c23d6808996354c16e26f (diff) | |
parent | ac4fabb06590af2fe85d5b3e51654c7be1fd6466 (diff) | |
download | cortex-m-2dfbe1127f681dba9d3fc49c92fcbad0867a9987.tar.gz cortex-m-2dfbe1127f681dba9d3fc49c92fcbad0867a9987.tar.zst cortex-m-2dfbe1127f681dba9d3fc49c92fcbad0867a9987.zip |
Merge #304
304: Allow using the crate with custom target JSON specs r=adamgreig a=jonas-schievink
This should fix https://github.com/rust-embedded/cortex-m-rt/issues/145 (cc @thejpster)
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
-rw-r--r-- | cortex-m-rt/build.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cortex-m-rt/build.rs b/cortex-m-rt/build.rs index 67cdfab..20f32b8 100644 --- a/cortex-m-rt/build.rs +++ b/cortex-m-rt/build.rs @@ -1,10 +1,21 @@ -use std::env; use std::fs::{self, File}; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::{env, ffi::OsStr}; fn main() { - let target = env::var("TARGET").unwrap(); + let mut target = env::var("TARGET").unwrap(); + + // When using a custom target JSON, `$TARGET` contains the path to that JSON file. By + // convention, these files are named after the actual target triple, eg. + // `thumbv7m-customos-elf.json`, so we extract the file stem here to allow custom target specs. + let path = Path::new(&target); + if path.extension() == Some(OsStr::new("json")) { + target = path + .file_stem() + .map_or(target.clone(), |stem| stem.to_str().unwrap().to_string()); + } + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); has_fpu(&target); |