Skip to content

Commit 107fb22

Browse files
committed
tock-register-interface: support disabling crate::registers
tock-register-interface has grown to feature traits for defining custom registers and using a well-established API to access these, manipulate fields, etc. Examples such as the RISC-V CSR interface included with Tock show that tock-registers has utility, even without using the included register types. This feature allows a user of tock-registers to disable all of the built-in register types, but still use the crate's API. Furthermore, it is possible to design generic types which take references to some opaque tock-registers type, without including such types in the crate. To demonstrate that this feature indeed works as intended, the RISC-V CSR crate is changed to depend on a build of tock-registers with this feature disabled. If no register types are built, this enforces that the library may otherwise not use any unsafe code. By default, the register types will still be included with the crate. Signed-off-by: Leon Schuermann <leon@is.currently.online>
1 parent f979973 commit 107fb22

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

libraries/tock-register-interface/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ edition = "2018"
1515
travis-ci = { repository = "tock/tock", branch = "master" }
1616

1717
[features]
18+
default = [ "register_types" ]
19+
20+
# Include actual register types (except LocalRegisterCopy). Disabling
21+
# the feature makes this an interface-only library and removes all
22+
# usage of unsafe code
23+
register_types = []
24+
1825
no_std_unit_tests = []

libraries/tock-register-interface/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
#![feature(const_fn_trait_bound)]
66
#![no_std]
77

8+
// If we don't build any actual register types, we don't need unsafe
9+
// code in this crate
10+
#![cfg_attr(not(feature = "register_types"), forbid(unsafe_code))]
11+
812
pub mod fields;
913
pub mod interfaces;
1014
pub mod macros;
15+
16+
#[cfg(feature = "register_types")]
1117
pub mod registers;
1218

1319
mod local_register;

0 commit comments

Comments
 (0)