Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Use stable Rust #512

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ endif
.PHONY: setup
setup: setup-qemu
rustup install stable
cargo +stable install elf2tab
cargo miri setup
rustup target add --toolchain stable thumbv7em-none-eabi
cargo install elf2tab
cargo +nightly miri setup

# Sets up QEMU in the tock/ directory. We use Tock's QEMU which may contain
# patches to better support boards that Tock supports.
Expand Down Expand Up @@ -108,19 +107,8 @@ EXCLUDE_STD := --exclude libtock_unittest --exclude print_sizes \
--exclude runner --exclude syscalls_tests \
--exclude libtock_build_scripts

# Currently, all of our crates should build with a stable toolchain. This
# verifies our crates don't depend on unstable features by using cargo check. We
# specify a different target directory so this doesn't flush the cargo cache of
# the primary toolchain.
.PHONY: test-stable
test-stable:
cargo +stable check --target-dir=target/stable --workspace \
$(EXCLUDE_RUNTIME)
LIBTOCK_PLATFORM=nrf52 cargo +stable check $(EXCLUDE_STD) \
--target=thumbv7em-none-eabi --target-dir=target/stable --workspace

.PHONY: test
test: examples test-stable
test: examples
cargo test $(EXCLUDE_RUNTIME) --workspace
LIBTOCK_PLATFORM=nrf52 cargo fmt --all -- --check
cargo clippy --all-targets $(EXCLUDE_RUNTIME) --workspace
Expand All @@ -129,7 +117,7 @@ test: examples test-stable
LIBTOCK_PLATFORM=hifive1 cargo clippy $(EXCLUDE_STD) \
--target=riscv32imac-unknown-none-elf --workspace
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check" \
cargo miri test $(EXCLUDE_MIRI) --workspace
cargo +nightly miri test $(EXCLUDE_MIRI) --workspace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pin to a particular nightly release, otherwise this will break randomly as new nightly toolchains come out.

echo '[ SUCCESS ] libtock-rs tests pass'

# Helper functions to define make targets to build for specific (flash, ram,
Expand Down
17 changes: 14 additions & 3 deletions platform/src/register.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::mem::transmute;

/// In order to work with Miri's `-Zmiri-track-raw-pointers` flag, we cannot
/// pass pointers to the kernel through `usize` values (as casting to and from
/// `usize` drops the pointer`s tag). Instead, `RawSyscalls` uses the `Register`
Expand All @@ -16,19 +18,28 @@ pub struct Register(pub *mut ());

impl From<crate::ErrorCode> for Register {
fn from(value: crate::ErrorCode) -> Register {
Register(value as u16 as *mut ())
(value as usize).into()
}
}

impl From<u32> for Register {
fn from(value: u32) -> Register {
Register(value as *mut ())
(value as usize).into()
}
}

impl From<usize> for Register {
fn from(value: usize) -> Register {
Register(value as *mut ())
// Note: clippy is wrong here; transmute has different semantics than
// `as` casts under strict provenance.
#[allow(clippy::useless_transmute)]
// We want to convert using the same semantics as core::ptr::invalid:
// convert the usize into a pointer with that address without attaching
// provenance to it. However, core::ptr::invalid is a nightly-only
// function. In order to build on stable, we copy its implementation.
// Safety: Raw pointers do not have any validity invariants that usize
// does not have; a raw pointer can point to any address.
Register(unsafe { transmute(value) })
}
}

Expand Down
6 changes: 2 additions & 4 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[toolchain]
# See https://rust-lang.github.io/rustup-components-history/ for a list of
# recently nightlies and what components are available for them.
channel = "nightly-2022-06-10"
components = ["clippy", "miri", "rustfmt"]
channel = "stable"
components = ["clippy", "rustfmt"]
targets = ["thumbv6m-none-eabi",
"thumbv7em-none-eabi",
"riscv32imac-unknown-none-elf",
Expand Down
2 changes: 1 addition & 1 deletion unittest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ version = "0.1.0"

[dependencies]
libtock_platform = { path = "../platform" }
thiserror = "1.0"
thiserror = "1.0.44"
Loading