From bb89adb6fd7354abfe1d531be97ab2f5947fc5da Mon Sep 17 00:00:00 2001 From: David Brown Date: Tue, 15 Oct 2024 09:30:15 -0600 Subject: [PATCH] zephyr: docgen Add a small docgen crate. To help facilitate checking the docs, this project can be built, and then `cargo doc` run there. This includes the symlink for the config file, because that is needed in order for this to be able to build. Signed-off-by: David Brown --- docgen/.cargo/config.toml | 1 + docgen/.gitignore | 7 +++++++ docgen/CMakeLists.txt | 8 ++++++++ docgen/Cargo.toml | 16 ++++++++++++++++ docgen/prj.conf | 5 +++++ docgen/src/lib.rs | 16 ++++++++++++++++ 6 files changed, 53 insertions(+) create mode 120000 docgen/.cargo/config.toml create mode 100644 docgen/.gitignore create mode 100644 docgen/CMakeLists.txt create mode 100644 docgen/Cargo.toml create mode 100644 docgen/prj.conf create mode 100644 docgen/src/lib.rs diff --git a/docgen/.cargo/config.toml b/docgen/.cargo/config.toml new file mode 120000 index 00000000..f26aaf03 --- /dev/null +++ b/docgen/.cargo/config.toml @@ -0,0 +1 @@ +../../../../../zephyr/build/rust/sample-cargo-config.toml \ No newline at end of file diff --git a/docgen/.gitignore b/docgen/.gitignore new file mode 100644 index 00000000..80e243ad --- /dev/null +++ b/docgen/.gitignore @@ -0,0 +1,7 @@ +# In this case, we do want the symlink checked in. We'll assume we have the module in the standard +# module place. +# +# On Windows, this symlink will just get checked out as a regular file and will have to be replaced +# with a copy (or real symlinks enabled). But, this shouldn't affect CI runs of the documentation, +# which are done on Linux. +!.cargo/ diff --git a/docgen/CMakeLists.txt b/docgen/CMakeLists.txt new file mode 100644 index 00000000..3030520d --- /dev/null +++ b/docgen/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(hello_rust_world) +rust_cargo_application() diff --git a/docgen/Cargo.toml b/docgen/Cargo.toml new file mode 100644 index 00000000..5588550d --- /dev/null +++ b/docgen/Cargo.toml @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Linaro LTD +# SPDX-License-Identifier: Apache-2.0 + +[package] +# This must be rustapp for now. +name = "rustapp" +version = "3.7.0" +edition = "2021" +description = "A small application to generate documentation" +license = "Apache-2.0 or MIT" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +zephyr = "3.7.0" diff --git a/docgen/prj.conf b/docgen/prj.conf new file mode 100644 index 00000000..930445c6 --- /dev/null +++ b/docgen/prj.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Linaro LTD +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_RUST=y +CONFIG_RUST_ALLOC=y diff --git a/docgen/src/lib.rs b/docgen/src/lib.rs new file mode 100644 index 00000000..b29be52b --- /dev/null +++ b/docgen/src/lib.rs @@ -0,0 +1,16 @@ +// Copyright (c) 2024 Linaro LTD +// SPDX-License-Identifier: Apache-2.0 + +#![no_std] + +use zephyr::printkln; + +// Reference the Zephyr crate so that the panic handler gets used. This is only needed if no +// symbols from the crate are directly used. +extern crate zephyr; + +#[no_mangle] +extern "C" fn rust_main() { + printkln!("Hello world from Rust on {}", + zephyr::kconfig::CONFIG_BOARD); +}