Skip to content

Commit

Permalink
refactor(buildinfo): use a macro instead of a build script
Browse files Browse the repository at this point in the history
Use one of our own macros to read the board name from a shell
environment variable we provide from the build system.
This was previously done using a build script, leveraging the fact that
cargo exposed `--cfg` flags as environment variables, but using a macro
is simpler, faster, and safer.
  • Loading branch information
ROMemories authored and kaspar030 committed Apr 22, 2024
1 parent c3cfd08 commit 51b1109
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
- name: clippy
uses: clechasseur/rs-clippy-check@v3
with:
args: --verbose --locked --features no-boards -p riot-rs -p riot-rs-boards -p riot-rs-buildinfo -p riot-rs-chips -p riot-rs-debug -p riot-rs-embassy -p riot-rs-macros -p riot-rs-random -p riot-rs-rt -p riot-rs-utils
args: --verbose --locked --features no-boards -p riot-rs -p riot-rs-boards -p riot-rs-chips -p riot-rs-debug -p riot-rs-embassy -p riot-rs-macros -p riot-rs-random -p riot-rs-rt -p riot-rs-utils

- name: rustdoc
run: RUSTDOCFLAGS='-D warnings' cargo doc -p riot-rs --features no-boards,bench,threading,random,csprng,hwrng
Expand Down
6 changes: 1 addition & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ riot-rs-boards = { path = "src/riot-rs-boards", default-features = false }
riot-rs-debug = { path = "src/riot-rs-debug", default-features = false }
riot-rs-rt = { path = "src/riot-rs-rt" }
riot-rs-runqueue = { path = "src/riot-rs-runqueue" }
riot-rs-utils = { path = "src/riot-rs-utils", default-features = false }

const_panic = { version = "0.2.8", default_features = false }
document-features = "0.2.8"
Expand Down
1 change: 1 addition & 0 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contexts:
- >-
OPENOCD_ARGS="${OPENOCD_ARGS}"
SCRIPTS=${SCRIPTS}
CONFIG_BOARD=${builder}
CARGO_BUILD_TARGET=${RUSTC_TARGET}
${CARGO_TARGET_PREFIX}_RUNNER=${CARGO_RUNNER}
${CARGO_TARGET_PREFIX}_RUSTFLAGS="${RUSTFLAGS}"
Expand Down
8 changes: 0 additions & 8 deletions src/riot-rs-buildinfo/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions src/riot-rs-buildinfo/build.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/riot-rs-buildinfo/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ embassy-usb = { workspace = true, optional = true }
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
riot-rs-debug = { workspace = true }
riot-rs-rt = { path = "../riot-rs-rt" }
riot-rs-utils = { path = "../riot-rs-utils" }
riot-rs-random = { path = "../riot-rs-random", optional = true }
riot-rs-utils = { workspace = true }

heapless = "0.8.0"
once_cell = { version = "1.19.0", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion src/riot-rs-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cfg-if.workspace = true
linkme.workspace = true
riot-rs-debug.workspace = true
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
riot-rs-utils = { path = "../riot-rs-utils" }
riot-rs-utils = { workspace = true }
rtt-target = { version = "0.4.0", optional = true }

[target.'cfg(context = "cortex-m")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/riot-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ document-features = { workspace = true }
linkme = { workspace = true }
riot-rs-bench = { workspace = true, optional = true }
riot-rs-boards = { path = "../riot-rs-boards" }
riot-rs-buildinfo = { path = "../riot-rs-buildinfo" }
riot-rs-debug = { workspace = true }
riot-rs-embassy = { path = "../riot-rs-embassy" }
riot-rs-macros = { path = "../riot-rs-macros" }
riot-rs-random = { path = "../riot-rs-random", optional = true }
riot-rs-rt = { path = "../riot-rs-rt" }
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
riot-rs-utils = { workspace = true }
static_cell = { workspace = true }

[target.'cfg(context = "cortex-m")'.dependencies]
Expand Down
11 changes: 11 additions & 0 deletions src/riot-rs/src/buildinfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Exposes information about the build.

/// The board name.
///
/// The board name is read from the `CONFIG_BOARD` environment variable, which is expected to be
/// provided by the build system.
pub const BOARD: &str = riot_rs_utils::str_from_env_or!(
"CONFIG_BOARD",
"unknown",
"board name provided by the build system"
);
4 changes: 2 additions & 2 deletions src/riot-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#![no_std]
#![feature(doc_auto_cfg)]

pub mod buildinfo;

#[cfg(feature = "bench")]
#[doc(inline)]
pub use riot_rs_bench as bench;
#[doc(inline)]
pub use riot_rs_buildinfo as buildinfo;
#[doc(inline)]
pub use riot_rs_debug as debug;
#[doc(inline)]
pub use riot_rs_embassy as embassy;
Expand Down

0 comments on commit 51b1109

Please sign in to comment.