Skip to content

Commit

Permalink
Small build system updates, make RIOT_USEMODULE optional
Browse files Browse the repository at this point in the history
Merges: #39
  • Loading branch information
chrysn authored Feb 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e37ebbf + 17020f4 commit 8ff2d35
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ riot-rs-core = { version = "< 0.2.0", optional = true }

[build-dependencies]
bindgen = "^0.64"
shlex = "^1"
shlex = "^1.3"
serde_json = "1"
serde = { version = "1", features = [ "derive" ] }
regex = "1"
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -60,11 +60,17 @@ and efforts are made to not make breaking changes even while in the 0.x phase.
Note that as it passes on RIOT internals,
any of the SemVer guarantees only hold when built on the *same* RIOT --
once the underlying C code is changed, all bets are off.
Users of `riot-rs` can introspect its markers (see `build.rs`)
to influence which symbols to use.
Users of `riot-rs` can introspect the `DEP_RIOT_SYS_...` variables
that are available to crates that set `links = "riot-sys"`
to affect the symbols those crates use.
Typical variables to inspect are `DEP_RIOT_SYS_BINDGEN_OUTPUT_FILE`
(to determine whether a symbol is imported in the first place, eg. when RIOT renames something)
and `DEP_RIOT_SYS_CFLAGS` which includes the enabled modules.

#### Markers

**Deprecated, see below**.

Some decisions of downstream crates need to depend on whether some feature is around in
RIOT. For many things that's best checked on module level, but some minor items have no
module to mark the feature, and checking for versions by numers is not fine-grained enough,
14 changes: 6 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -119,16 +119,17 @@ fn main() {
cc = consensus_cc
.expect("Entries are present in compile_commands.json")
.to_string();
cflags = shlex::join(consensus_cflag_groups.unwrap().iter().flatten().map(|s| *s));
cflags = shlex::try_join(consensus_cflag_groups.unwrap().iter().flatten().map(|s| *s))
.expect("Input is not expected to contain NUL characters");

let usemodule = {
#[cfg(not(feature = "riot-rs"))]
{
println!("cargo:rerun-if-env-changed=RIOT_USEMODULE");
env::var("RIOT_USEMODULE").expect(&format!(
"RIOT_USEMODULE is required when {} is given",
&compile_commands_json,
))
// We tolerate the absence. Older versions of riot-wrappers would then fail to
// enable modules, but newer versions just work without it (and would need a dummy
// variable passed in otherwise). On the long run, this is going away anyway.
env::var("RIOT_USEMODULE").unwrap_or_default()
}
#[cfg(feature = "riot-rs")]
{
@@ -642,8 +643,6 @@ fn main() {
/// This is equivalent to not having the marker in the first place, except that their
/// presence serves as a reminder to not reuse that marker name.
Never,
/// A marker that is set if the given string is found in the bindgen output.
InCode(&'static str),
/// A marker that is set if its name is found in the bindgen output. Shorthand for
/// Text(name).
NameInCode,
@@ -673,7 +672,6 @@ fn main() {
];
for (needle, name) in markers {
let found = match needle {
InCode(s) => bindgen_output.contains(s),
NameInCode => bindgen_output.contains(name),
Always => true,
Never => false,
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -56,11 +56,17 @@
//! Note that as it passes on RIOT internals,
//! any of the SemVer guarantees only hold when built on the *same* RIOT --
//! once the underlying C code is changed, all bets are off.
//! Users of `riot-rs` can introspect its markers (see `build.rs`)
//! to influence which symbols to use.
//! Users of `riot-rs` can introspect the `DEP_RIOT_SYS_...` variables
//! that are available to crates that set `links = "riot-sys"`
//! to affect the symbols those crates use.
//! Typical variables to inspect are `DEP_RIOT_SYS_BINDGEN_OUTPUT_FILE`
//! (to determine whether a symbol is imported in the first place, eg. when RIOT renames something)
//! and `DEP_RIOT_SYS_CFLAGS` which includes the enabled modules.
//!
//! ### Markers
//!
//! **Deprecated, see below**.
//!
//! Some decisions of downstream crates need to depend on whether some feature is around in
//! RIOT. For many things that's best checked on module level, but some minor items have no
//! module to mark the feature, and checking for versions by numers is not fine-grained enough,

0 comments on commit 8ff2d35

Please sign in to comment.