Skip to content

Commit 43ace87

Browse files
committed
Remove riscv-target
1 parent f8c3923 commit 43ace87

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
### Changed
1818

19+
- Removed riscv-target dependency for build
1920
- Cargo workspace for riscv and riscv-rt
2021
- Use inline assembly instead of pre-compiled blobs
2122
- Removed bors in favor of GitHub Merge Queue

riscv-rt/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ riscv-rt-macros = { path = "macros", version = "0.2.0" }
2121

2222
[dev-dependencies]
2323
panic-halt = "0.2.0"
24-
25-
[build-dependencies]
26-
riscv-target = "0.1.2"

riscv-rt/build.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// NOTE: Adapted from cortex-m/build.rs
22

3-
use riscv_target::Target;
4-
use std::{env, fs, io, path::PathBuf};
3+
use std::{collections::HashSet, env, fs, io, path::PathBuf};
54

65
fn add_linker_script(arch_width: u32) -> io::Result<()> {
76
// Read the file to a string and replace all occurrences of ${ARCH_WIDTH} with the arch width
@@ -18,17 +17,47 @@ fn add_linker_script(arch_width: u32) -> io::Result<()> {
1817
Ok(())
1918
}
2019

20+
/// Parse the target RISC-V architecture and returns its bit width and the extension set
21+
fn parse_target(target: &str) -> (u32, HashSet<char>) {
22+
// isolate bit width and extensions from the rest of the target information
23+
let arch = target
24+
.trim_start_matches("riscv")
25+
.split('-')
26+
.next()
27+
.unwrap();
28+
29+
let bits = arch
30+
.chars()
31+
.take_while(|c| c.is_ascii_digit())
32+
.collect::<String>()
33+
.parse::<u32>()
34+
.unwrap();
35+
36+
let mut extensions: HashSet<char> = arch.chars().skip_while(|c| c.is_ascii_digit()).collect();
37+
// get rid of the 'g' shorthand extension
38+
if extensions.remove(&'g') {
39+
extensions.insert('i');
40+
extensions.insert('m');
41+
extensions.insert('a');
42+
extensions.insert('f');
43+
extensions.insert('d');
44+
}
45+
46+
(bits, extensions)
47+
}
48+
2149
fn main() {
2250
let target = env::var("TARGET").unwrap();
2351
let _name = env::var("CARGO_PKG_NAME").unwrap();
2452

2553
// set configuration flags depending on the target
2654
if target.starts_with("riscv") {
2755
println!("cargo:rustc-cfg=riscv");
28-
let target = Target::from_target_str(&target);
2956

30-
// generate the linker script
31-
let arch_width = match target.bits {
57+
let (bits, extensions) = parse_target(&target);
58+
59+
// generate the linker script and expose the ISA width
60+
let arch_width = match bits {
3261
32 => {
3362
println!("cargo:rustc-cfg=riscv32");
3463
4
@@ -42,8 +71,8 @@ fn main() {
4271
add_linker_script(arch_width).unwrap();
4372

4473
// expose the ISA extensions
45-
if target.has_extension('m') {
46-
println!("cargo:rustc-cfg=riscvm");
74+
for ext in &extensions {
75+
println!("cargo:rustc-cfg=riscv{}", ext);
4776
}
4877
}
4978
}

0 commit comments

Comments
 (0)