Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zephyr 3.6 support #52

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ menuconfig RUST
bool "Rust"
select THREAD_CUSTOM_DATA
select CPLUSPLUS
select PICOLIBC_USE_MODULE if PICOLIBC
help
Rust language support.

Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========

Expand Down
2 changes: 1 addition & 1 deletion ci/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 7 additions & 2 deletions rust-smem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
10 changes: 6 additions & 4 deletions rust/zephyr-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 13 additions & 2 deletions rust/zephyr-core/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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<K: KObj>(kobj: &K, thread: ThreadId) {
if !zephyr_sys::raw::RUST_CONFIG_USERSPACE {
// Avoid unnecessary call to stub function
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_syscalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading