diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a3c494..d14cd0b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - zephyr_version: [3.4.0, 2.7.3, 2.6.0, 2.5.0, 2.4.0, 2.3.0] + zephyr_version: [3.6.0, 3.5.0, 3.4.0, 2.7.3, 2.3.0] board: [qemu_x86, qemu_cortex_m3, qemu_cortex_r5, nucleo_l552ze_q, native_posix, qemu_riscv32, qemu_riscv64] test: [samples/rust-app, samples/no_std, samples/serial] exclude: @@ -38,6 +38,10 @@ jobs: zephyr_version: 2.7.3 - board: native_posix test: samples/serial + - board: native_posix + zephyr_version: 3.5.0 + - board: native_posix + zephyr_version: 3.6.0 include: - fails: false - run: false diff --git a/Kconfig b/Kconfig index 39d1671..68ec6f4 100644 --- a/Kconfig +++ b/Kconfig @@ -2,6 +2,7 @@ menuconfig RUST bool "Rust" select THREAD_CUSTOM_DATA select CPLUSPLUS + select PICOLIBC_USE_MODULE if PICOLIBC help Rust language support. diff --git a/README.rst b/README.rst index ad6e6a7..8d56c0b 100644 --- a/README.rst +++ b/README.rst @@ -10,10 +10,15 @@ Zephyr app. Version Compatibility ===================== -**Zephyr**: v2.3, v2.4, v2.5, v2.6, v2.7, v3.4 +**Zephyr**: v2.3, v2.7.3, v3.4, v3.5, v3.6 **Rust**: exactly 1.68.0 +Please use one of the above Zephyr releases before reporting issues! At the +time you are reading this, Zephyr's main branch will likely not work, though it +is usually one 1-2 minor changes to support a new release. The project aims to +support everything from 2.3 to the present. + Features ======== diff --git a/ci/build-all.sh b/ci/build-all.sh index 8a28c90..b08072b 100755 --- a/ci/build-all.sh +++ b/ci/build-all.sh @@ -2,7 +2,7 @@ #rm -rf log -ZEPHYR_VERSIONS="3.4.0 2.7.3 2.6.0 2.5.0 2.4.0 2.3.0" +ZEPHYR_VERSIONS="3.6.0 3.5.0 3.4.0 2.7.3 2.3.0" #parallel \ # -j8 \ diff --git a/rust-smem.c b/rust-smem.c index a8fb7c4..13cbc08 100644 --- a/rust-smem.c +++ b/rust-smem.c @@ -37,13 +37,18 @@ struct k_heap Z_GENERIC_SECTION(RUST_STD_SECTION) rust_std_mem_pool; #if defined(CONFIG_USERSPACE) || defined(CONFIG_RUST_ALLOC_POOL) /* Harmless API difference that generates a warning */ -#if ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(2, 4, 0) +#if ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(3, 4, 0) +static int rust_std_init(void) +{ +#elif ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(2, 4, 0) static int rust_std_init(const struct device *arg) +{ + ARG_UNUSED(arg); #else static int rust_std_init(struct device *arg) -#endif /* ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(2, 4, 0) */ { ARG_UNUSED(arg); +#endif /* ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(2, 4, 0) */ #ifdef CONFIG_USERSPACE struct k_mem_partition *rust_std_parts[] = { &rust_std_partition }; diff --git a/rust/zephyr-core/build.rs b/rust/zephyr-core/build.rs index 750c4ac..fbf2bb1 100644 --- a/rust/zephyr-core/build.rs +++ b/rust/zephyr-core/build.rs @@ -5,16 +5,18 @@ fn main() { let kernel_version = u32::from_str_radix(&kernel_version_str_trimmed, 16) .expect("ZEPHYR_KERNEL_VERSION_NUM must be an integer"); - if kernel_version >= 0x3_00_00 { - println!("cargo:rustc-cfg=zephyr300"); - } if kernel_version >= 0x2_05_00 { println!("cargo:rustc-cfg=zephyr250"); } - if kernel_version >= 0x2_07_00 { println!("cargo:rustc-cfg=zephyr270"); } + if kernel_version >= 0x3_00_00 { + println!("cargo:rustc-cfg=zephyr300"); + } + if kernel_version >= 0x3_05_00 { + println!("cargo:rustc-cfg=zephyr350"); + } if std::env::var("CONFIG_USERSPACE").expect("CONFIG_USERSPACE must be set") == "y" { println!("cargo:rustc-cfg=usermode"); diff --git a/rust/zephyr-core/src/thread.rs b/rust/zephyr-core/src/thread.rs index 80ee46a..e7a99f9 100644 --- a/rust/zephyr-core/src/thread.rs +++ b/rust/zephyr-core/src/thread.rs @@ -32,13 +32,15 @@ macro_rules! trait_impl { unsafe { zephyr_sys::syscalls::$context::k_wakeup(thread.tid()) } } - #[cfg(not(any(zephyr270, zephyr300)))] + /* If less than 2.7, always use the k_current_get syscall */ + #[cfg(not(zephyr270))] fn k_current_get() -> crate::thread::ThreadId { ThreadId(unsafe { NonNull::new_unchecked(zephyr_sys::syscalls::$context::k_current_get()) }) } + /* 2.7 and above with TLS allows pulling from TLS */ #[cfg(all(zephyr270, tls))] fn k_current_get() -> crate::thread::ThreadId { extern "C" { @@ -50,13 +52,22 @@ macro_rules! trait_impl { }) } - #[cfg(any(zephyr300, all(zephyr270, not(tls))))] + /* 2.7 without TLS renames the syscall to z_current_get */ + #[cfg(all(zephyr270, not(zephyr350), not(tls)))] fn k_current_get() -> crate::thread::ThreadId { ThreadId(unsafe { NonNull::new_unchecked(zephyr_sys::syscalls::$context::z_current_get()) }) } + /* 3.5 renames the syscall again to k_sched_current_thread_query */ + #[cfg(all(zephyr350, not(tls)))] + fn k_current_get() -> crate::thread::ThreadId { + ThreadId(unsafe { + NonNull::new_unchecked(zephyr_sys::syscalls::$context::k_sched_current_thread_query()) + }) + } + fn k_object_access_grant(kobj: &K, thread: ThreadId) { if !zephyr_sys::raw::RUST_CONFIG_USERSPACE { // Avoid unnecessary call to stub function diff --git a/scripts/gen_syscalls.py b/scripts/gen_syscalls.py index 90c9dea..22b685b 100755 --- a/scripts/gen_syscalls.py +++ b/scripts/gen_syscalls.py @@ -147,7 +147,7 @@ def main(): whitelist = set(["kernel.h", "kobject.h", "device.h", "uart.h", "mutex.h", "errno_private.h", "eeprom.h", "time.h"]) includes = ["kernel.h", "device.h", "drivers/uart.h", "sys/mutex.h", "sys/errno_private.h", "drivers/eeprom.h", "posix/time.h"] - for match_group, fn in syscalls: + for match_group, fn in [i[:2] for i in syscalls]: if fn not in whitelist: continue include = "syscalls/%s" % fn