Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Created January 20, 2025 02:05
Show Gist options
  • Select an option

  • Save lupyuen/ccfae733657b864f2f9a24ce41808144 to your computer and use it in GitHub Desktop.

Select an option

Save lupyuen/ccfae733657b864f2f9a24ce41808144 to your computer and use it in GitHub Desktop.
hello_rust_cargo on Apache NuttX RTOS rv-virt:leds
luppy@thinkstation:~$ rm -rf .cargo .rustup rust rust2
luppy@thinkstation:~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/home/luppy/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/home/luppy/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/home/luppy/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/luppy/.profile
/home/luppy/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>
info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2025-01-09, rust version 1.84.0 (9fc6b4312 2025-01-07)
info: downloading component 'cargo'
info: downloading component 'clippy'
2.8 MiB / 2.8 MiB (100 %) 1.3 MiB/s in 1s ETA: 0s
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
70.6 MiB / 70.6 MiB (100 %) 54.6 MiB/s in 1s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
8.8 MiB / 8.8 MiB (100 %) 8.0 MiB/s in 1s ETA: 0s
info: installing component 'clippy'
info: installing component 'rust-docs'
16.5 MiB / 16.5 MiB (100 %) 6.4 MiB/s in 2s ETA: 0s
info: installing component 'rust-std'
29.0 MiB / 29.0 MiB (100 %) 9.4 MiB/s in 3s ETA: 0s
info: installing component 'rustc'
70.6 MiB / 70.6 MiB (100 %) 7.1 MiB/s in 9s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'
stable-x86_64-unknown-linux-gnu installed - rustc 1.84.0 (9fc6b4312 2025-01-07)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.
This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish" # For fish
luppy@thinkstation:~$ . "$HOME/.cargo/env"
luppy@thinkstation:~$ rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: checking for self-update
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.84.0 (9fc6b4312 2025-01-07)
info: cleaning up downloads & tmp directories
luppy@thinkstation:~$ rustup toolchain install nightly
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2025-01-20, rust version 1.86.0-nightly (9a1d156f3 2025-01-19)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
8.8 MiB / 8.8 MiB (100 %) 7.3 MiB/s in 1s ETA: 0s
info: installing component 'clippy'
info: installing component 'rust-docs'
18.2 MiB / 18.2 MiB (100 %) 5.3 MiB/s in 4s ETA: 0s
info: installing component 'rust-std'
26.8 MiB / 26.8 MiB (100 %) 8.3 MiB/s in 4s ETA: 0s
info: installing component 'rustc'
69.3 MiB / 69.3 MiB (100 %) 8.2 MiB/s in 9s ETA: 0s
info: installing component 'rustfmt'
nightly-x86_64-unknown-linux-gnu installed - rustc 1.86.0-nightly (9a1d156f3 2025-01-19)
info: checking for self-update
luppy@thinkstation:~$ rustup default nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'
nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.86.0-nightly (9a1d156f3 2025-01-19)
luppy@thinkstation:~$ rustc --version
rustc 1.86.0-nightly (9a1d156f3 2025-01-19)
luppy@thinkstation:~$ rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
info: downloading component 'rust-src'
info: installing component 'rust-src'
luppy@thinkstation:~$ mkdir rust
luppy@thinkstation:~$ cd rust
luppy@thinkstation:~/rust$ git clone https://github.com/apache/nuttx
Cloning into 'nuttx'...
remote: Enumerating objects: 839358, done.
remote: Counting objects: 100% (1345/1345), done.
remote: Compressing objects: 100% (346/346), done.
remote: Total 839358 (delta 1078), reused 1003 (delta 997), pack-reused 838013 (from 2)
Receiving objects: 100% (839358/839358), 298.36 MiB | 17.16 MiB/s, done.
Resolving deltas: 100% (653762/653762), done.
Updating files: 100% (23812/23812), done.
luppy@thinkstation:~/rust$ git clone https://github.com/apache/nuttx-apps apps
Cloning into 'apps'...
remote: Enumerating objects: 94008, done.
remote: Counting objects: 100% (1553/1553), done.
remote: Compressing objects: 100% (573/573), done.
remote: Total 94008 (delta 1241), reused 980 (delta 980), pack-reused 92455 (from 4)
Receiving objects: 100% (94008/94008), 27.35 MiB | 14.12 MiB/s, done.
Resolving deltas: 100% (75038/75038), done.
luppy@thinkstation:~/rust$ cd nuttx
luppy@thinkstation:~/rust/nuttx$ git status && hash1=`git rev-parse HEAD`
pushd ../apps
git status && hash2=`git rev-parse HEAD`
popd
echo NuttX Source: https://github.com/apache/nuttx/tree/$hash1 >nuttx.hash
echo NuttX Apps: https://github.com/apache/nuttx-apps/tree/$hash2 >>nuttx.hash
cat nuttx.hash
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/rust/apps ~/rust/nuttx
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~/rust/nuttx
NuttX Source: https://github.com/apache/nuttx/tree/4857ea211f069ba1d2602edc1f1946f2d2917c08
NuttX Apps: https://github.com/apache/nuttx-apps/tree/9b6de015bc69f3c30159a1b967db25fb5c59b8bc
luppy@thinkstation:~/rust/nuttx$ make distclean
NuttX has not been configured!
To configure the project:
tools/configure.sh <config>
For a list of available configurations:
tools/configure.sh -L
luppy@thinkstation:~/rust/nuttx$ tools/configure.sh rv-virt:leds
Copy files
Select CONFIG_HOST_LINUX=y
Refreshing...
CP: arch/dummy/Kconfig to /home/luppy/rust/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /home/luppy/rust/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /home/luppy/rust/apps/platform/dummy
LN: include/arch to arch/risc-v/include
LN: include/arch/board to /home/luppy/rust/nuttx/boards/risc-v/qemu-rv/rv-virt/include
LN: drivers/platform to /home/luppy/rust/nuttx/drivers/dummy
LN: include/arch/chip to /home/luppy/rust/nuttx/arch/risc-v/include/qemu-rv
LN: arch/risc-v/src/chip to /home/luppy/rust/nuttx/arch/risc-v/src/qemu-rv
LN: arch/risc-v/src/board to /home/luppy/rust/nuttx/boards/risc-v/qemu-rv/rv-virt/src
mkkconfig in /home/luppy/rust/apps/audioutils
mkkconfig in /home/luppy/rust/apps/benchmarks
mkkconfig in /home/luppy/rust/apps/boot
mkkconfig in /home/luppy/rust/apps/canutils
mkkconfig in /home/luppy/rust/apps/crypto
mkkconfig in /home/luppy/rust/apps/database
mkkconfig in /home/luppy/rust/apps/examples/mcuboot
mkkconfig in /home/luppy/rust/apps/examples/module
mkkconfig in /home/luppy/rust/apps/examples/rust
mkkconfig in /home/luppy/rust/apps/examples/sotest
mkkconfig in /home/luppy/rust/apps/examples
mkkconfig in /home/luppy/rust/apps/fsutils
mkkconfig in /home/luppy/rust/apps/games
mkkconfig in /home/luppy/rust/apps/graphics
mkkconfig in /home/luppy/rust/apps/industry
mkkconfig in /home/luppy/rust/apps/inertial
mkkconfig in /home/luppy/rust/apps/interpreters/luamodules
mkkconfig in /home/luppy/rust/apps/interpreters
mkkconfig in /home/luppy/rust/apps/logging
mkkconfig in /home/luppy/rust/apps/lte
mkkconfig in /home/luppy/rust/apps/math
mkkconfig in /home/luppy/rust/apps/mlearning
mkkconfig in /home/luppy/rust/apps/netutils
mkkconfig in /home/luppy/rust/apps/sdr
mkkconfig in /home/luppy/rust/apps/system
mkkconfig in /home/luppy/rust/apps/testing
mkkconfig in /home/luppy/rust/apps/videoutils
mkkconfig in /home/luppy/rust/apps/wireless/bluetooth
mkkconfig in /home/luppy/rust/apps/wireless/ieee802154
mkkconfig in /home/luppy/rust/apps/wireless
mkkconfig in /home/luppy/rust/apps
#
# configuration written to .config
#
luppy@thinkstation:~/rust/nuttx$ kconfig-tweak --enable CONFIG_EXAMPLES_HELLO_RUST_CARGO
luppy@thinkstation:~/rust/nuttx$ kconfig-tweak --disable CONFIG_ARCH_FPU
luppy@thinkstation:~/rust/nuttx$ kconfig-tweak --enable CONFIG_SYSTEM_TIME64
kconfig-tweak --enable CONFIG_FS_LARGEFILE
kconfig-tweak --enable CONFIG_DEV_URANDOM
kconfig-tweak --set-val CONFIG_TLS_NELEM 16
luppy@thinkstation:~/rust/nuttx$ make olddefconfig
CP: arch/dummy/Kconfig to /home/luppy/rust/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /home/luppy/rust/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /home/luppy/rust/apps/platform/dummy
LN: include/arch to arch/risc-v/include
LN: include/arch/board to /home/luppy/rust/nuttx/boards/risc-v/qemu-rv/rv-virt/include
LN: drivers/platform to /home/luppy/rust/nuttx/drivers/dummy
LN: include/arch/chip to /home/luppy/rust/nuttx/arch/risc-v/include/qemu-rv
LN: arch/risc-v/src/chip to /home/luppy/rust/nuttx/arch/risc-v/src/qemu-rv
LN: arch/risc-v/src/board to /home/luppy/rust/nuttx/boards/risc-v/qemu-rv/rv-virt/src
#
# configuration written to .config
#
luppy@thinkstation:~/rust/nuttx$ vi $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/fs.rs
luppy@thinkstation:~/rust/nuttx$ ## Remember to patch fs.rs
luppy@thinkstation:~/rust/nuttx$ head -n 1049 $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/pal/unix/fs.rs | tail -n 17
target_os = "vita",
target_os = "hurd",
)))]
fn name_cstr(&self) -> &CStr {
// Previously: unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()) }
unsafe { CStr::from_ptr(self.entry.d_name.as_ptr() as *const u8) }
}
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
target_os = "fuchsia",
target_os = "redox",
target_os = "aix",
target_os = "nto",
target_os = "vita",
luppy@thinkstation:~/rust/nuttx$ make -j
Create version.h
CPP: nxfonts_convert.c-> nxfonts_convert_1bpp.i LN: platform/board to /home/luppy/rust/apps/platform/dummy
Updating crates.io index
Locking 30 packages to latest compatible versions
Downloaded itoa v1.0.14
Downloaded serde v1.0.217
Downloaded pin-project-lite v0.2.16
Downloaded ryu v1.0.18
Downloaded serde_derive v1.0.217
Downloaded unicode-ident v1.0.14
Downloaded proc-macro2 v1.0.93
Downloaded quote v1.0.38
Downloaded memchr v2.7.4
Downloaded serde_json v1.0.137
Downloaded syn v2.0.96
Downloaded tokio v1.43.0
Downloaded 12 crates (1.7 MB) in 0.47s
Updating crates.io index
Downloaded adler2 v2.0.0
Downloaded getopts v0.2.21
Downloaded miniz_oxide v0.8.3
Downloaded cfg-if v1.0.0
Downloaded rustc-demangle v0.1.24
Downloaded addr2line v0.24.2
Downloaded allocator-api2 v0.2.21
Downloaded hashbrown v0.15.2
Downloaded compiler_builtins v0.1.143
Downloaded gimli v0.31.1
Downloaded unicode-width v0.1.14
Downloaded object v0.36.7
Downloaded libc v0.2.169
Downloaded 13 crates (2.2 MB) in 0.29s
Compiling compiler_builtins v0.1.143
Compiling core v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
Compiling libc v0.2.169
Compiling object v0.36.7
Compiling std v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
Compiling proc-macro2 v1.0.93
Compiling unicode-ident v1.0.14
Compiling serde v1.0.217
Compiling serde_json v1.0.137
Compiling quote v1.0.38
Compiling syn v2.0.96
Compiling serde_derive v1.0.217
Compiling rustc-std-workspace-core v1.99.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
Compiling alloc v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
Compiling cfg-if v1.0.0
Compiling memchr v2.7.4
Compiling adler2 v2.0.0
Compiling rustc-demangle v0.1.24
Compiling unwind v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
Compiling rustc-std-workspace-alloc v1.99.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
Compiling panic_abort v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
Compiling panic_unwind v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
Compiling gimli v0.31.1
Compiling miniz_oxide v0.8.3
Compiling hashbrown v0.15.2
Compiling std_detect v0.1.5 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
Compiling addr2line v0.24.2
Compiling proc_macro v0.0.0 (/home/luppy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro)
Compiling pin-project-lite v0.2.16
Compiling itoa v1.0.14
Compiling ryu v1.0.18
Compiling tokio v1.43.0
Compiling hello v0.1.0 (/home/luppy/rust/apps/examples/rust/hello)
Finished `release` profile [optimized] target(s) in 46.85s
Register: ostest
Register: hello
Register: leds
Register: hello_rust_cargo
Register: nsh
Register: getprime
Register: sh
CPP: /home/luppy/rust/nuttx/boards/risc-v/qemu-rv/rv-virt/scripts/ld.script-LD: nuttx
riscv-none-elf-ld: warning: /home/luppy/rust/nuttx/nuttx has a LOAD segment with RWX permissions
Memory region Used Size Region Size %age Used
luppy@thinkstation:~/rust/nuttx$ qemu-system-riscv32 \
-semihosting \
-M virt,aclint=on \
-cpu rv32 \
-smp 8 \
-bios nuttx \
-nographic
ABCboard_userled: LED 1 set to 0
board_userled: LED 2 set to 0
board_userled: LED 3 set to 0
NuttShell (NSH) NuttX-12.8.0
nsh> uname -a
NuttX 12.8.0 4857ea211f Jan 20 2025 10:03:14 risc-v rv-virt
nsh> hello
Hello, World!!
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
"name": "Alice",
"age": 28
}
Hello world from tokio!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment