Skip to content

Commit 2dfbe11

Browse files
Merge #304
304: Allow using the crate with custom target JSON specs r=adamgreig a=jonas-schievink This should fix rust-embedded/cortex-m-rt#145 (cc @thejpster) Co-authored-by: Jonas Schievink <[email protected]>
2 parents 47987f6 + ac4fabb commit 2dfbe11

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cortex-m-rt/build.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
use std::env;
21
use std::fs::{self, File};
32
use std::io::Write;
4-
use std::path::PathBuf;
3+
use std::path::{Path, PathBuf};
4+
use std::{env, ffi::OsStr};
55

66
fn main() {
7-
let target = env::var("TARGET").unwrap();
7+
let mut target = env::var("TARGET").unwrap();
8+
9+
// When using a custom target JSON, `$TARGET` contains the path to that JSON file. By
10+
// convention, these files are named after the actual target triple, eg.
11+
// `thumbv7m-customos-elf.json`, so we extract the file stem here to allow custom target specs.
12+
let path = Path::new(&target);
13+
if path.extension() == Some(OsStr::new("json")) {
14+
target = path
15+
.file_stem()
16+
.map_or(target.clone(), |stem| stem.to_str().unwrap().to_string());
17+
}
18+
819
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
920

1021
has_fpu(&target);

0 commit comments

Comments
 (0)