From 68d1750c12a2000524223dd432826869b17533b5 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 29 Jan 2025 10:50:27 +0800 Subject: [PATCH] docs: Rename hello_rust to rust/baremetal to reflect the actual codebase Summary: - The `hello_rust` example has been moved to `rust/baremetal` to better reflect its purpose as a bare-metal Rust application. - The move also helps in organizing the Rust examples more clearly, separating them into categories based on their environment (bare-metal vs. non-bare-metal). - A new directory structure has been created under `rust/baremetal`, and the `index.rst` file has been updated to describe the `baremetal` example in detail. - The top-level `rust/index.rst` file has been created to include the new `rust/baremetal` directory in the toctree. Impact: - The new file structure and documentation improvements will help new contributors and users understand the purpose and setup of the example more easily. - This change aligns the documentation with the actual codebase, enhancing the overall maintainability and clarity of the project. Signed-off-by: Huang Qi --- .../applications/examples/hello_rust/index.rst | 5 ----- .../examples/rust/baremetal/index.rst | 16 ++++++++++++++++ .../applications/examples/rust/index.rst | 11 +++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) delete mode 100644 Documentation/applications/examples/hello_rust/index.rst create mode 100644 Documentation/applications/examples/rust/baremetal/index.rst create mode 100644 Documentation/applications/examples/rust/index.rst diff --git a/Documentation/applications/examples/hello_rust/index.rst b/Documentation/applications/examples/hello_rust/index.rst deleted file mode 100644 index 636b2001a2..0000000000 --- a/Documentation/applications/examples/hello_rust/index.rst +++ /dev/null @@ -1,5 +0,0 @@ -================================== -``hello_rust`` Hello World in Rust -================================== - -Hello World in Rust. diff --git a/Documentation/applications/examples/rust/baremetal/index.rst b/Documentation/applications/examples/rust/baremetal/index.rst new file mode 100644 index 0000000000..2745b2329c --- /dev/null +++ b/Documentation/applications/examples/rust/baremetal/index.rst @@ -0,0 +1,16 @@ +================================== +`baremetal` Hello World in Rust +================================== + +This example demonstrates how to create a simple "Hello World" program in Rust for a bare-metal environment. The program is compiled using the `rustc` compiler directly, without relying on any operating system or standard library. + +The key aspects of this example include: + +- **No Standard Library**: The program uses the `#![no_std]` attribute, which means it does not link against the standard library. This is essential for bare-metal programming where the standard library is not available. +- **No Main Function**: The program uses the `#![no_main]` attribute, which indicates that the program does not have a standard `main` function. Instead, it defines a custom entry point. +- **Panic Handler**: A custom panic handler is defined using the `#[panic_handler]` attribute. This handler is called when a panic occurs, and in this case, it enters an infinite loop to halt the program. +- **C Interoperability**: The program uses the `extern "C"` block to declare the `printf` function from the C standard library. This allows the Rust program to call C functions directly. +- **Entry Point**: The `hello_rust_main` function is the entry point of the program. It is marked with `#[no_mangle]` to prevent the Rust compiler from mangling its name, making it callable from C. +- **Printing**: The program uses the `printf` function to print "Hello, Rust!!" to the console. The `printf` function is called using the `unsafe` block because it involves calling a C function. + +This example is a great starting point for understanding how to write and compile Rust programs for bare-metal environments, where you have full control over the hardware and no operating system overhead. diff --git a/Documentation/applications/examples/rust/index.rst b/Documentation/applications/examples/rust/index.rst new file mode 100644 index 0000000000..7fd551f367 --- /dev/null +++ b/Documentation/applications/examples/rust/index.rst @@ -0,0 +1,11 @@ +Rust Examples +============= + +This directory contains examples of Rust applications. + +.. toctree:: + :glob: + :maxdepth: 1 + :titlesonly: + + */index*