{"id":20841153,"url":"https://github.com/zephyrproject-rtos/zephyr-lang-rust","last_synced_at":"2025-04-06T09:06:16.047Z","repository":{"id":256630884,"uuid":"855957168","full_name":"zephyrproject-rtos/zephyr-lang-rust","owner":"zephyrproject-rtos","description":"Support for Zephyr applications written in Rust","archived":false,"fork":false,"pushed_at":"2025-03-28T15:51:17.000Z","size":530,"stargazers_count":117,"open_issues_count":17,"forks_count":16,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-30T08:12:14.833Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zephyrproject-rtos.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-11T18:29:43.000Z","updated_at":"2025-03-27T18:28:51.000Z","dependencies_parsed_at":"2024-10-28T16:19:44.741Z","dependency_job_id":"a496119e-f380-41e5-9350-f7967a5d18b1","html_url":"https://github.com/zephyrproject-rtos/zephyr-lang-rust","commit_stats":null,"previous_names":["d3zd3z/zephyr-lang-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephyrproject-rtos%2Fzephyr-lang-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephyrproject-rtos%2Fzephyr-lang-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephyrproject-rtos%2Fzephyr-lang-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephyrproject-rtos%2Fzephyr-lang-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zephyrproject-rtos","download_url":"https://codeload.github.com/zephyrproject-rtos/zephyr-lang-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457799,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:19:00.609Z","updated_at":"2025-04-06T09:06:16.021Z","avatar_url":"https://github.com/zephyrproject-rtos.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":".. _language_rust:\n\nRust Language Support\n#####################\n\nRust is a systems programming language focused on safety, speed, and concurrency. Designed to\nprevent common programming errors such as null pointer dereferencing and buffer overflows, Rust\nemphasizes memory safety without sacrificing performance. Its powerful type system and ownership\nmodel ensure thread-safe programming, making it an ideal choice for developing reliable and\nefficient low-level code.  Rust's expressive syntax and modern features make it a robust alternative\nfor developers working on embedded systems, operating systems, and other performance-critical\napplications.\n\n.. toctree::\n   :maxdepth: 2\n\n   docs/bindings.rst\n\nEnabling Rust Support\n*********************\n\nCurrently, Zephyr supports applications written in Rust and C.  The enable Rust support, you must\nselect the :kconfig:option:`CONFIG_RUST` in the application configuration file.\n\nThe rust toolchain is separate from the rest of the Zephyr SDK.   It is recommended to use the\n`rustup`_ tool to install the rust toolchain.  In addition to the base compiler, you will need to\ninstall core libraries for the target(s) you wish to compile on.  It is easiest to determine what\nneeds to be installed by trying a build.  The diagnostics from the rust compilation will indicate\nthe rust command needed to install the appropriate target support:\n\n.. _rustup: https://rustup.rs/\n\n.. code-block:: console\n\n   $ west build ...\n   ...\n   error[E0463]: can't find crate for `core`\n     |\n   = note: the `thumbv7m-none-eabi` target may not be installed\n   = help: consider downloading the target with `rustup target add thumbv7m-none-eabi`\n\nIn this case, the given ``rustup`` command will install the needed target support.  The target\nneeded will depend on both the board selected, as well as certain configuration choices (such as\nwhether floating point is enabled).\n\nWriting a Rust Application\n**************************\n\nSee :zephyr_file:`samples/rust` for examples of an application.\n\nCMake files\n-----------\n\nThe application should contain a :file:`CMakeLists.txt`, similar to the following:\n\n.. code-block:: cmake\n\n   cmake_minimum_required(VERSION 3.20.0)\n\n   find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})\n   project(hello_world)\n\n   rust_cargo_application()\n\nCargo files\n-----------\n\nRust applications are built with Cargo.  The Zephyr build system will configure and invoke cargo in\nyour application directory, with options set so that it can find the Zephyr support libraries, and\nthat the output will be contained within the Zephyr build directory.\n\nThe :file:`Cargo.toml` will need to have a ``[lib]`` section that sets ``crate-type =\n[\"staticlib\"]``, and will need to include ``zephyr = \"0.1.0\"`` as a dependency.  You can use\ncrates.io and the Crate ecosystem to include any other dependencies you need.  Just make sure that\nyou use crates that support building with no-std.\n\nApplication\n-----------\n\nThe application source itself should live in :file:`src/lib.rs`.  A few things are needed.  A minimal\nfile would be:\n\n.. code-block:: rust\n\n   #![no_std]\n\n   extern crate zephyr;\n\n   #[no_mangle]\n   extern \"C\" fn rust_main() {\n   }\n\nThe ``no_std`` declaration is needed to prevent the code from referencing the ``std`` library.  The\nextern reference will cause the zephyr crate to be brought in, even if nothing from it is used.\nPractically, any meaningful Rust application on Zephyr will use something from this crate, and this\nline is not necessary.  Lastly, the main declaration exports the main symbol so that it can be\ncalled by C code.  The build ``rust_cargo_application()`` cmake function will include a small C file\nthat will call into this from the C main function.\n\nZephyr Functionality\n********************\n\nThe bindings to Zephyr for Rust are under development, and are currently rather minimalistic.\n\nBool Kconfig settings\n---------------------\n\nBoolean Kconfig settings can be used from within Rust code.  Due to design constraints by the Rust\nlanguage, settings that affect compilation must be determined before the build is made.  In order to\nuse this in your application, you will need to use the ``zephyr-build`` crate, provided, to make\nthese symbols available.\n\nTo your ``Cargo.toml`` file, add the following:\n\n.. code-block:: toml\n\n   [build-dependencies]\n   zephyr-build = \"0.1.0\"\n\nThen, you will need a ``build.rs`` file to call the support function.  The following will work:\n\n.. code-block:: rust\n\n   fn main() {\n       zephyr_build::export_bool_kconfig();\n   }\n\nAt this point, it will be possible to use the ``cfg`` directive in Rust on boolean Kconfig values.\nFor example:\n\n.. code-block:: rust\n\n   #[cfg(CONFIG_SCHED_DUMB)]\n   one_declaration;\n\n   #[cfg(not(CONFIG_SCHED_DUMB))]\n   other_declaration;\n\nOther Kconfig settings\n----------------------\n\nAll bool, numeric and string Kconfig settings are accessible from the ``zephyr::kconfig`` module.\nFor example:\n\n.. code-block:: rust\n\n   let ceiling = zephyr::kconfig::CONFIG_PRIORITY_CEILING - 1;\n\nOther functionality\n-------------------\n\nAccess to other functionality within zephyr is a work-in-progress, and this document will be updated\nas that is done.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephyrproject-rtos%2Fzephyr-lang-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzephyrproject-rtos%2Fzephyr-lang-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephyrproject-rtos%2Fzephyr-lang-rust/lists"}