Skip to content

Commit

Permalink
Merge branch 'main' into init-by-number
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Dec 2, 2023
2 parents ddf9265 + 9d6851e commit 6501495
Show file tree
Hide file tree
Showing 38 changed files with 689 additions and 288 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/buildtest.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/rustfmt.yml

This file was deleted.

152 changes: 152 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Ideally this should be replaced with a call out to Murdock; until that is
# practical, building representative examples.

name: test

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

jobs:
quick-examples:
runs-on: ubuntu-latest
container: riot/riotbuild
# Best would be "continue until there are errors from different examples *and* different boards"
continue-on-error: true
strategy:
matrix:
example: [examples/rust-hello-world, examples/rust-gcoap, tests/rust_minimal]
board: [native, sltb001a, samr21-xpro, stk3700]
steps:
# common steps start here
- name: Check out riot-wrappers
uses: actions/checkout@v3
- name: Check out RIOT
uses: actions/checkout@v3
with:
repository: RIOT-OS/RIOT
path: RIOT
- name: Patch .cargo/config.toml to use current checkout
run: |
set -x
cd RIOT
rm -f .cargo/config.toml
mkdir -p .cargo # Keep working if RIOT ever decides it doesn't need overrides any more
echo '[patch.crates-io]' >> .cargo/config.toml
echo 'riot-wrappers = { path = "../", version = "*" }' >> .cargo/config.toml
echo 'riot-sys = { git = "https://github.com/RIOT-OS/rust-riot-sys" }' >> .cargo/config.toml
- name: Pull cargo updates
# No sense in running this in parallel -- this will download the index
# and all relevant crates once, and after that, just make some notes in Cargo.lock
run: |
set -x
for MANIF in $(find RIOT -name Cargo.toml)
do
echo "::group::Updating ${MANIF}"
cargo update -p riot-sys -p riot-wrappers --aggressive --manifest-path $MANIF
cargo fetch --manifest-path $MANIF
cargo tree --manifest-path $MANIF
echo "::endgroup::"
done
# common steps end here

- name: Build the example
run: |
make all BOARD=${{ matrix.board }} -C RIOT/${{ matrix.example }}
most-tests:
runs-on: ubuntu-latest
container: riot/riotbuild
strategy:
matrix:
board: [native, sltb001a, samr21-xpro, stk3700]
steps:
# common steps start here
- name: Check out riot-wrappers
uses: actions/checkout@v3
- name: Check out RIOT
uses: actions/checkout@v3
with:
repository: RIOT-OS/RIOT
path: RIOT
- name: Patch .cargo/config.toml to use current checkout
run: |
set -x
cd RIOT
rm -f .cargo/config.toml
mkdir -p .cargo # Keep working if RIOT ever decides it doesn't need overrides any more
echo '[patch.crates-io]' >> .cargo/config.toml
echo 'riot-wrappers = { path = "../", version = "*" }' >> .cargo/config.toml
echo 'riot-sys = { git = "https://github.com/RIOT-OS/rust-riot-sys" }' >> .cargo/config.toml
- name: Pull cargo updates
# No sense in running this in parallel -- this will download the index
# and all relevant crates once, and after that, just make some notes in Cargo.lock
run: |
set -x
for MANIF in $(find RIOT -name Cargo.toml)
do
echo "::group::Updating ${MANIF}"
cargo update -p riot-sys -p riot-wrappers --aggressive --manifest-path $MANIF
cargo fetch --manifest-path $MANIF
cargo tree --manifest-path $MANIF
echo "::endgroup::"
done
# common steps end here

- name: Build and run tests
run: |
set -x
export RIOTBASE=$(pwd)/RIOT
# Removing tests/pkg/lvgl due to https://github.com/RIOT-OS/RIOT/issues/20110
#
# Skipping examples because ... not sure, did it that way before
# https://github.com/RIOT-OS/rust-riot-wrappers/pull/68, and examples
# are built extra
#
# Skipping peripheral and driver tests because we don't implement those
# with wrappers; the valuable ones are those like saul where there are
# modules that use Rust.
DIRS=$(make --quiet -C ${RIOTBASE} -f makefiles/app_dirs.inc.mk info-applications | grep -v tests/pkg/lvgl |grep -v examples |grep -v periph |grep -v driver)
for D in ${DIRS}; do
echo "::group::Building ${D}"
cd ${D}
if BOARDS=${{ matrix.board }} make info-boards-supported | grep -q .
then
# RIOTNOLINK is a workaround for boards with insufficient memory
# showing as supported but still being known not to be buildable.
# Other CI works around by having RIOT_CI_BUILD set RIOTNOLINK if
# the board is known to not have enough memory from
# BOARD_INSUFFICIENT_MEMORY, but that information is not piped out.
#
# Until a better workaround is found, no boards are linked, and if
# a board does exceed its memory due to a Rust change, that will
# only be spotted when the Rust crate is updated in RIOT and a full
# test with the precise criterion is run.
BOARD=${{ matrix.board }} make all RIOTNOLINK=1
if [ "native" = "${{ matrix.board }}" ] && make test/available BOARD=native
then
echo "::group::Testing ${D}"
make all test BOARD=native
echo "::endgroup::"
fi
BOARD=${{ matrix.board }} make clean
else
echo "Board is not supported for this test, skipping."
fi
cd -
echo "::endgroup::"
done
echo "::echo ::off"
rustfmt:
runs-on: ubuntu-latest
container: rustlang/rust:nightly
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run cargo-fmt
run: cargo fmt --check
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bare-metal = "1"
cstr = "^0.2.11"

heapless = "^0.7"
rand_core_06 = { package = "rand_core", version = "^0.6" }

# For nimble UUID parsing and some debug implementations
hex = { version = "^0.4.3", default-features = false }
Expand All @@ -48,6 +49,7 @@ pin-utils = "0.1"

[build-dependencies]
shlex = "0.1.1"
syn = { version = "1.0.107", features = [ "parsing" ] }

[features]
default = []
Expand Down
38 changes: 32 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,38 @@ fn main() {
let bindgen_output = std::fs::read_to_string(bindgen_output_file)
.expect("Failed to read BINDGEN_OUTPUT_FILE");

// Whether or not the extra space is there depends on whether or not rustfmt is installed.
// FIXME: Find a better way to extract that information
if bindgen_output.contains("pub const CONFIG_AUTO_INIT_ENABLE_DEBUG: u32 = 1;")
|| bindgen_output.contains("pub const CONFIG_AUTO_INIT_ENABLE_DEBUG : u32 = 1 ;")
{
println!("cargo:rustc-cfg=marker_config_auto_init_enable_debug");
const BOOLEAN_FLAGS: &[&str] = &[
// This decides whether or not some fields are populated ... and unlike with other
// structs, the zeroed default is not a good solution here. (It'd kind of work, but
// it'd produce incorrect debug output).
"CONFIG_AUTO_INIT_ENABLE_DEBUG",
];

let parsed = syn::parse_file(&bindgen_output).expect("Failed to parse bindgen output");
for item in &parsed.items {
if let syn::Item::Const(const_) = item {
// It's the easiest way to get something we can `contains`...
let ident = const_.ident.to_string();
if BOOLEAN_FLAGS.contains(&ident.as_str()) {
if let syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Int(litint),
..
}) = &*const_.expr
{
let value: usize = litint
.base10_parse()
.expect("Identifier is integer literal but not parsable");
if value != 0 {
println!("cargo:rustc-cfg=marker_{}", ident.to_lowercase());
}
continue;
}
panic!(
"Found {} but it's not the literal const it was expected to be",
ident
);
}
}
}
} else {
println!("cargo:warning=Old riot-sys did not provide BINDGEN_OUTPUT_FILE, assuming it's an old RIOT version");
Expand Down
4 changes: 2 additions & 2 deletions src/auto_init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tools for declaring a function that is run during initialization
//!
//! The [auto_init!] macro is this module's main product.
//! The [`auto_init!`](super::auto_init!) macro is this module's main product.
/// Wrapper around [riot_sys::auto_init_module_t]
///
Expand All @@ -13,7 +13,7 @@ impl AutoInitModule {
/// Initializer for module auto-initialization
///
/// Do not call this directly: Its result must be placed in a static in a special section in
/// memory, which is handled by the [`auto_init!`] macro.
/// memory, which is handled by the [`auto_init!`](super::auto_init!) macro.
pub const fn new(
init_function: extern "C" fn(),
priority: u16,
Expand Down
2 changes: 1 addition & 1 deletion src/bluetil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum Error {

impl From<crate::error::NumericError> for Error {
fn from(e: crate::error::NumericError) -> Error {
match e.number as _ {
match e.number() as _ {
riot_sys::BLUETIL_AD_NOTFOUND => Error::NotFound,
riot_sys::BLUETIL_AD_NOMEM => Error::NoMem,
_ => panic!("Invalid bluetil error"),
Expand Down
10 changes: 2 additions & 8 deletions src/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ unsafe extern "C" fn link_encoder<H: WithLinkEncoder>(
let h: &H = unsafe { &*((*resource).context as *const _) };

let buf = buf as *mut u8; // cast away signedness of char
let mut buf = if buf.is_null() {
let buf = if buf.is_null() {
None
} else {
Some(core::slice::from_raw_parts_mut(buf, buf_len as _))
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<'a, H> SingleHandlerListener<'a, H>
where
H: 'a + Handler + WithLinkEncoder,
{
/// Like [`new()`], but utilizing that the handler is also [WithLinkEncoder] and can thus influence
/// Like [`Self::new()`], but utilizing that the handler is also [WithLinkEncoder] and can thus influence
/// what is reported when the default .well-known/core handler is queried.
pub fn new_with_link_encoder(
path: &'a core::ffi::CStr,
Expand Down Expand Up @@ -344,7 +344,6 @@ pub trait WithLinkEncoder {
}

use riot_sys::{
coap_get_total_hdr_len,
coap_opt_add_opaque,
coap_opt_add_uint,
coap_opt_get_next,
Expand Down Expand Up @@ -376,11 +375,6 @@ impl PacketBuffer {
}) as u8 // odd return type in C
}

/// Wrapper for coap_get_total_hdr_len
fn get_total_hdr_len(&self) -> usize {
(unsafe { coap_get_total_hdr_len(crate::inline_cast(self.pkt)) }) as usize
}

/// Wrapper for gcoap_resp_init
///
/// As it is used and wrapped here, this makes GCOAP_RESP_OPTIONS_BUF bytes unusable, but
Expand Down
3 changes: 2 additions & 1 deletion src/gnrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pub mod ipv6;

pub mod netapi;
pub mod netreg;
pub mod pktbuf;
#[deprecated(note = "moved to gnrc_pktbuf toplevel module")]
pub use crate::gnrc_pktbuf as pktbuf;

use riot_sys::{gnrc_netif_iter, gnrc_netif_t};

Expand Down
2 changes: 1 addition & 1 deletion src/gnrc/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl From<embedded_nal::Ipv6Addr> for Address {
#[cfg(feature = "with_embedded_nal")]
impl From<Address> for embedded_nal::Ipv6Addr {
fn from(addr: Address) -> Self {
Self::from(self.raw())
Self::from(*addr.raw())
}
}

Expand Down
Loading

0 comments on commit 6501495

Please sign in to comment.