1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_rust: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker======= 4*61c4878aSAndroid Build Coastguard Workerpw_rust 5*61c4878aSAndroid Build Coastguard Worker======= 6*61c4878aSAndroid Build Coastguard WorkerRust support in pigweed is **highly** experimental. Currently functionality 7*61c4878aSAndroid Build Coastguard Workeris split between Bazel and GN support. 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard Worker----- 10*61c4878aSAndroid Build Coastguard WorkerBazel 11*61c4878aSAndroid Build Coastguard Worker----- 12*61c4878aSAndroid Build Coastguard WorkerBazel support is based on `rules_rust <https://github.com/bazelbuild/rules_rust>`_ 13*61c4878aSAndroid Build Coastguard Workerand supports a rich set of targets for both host and target builds. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard WorkerBuilding and Running the Embedded Examples 16*61c4878aSAndroid Build Coastguard Worker========================================== 17*61c4878aSAndroid Build Coastguard WorkerThe examples can be built for both the ``lm3s6965evb`` and ``microbit`` 18*61c4878aSAndroid Build Coastguard WorkerQEMU machines. The examples can be built and run using the following commands 19*61c4878aSAndroid Build Coastguard Workerwhere ``PLATFORM`` is one of ``lm3s6965evb`` or ``microbit``. 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Workerembedded_hello 22*61c4878aSAndroid Build Coastguard Worker-------------- 23*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 24*61c4878aSAndroid Build Coastguard Worker 25*61c4878aSAndroid Build Coastguard Worker $ bazel build //pw_rust/examples/embedded_hello:hello \ 26*61c4878aSAndroid Build Coastguard Worker --platforms //pw_build/platforms:${PLATFORM} 27*61c4878aSAndroid Build Coastguard Worker 28*61c4878aSAndroid Build Coastguard Worker $ qemu-system-arm \ 29*61c4878aSAndroid Build Coastguard Worker -machine ${PLATFORM} \ 30*61c4878aSAndroid Build Coastguard Worker -nographic \ 31*61c4878aSAndroid Build Coastguard Worker -semihosting-config enable=on,target=native \ 32*61c4878aSAndroid Build Coastguard Worker -kernel ./bazel-bin/pw_rust/examples/embedded_hello/hello 33*61c4878aSAndroid Build Coastguard Worker Hello, Pigweed! 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard Workertokenized_logging 37*61c4878aSAndroid Build Coastguard Worker----------------- 38*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 39*61c4878aSAndroid Build Coastguard Worker 40*61c4878aSAndroid Build Coastguard Worker $ bazel build //pw_rust/examples/tokenized_logging:tokenized_logging \ 41*61c4878aSAndroid Build Coastguard Worker --//pw_log/rust:pw_log_backend=//pw_rust/examples/tokenized_logging:pw_log_backend\ 42*61c4878aSAndroid Build Coastguard Worker --platforms //pw_build/platforms:${PLATFORM} 43*61c4878aSAndroid Build Coastguard Worker 44*61c4878aSAndroid Build Coastguard Worker $ qemu-system-arm \ 45*61c4878aSAndroid Build Coastguard Worker -machine ${PLATFORM} \ 46*61c4878aSAndroid Build Coastguard Worker -nographic \ 47*61c4878aSAndroid Build Coastguard Worker -semihosting-config enable=on,target=native \ 48*61c4878aSAndroid Build Coastguard Worker -kernel ./bazel-bin/pw_rust/examples/tokenized_logging/tokenized_logging \ 49*61c4878aSAndroid Build Coastguard Worker | python -m pw_tokenizer.detokenize \ 50*61c4878aSAndroid Build Coastguard Worker base64 \ 51*61c4878aSAndroid Build Coastguard Worker ./bazel-bin/pw_rust/examples/tokenized_logging/tokenized_logging 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard Worker-- 54*61c4878aSAndroid Build Coastguard WorkerGN 55*61c4878aSAndroid Build Coastguard Worker-- 56*61c4878aSAndroid Build Coastguard WorkerIn GN, currently only building a single host binary using the standard 57*61c4878aSAndroid Build Coastguard Workerlibraries is supported. Windows builds are currently unsupported. 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard WorkerBuilding 60*61c4878aSAndroid Build Coastguard Worker======== 61*61c4878aSAndroid Build Coastguard WorkerTo build the sample rust targets, you need to enable 62*61c4878aSAndroid Build Coastguard Worker``pw_rust_ENABLE_EXPERIMENTAL_BUILD``: 63*61c4878aSAndroid Build Coastguard Worker 64*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker $ gn gen out --args="pw_rust_ENABLE_EXPERIMENTAL_BUILD=true" 67*61c4878aSAndroid Build Coastguard Worker 68*61c4878aSAndroid Build Coastguard WorkerOnce that is set, you can build and run the ``hello`` example: 69*61c4878aSAndroid Build Coastguard Worker 70*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 71*61c4878aSAndroid Build Coastguard Worker 72*61c4878aSAndroid Build Coastguard Worker $ ninja -C out host_clang_debug/obj/pw_rust/examples/basic_executable/bin/hello 73*61c4878aSAndroid Build Coastguard Worker $ ./out/host_clang_debug/obj/pw_rust/examples/basic_executable/bin/hello 74*61c4878aSAndroid Build Coastguard Worker Hello, Pigweed! 75*61c4878aSAndroid Build Coastguard Worker 76*61c4878aSAndroid Build Coastguard Workerno_std 77*61c4878aSAndroid Build Coastguard Worker------ 78*61c4878aSAndroid Build Coastguard WorkerSet ``pw_rust_USE_STD = false`` in the toolchain configuration, if the target 79*61c4878aSAndroid Build Coastguard Workertoolchain does not support ``std``. 80*61c4878aSAndroid Build Coastguard Worker 81*61c4878aSAndroid Build Coastguard Worker``no_std`` toolchain builds target 82*61c4878aSAndroid Build Coastguard Worker``//pw_rust/examples/basic_executable/bin/hello_pw_log``. It also prints 83*61c4878aSAndroid Build Coastguard Worker"Hello, Pigweed!", but links and uses ``pw_log`` C++ backend. 84*61c4878aSAndroid Build Coastguard Worker 85*61c4878aSAndroid Build Coastguard Worker------------------ 86*61c4878aSAndroid Build Coastguard WorkerThird Party Crates 87*61c4878aSAndroid Build Coastguard Worker------------------ 88*61c4878aSAndroid Build Coastguard WorkerThrid party crates are vendored in the 89*61c4878aSAndroid Build Coastguard Worker`third_party/rust_crates <https://pigweed.googlesource.com/third_party/rust_crates>`_ 90*61c4878aSAndroid Build Coastguard Workerrespository. Currently referencing these is only supported through the bazel 91*61c4878aSAndroid Build Coastguard Workerbuild. 92