Skip to content

Commit eb02f31

Browse files
Merge pull request #160 from rust-embedded/remove-riscv-target
`riscv-rt`: remove riscv-target ;`riscv`:update for embedded-hal to 1.0.0-rc.2
2 parents f8c3923 + 1767d60 commit eb02f31

File tree

11 files changed

+58
-30
lines changed

11 files changed

+58
-30
lines changed

.github/workflows/riscv-rt.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
# All generated code should be running on stable now, MRSV is 1.59.0
14-
toolchain: [ stable, nightly, 1.59.0 ]
13+
# All generated code should be running on stable now, MRSV is 1.60.0
14+
toolchain: [ stable, nightly, 1.60.0 ]
1515
target:
1616
- riscv32i-unknown-none-elf
1717
- riscv32imc-unknown-none-elf
@@ -41,7 +41,7 @@ jobs:
4141
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --features=single-hart
4242
- name: Build example (all features)
4343
run: RUSTFLAGS="-C link-arg=-Triscv-rt/examples/device.x" cargo build --package riscv-rt --target ${{ matrix.target }} --example ${{ matrix.example }} --all-features
44-
44+
4545
# Job to check that all the builds succeeded
4646
build-check:
4747
needs:

.github/workflows/riscv.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build-riscv:
1212
strategy:
1313
matrix:
14-
# All generated code should be running on stable now, MRSV is 1.59.0
14+
# All generated code should be running on stable now, MRSV is 1.60.0
1515
toolchain: [ stable, nightly, 1.60.0 ]
1616
target:
1717
- riscv32i-unknown-none-elf
@@ -35,7 +35,7 @@ jobs:
3535
run: cargo build --package riscv --target ${{ matrix.target }}
3636
- name: Build (all features)
3737
run: cargo build --package riscv --target ${{ matrix.target }} --all-features
38-
38+
3939
# On MacOS, Ubuntu, and Windows, we at least make sure that the crate builds and links.
4040
build-others:
4141
strategy:
@@ -49,7 +49,7 @@ jobs:
4949
run: cargo build --package riscv
5050
- name: Build (all features)
5151
run: cargo build --package riscv --all-features
52-
52+
5353
# Job to check that all the builds succeeded
5454
build-check:
5555
needs:

riscv-rt/CHANGELOG.md

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

1717
### Changed
1818

19+
- Removed riscv-target dependency for build
20+
- Upgrade rust-version to 1.60
1921
- Cargo workspace for riscv and riscv-rt
2022
- Use inline assembly instead of pre-compiled blobs
2123
- Removed bors in favor of GitHub Merge Queue

riscv-rt/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "riscv-rt"
33
version = "0.11.0"
4-
rust-version = "1.59"
4+
rust-version = "1.60"
55
repository = "https://github.com/rust-embedded/riscv"
66
authors = ["The RISC-V Team <[email protected]>"]
77
categories = ["embedded", "no-std"]
@@ -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/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project is developed and maintained by the [RISC-V team][team].
1111

1212
## Minimum Supported Rust Version (MSRV)
1313

14-
This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
14+
This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
1515
compile with older versions but that may change in any new patch release.
1616

1717
## License

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
}

riscv-rt/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! # Minimum Supported Rust Version (MSRV)
44
//!
5-
//! This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
5+
//! This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
66
//! compile with older versions but that may change in any new patch release.
77
//!
88
//! # Features
@@ -483,14 +483,14 @@ pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
483483
sd {a},0({start})
484484
addi {start},{start},8
485485
bltu {start},{end},1b
486-
486+
487487
2: // .data zero registers
488488
li {a},0
489489
li {input},0
490490
491491
la {start},_sbss
492492
la {end},_ebss
493-
493+
494494
bgeu {start},{end},4f
495495
496496
3: // .bss main loop

riscv/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
### Changed
2222

2323
- Cargo workspace for riscv and riscv-rt
24-
- Update `embedded-hal` dependency to v1.0 (bumps MSRV to 1.60)
24+
- Update `embedded-hal` dependency to v1.0.0-rc.2 (bumps MSRV to 1.60)
2525
- `misa::MXL` renamed to `misa::XLEN`
2626
- Removed `bit_field` dependency
2727
- CI actions updated. They now use `checkout@v3` and `dtolnay/rust-toolchain`.

riscv/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "riscv"
33
version = "0.10.1"
44
edition = "2021"
5-
rust-version = "1.59"
5+
rust-version = "1.60"
66
repository = "https://github.com/rust-embedded/riscv"
77
authors = ["The RISC-V Team <[email protected]>"]
88
categories = ["embedded", "hardware-support", "no-std"]
@@ -24,4 +24,4 @@ critical-section-single-hart = ["critical-section/restore-state-bool"]
2424

2525
[dependencies]
2626
critical-section = "1.1.2"
27-
embedded-hal = "1.0.0-rc.1"
27+
embedded-hal = "1.0.0-rc.2"

riscv/src/delay.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Delay devices and providers
22
use crate::register::mcycle;
3-
use embedded_hal::delay::DelayUs;
3+
use embedded_hal::delay::DelayNs;
44

55
/// Machine mode cycle counter (`mcycle`) as a delay provider
66
#[derive(Copy, Clone)]
@@ -19,12 +19,12 @@ impl McycleDelay {
1919
}
2020
}
2121

22-
impl DelayUs for McycleDelay {
22+
impl DelayNs for McycleDelay {
2323
#[inline]
24-
fn delay_us(&mut self, us: u32) {
24+
fn delay_ns(&mut self, ns: u32) {
2525
let t0 = mcycle::read64();
26-
let us_64: u64 = us.into();
27-
let clock = (us_64 * (self.ticks_second as u64)) / 1_000_000u64;
26+
let ns_64: u64 = ns.into();
27+
let clock = (ns_64 * (self.ticks_second as u64)) / 1_000_000_000u64;
2828
while mcycle::read64().wrapping_sub(t0) <= clock {}
2929
}
3030
}

riscv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! # Minimum Supported Rust Version (MSRV)
44
//!
5-
//! This crate is guaranteed to compile on stable Rust 1.59 and up. It *might*
5+
//! This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
66
//! compile with older versions but that may change in any new patch release.
77
//!
88
//! # Features

0 commit comments

Comments
 (0)