• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _module-pw_rust:
2
3=======
4pw_rust
5=======
6Rust support in pigweed is **highly** experimental.  Currently functionality
7is split between Bazel and GN support.
8
9-----
10Bazel
11-----
12Bazel support is based on `rules_rust <https://github.com/bazelbuild/rules_rust>`_
13and supports a rich set of targets for both host and target builds.
14
15Building and Running the Embedded Example
16=========================================
17The ``embedded_hello`` example can be built for both the ``lm3s6965evb``
18and ``microbit`` QEMU machines.  The example can be built and run using
19the following commands where ``PLATFORM`` is one of ``lm3s6965evb`` or
20``microbit``.
21
22.. code:: bash
23
24   $ bazel build //pw_rust/examples/embedded_hello:hello \
25     --platforms //pw_build/platforms:${PLATFORM} \
26
27   $ qemu-system-arm \
28     -machine ${PLATFORM} \
29     -nographic \
30     -semihosting-config enable=on,target=native \
31     -kernel ./bazel-bin/pw_rust/examples/embedded_hello/hello
32   Hello, Pigweed!
33
34--
35GN
36--
37In GN, currently only building a single host binary using the standard
38libraries is supported.  Windows builds are currently unsupported.
39
40Building
41========
42To build the sample rust targets, you need to enable
43``pw_rust_ENABLE_EXPERIMENTAL_BUILD``:
44
45.. code:: bash
46
47   $ gn gen out --args="pw_rust_ENABLE_EXPERIMENTAL_BUILD=true"
48
49Once that is set, you can build and run the ``hello`` example:
50
51.. code:: bash
52
53   $ ninja -C out host_clang_debug/obj/pw_rust/example/bin/hello
54   $ ./out/host_clang_debug/obj/pw_rust/examples/host_executable/bin/hello
55   Hello, Pigweed!
56
57------------------
58Third Party Crates
59------------------
60Thrid party crates are vendored in the
61`third_party/rust_crates <https://pigweed.googlesource.com/third_party/rust_crates>`_
62respository.  Currently referencing these is only supported through the bazel
63build.
64