Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active June 7, 2024 09:43
Show Gist options
  • Save lupyuen/e6fe3423e282ff8603de5f248bcb9ae5 to your computer and use it in GitHub Desktop.
Save lupyuen/e6fe3423e282ff8603de5f248bcb9ae5 to your computer and use it in GitHub Desktop.
Apache NuttX RTOS with D Apps. See https://github.com/apache/nuttx-apps/pull/2410
➜ neofetch
'c. luppy@5ce91ef07f94
,xNMM. ------------------
.OMMMMo OS: macOS 14.5 23F79 arm64
OMMM0, Host: Mac14,12
.;loddo:' loolloddol;. Kernel: 23.5.0
cKMMMMMMMMMMNWMMMMMMMMMM0: Uptime: 1 day, 1 hour, 52 mins
.KMMMMMMMMMMMMMMMMMMMMMMMWd. Packages: 77 (brew)
XMMMMMMMMMMMMMMMMMMMMMMMX. Shell: zsh 5.9
;MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 3840x2160
:MMMMMMMMMMMMMMMMMMMMMMMM: DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX. WM: Quartz Compositor
kMMMMMMMMMMMMMMMMMMMMMMMMWd. WM Theme: Blue (Dark)
.XMMMMMMMMMMMMMMMMMMMMMMMMMMk Terminal: iTerm2
.XMMMMMMMMMMMMMMMMMMMMMMMMK. Terminal Font: Hasklig-Medium 18
kMMMMMMMMMMMMMMMMMMMMMMd CPU: Apple M2 Pro
;KMMMMMMMWXXWMMMMMMMk. GPU: Apple M2 Pro
.cooc,. .,coo:. Memory: 4407MiB / 32768MiB
➜ cd /tmp/nuttx
➜ git clone https://github.com/apache/nuttx
Cloning into 'nuttx'...
remote: Enumerating objects: 762076, done.
remote: Counting objects: 100% (459/459), done.
remote: Compressing objects: 100% (229/229), done.
remote: Total 762076 (delta 112), reused 417 (delta 105), pack-reused 761617
Receiving objects: 100% (762076/762076), 262.61 MiB | 14.83 MiB/s, done.
Resolving deltas: 100% (594665/594665), done.
Updating files: 100% (22207/22207), done.
➜ git clone https://github.com/kassane/incubator-nuttx-apps --branch dlang-app apps
Cloning into 'apps'...
remote: Enumerating objects: 83984, done.
remote: Counting objects: 100% (682/682), done.
remote: Compressing objects: 100% (361/361), done.
remote: Total 83984 (delta 351), reused 569 (delta 313), pack-reused 83302
Receiving objects: 100% (83984/83984), 21.58 MiB | 11.79 MiB/s, done.
Resolving deltas: 100% (68027/68027), done.
➜ cd nuttx
➜ tools/configure.sh rv-virt:nsh
Copy files
Select CONFIG_HOST_MACOS=y
Select CONFIG_HOST_ARM64=y
Refreshing...
CP: arch/dummy/Kconfig to /private/tmp/nuttx/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /private/tmp/nuttx/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /private/tmp/nuttx/apps/platform/dummy
LN: include/arch to arch/risc-v/include
LN: include/arch/board to /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/include
LN: drivers/platform to /private/tmp/nuttx/nuttx/drivers/dummy
LN: include/arch/chip to /private/tmp/nuttx/nuttx/arch/risc-v/include/qemu-rv
LN: arch/risc-v/src/chip to /private/tmp/nuttx/nuttx/arch/risc-v/src/qemu-rv
LN: arch/risc-v/src/board to /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/src
mkkconfig in /private/tmp/nuttx/apps/audioutils
mkkconfig in /private/tmp/nuttx/apps/benchmarks
mkkconfig in /private/tmp/nuttx/apps/boot
mkkconfig in /private/tmp/nuttx/apps/canutils
mkkconfig in /private/tmp/nuttx/apps/crypto
mkkconfig in /private/tmp/nuttx/apps/database
mkkconfig in /private/tmp/nuttx/apps/examples/mcuboot
mkkconfig in /private/tmp/nuttx/apps/examples
mkkconfig in /private/tmp/nuttx/apps/fsutils
mkkconfig in /private/tmp/nuttx/apps/games
mkkconfig in /private/tmp/nuttx/apps/graphics
mkkconfig in /private/tmp/nuttx/apps/industry
mkkconfig in /private/tmp/nuttx/apps/inertial
mkkconfig in /private/tmp/nuttx/apps/interpreters/luamodules
mkkconfig in /private/tmp/nuttx/apps/interpreters
mkkconfig in /private/tmp/nuttx/apps/logging
mkkconfig in /private/tmp/nuttx/apps/lte
mkkconfig in /private/tmp/nuttx/apps/math
mkkconfig in /private/tmp/nuttx/apps/mlearning
mkkconfig in /private/tmp/nuttx/apps/netutils
mkkconfig in /private/tmp/nuttx/apps/sdr
mkkconfig in /private/tmp/nuttx/apps/system
mkkconfig in /private/tmp/nuttx/apps/testing
mkkconfig in /private/tmp/nuttx/apps/wireless/bluetooth
mkkconfig in /private/tmp/nuttx/apps/wireless/ieee802154
mkkconfig in /private/tmp/nuttx/apps/wireless
mkkconfig in /private/tmp/nuttx/apps
#
# configuration written to .config
#
➜ make menuconfig
CP: arch/dummy/Kconfig to /private/tmp/nuttx/nuttx/arch/dummy/dummy_kconfig
CP: boards/dummy/Kconfig to /private/tmp/nuttx/nuttx/boards/dummy/dummy_kconfig
LN: platform/board to /private/tmp/nuttx/apps/platform/dummy
LN: include/arch to arch/risc-v/include
LN: include/arch/board to /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/include
LN: drivers/platform to /private/tmp/nuttx/nuttx/drivers/dummy
LN: include/arch/chip to /private/tmp/nuttx/nuttx/arch/risc-v/include/qemu-rv
LN: arch/risc-v/src/chip to /private/tmp/nuttx/nuttx/arch/risc-v/src/qemu-rv
LN: arch/risc-v/src/board to /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/src
*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
➜ grep HELLO_D .config
CONFIG_EXAMPLES_HELLO_D=y
CONFIG_EXAMPLES_HELLO_D_PROGNAME="hello_d"
CONFIG_EXAMPLES_HELLO_D_PRIORITY=100
CONFIG_EXAMPLES_HELLO_D_STACKSIZE=2048
➜ make
Create version.h
LN: platform/board to /private/tmp/nuttx/apps/platform/dummy
Register: hello
Register: hello_d
Register: nsh
Register: sh
Register: getprime
Register: ostest
DC: hello_d_main.d make[2]: ldmd2: No such file or directory
make[2]: *** [hello_d_main.d.private.tmp.nuttx.apps.examples.hello_d.o] Error 1
make[1]: *** [/private/tmp/nuttx/apps/examples/hello_d_all] Error 2
make: *** [/private/tmp/nuttx/apps/libapps.a] Error 2
➜ brew install ldc
==> Downloading https://ghcr.io/v2/homebrew/core/ldc/manifests/1.38.0-1
################################################################################################################################## 100.0%
==> Fetching dependencies for ldc: z3 and llvm
==> Downloading https://ghcr.io/v2/homebrew/core/z3/manifests/4.13.0
################################################################################################################################## 100.0%
==> Fetching z3
==> Downloading https://ghcr.io/v2/homebrew/core/z3/blobs/sha256:d7a6ead5ea667caa7a45e1a623ecd386b09748ed5679b5001dda43365c961e01
################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/manifests/18.1.6
################################################################################################################################## 100.0%
==> Fetching llvm
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/blobs/sha256:b4d6504619c93d7d349882b76797bde21dce8df29981a4a5f05ee27a7a65ee1c
################################################################################################################################## 100.0%
==> Fetching ldc
==> Downloading https://ghcr.io/v2/homebrew/core/ldc/blobs/sha256:95844acab6441d928fd95b8e408668c734392a83a4d317fef59193095a5ae358
################################################################################################################################## 100.0%
==> Installing dependencies for ldc: z3 and llvm
==> Installing ldc dependency: z3
==> Downloading https://ghcr.io/v2/homebrew/core/z3/manifests/4.13.0
Already downloaded: /Users/luppy/Library/Caches/Homebrew/downloads/f76733dc8564492bde6da5ddd68bf485a259b09d276de374047a4600ed52edff--z3-4.13.0.bottle_manifest.json
==> Pouring z3--4.13.0.arm64_sonoma.bottle.tar.gz
🍺 /opt/homebrew/Cellar/z3/4.13.0: 120 files, 31.1MB
==> Installing ldc dependency: llvm
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/manifests/18.1.6
Already downloaded: /Users/luppy/Library/Caches/Homebrew/downloads/47df8186ee2180d361bf1348c606014623467d0ca20634150e4720d1c7bc2497--llvm-18.1.6.bottle_manifest.json
==> Pouring llvm--18.1.6.arm64_sonoma.bottle.tar.gz
🍺 /opt/homebrew/Cellar/llvm/18.1.6: 7,722 files, 1.8GB
==> Installing ldc
==> Pouring ldc--1.38.0.arm64_sonoma.bottle.1.tar.gz
🍺 /opt/homebrew/Cellar/ldc/1.38.0: 744 files, 100MB
==> Running `brew cleanup ldc`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
➜ ldmd2 --version
LDC - the LLVM D compiler (1.38.0):
based on DMD v2.108.1 and LLVM 18.1.6
built with LDC - the LLVM D compiler (1.38.0)
Default target: arm64-apple-darwin23.5.0
Host CPU: apple-m1
http://dlang.org - http://wiki.dlang.org/LDC
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
avr - Atmel AVR Microcontroller
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
loongarch32 - 32-bit LoongArch
loongarch64 - 64-bit LoongArch
mips - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc32le - PowerPC 32 LE
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
ve - VE
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
➜ make
CPP: /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/scripts/ld.script-> /private/tmp/nuttx/nuttx/boards/risc-v/qemu-rv/rv-virt/sLD: nuttx
riscv-none-elf-ld: warning: /private/tmp/nuttx/nuttx/nuttx has a LOAD segment with RWX permissions
➜ qemu-system-riscv32 \
-semihosting \
-M virt,aclint=on \
-cpu rv32 -smp 8 \
-bios none \
-kernel nuttx -nographic
ABC
NuttShell (NSH) NuttX-12.5.1
nsh> uname -a
NuttX 12.5.1 fb1ff61d0d Jun 6 2024 10:12:01 risc-v rv-virt
nsh> hello_d
Hello World, [generic-rv32]!
hello_d_main: Saying hello from the dynamically constructed instance
DHelloWorld.HelloWorld: CONSTRUCTION FAILED!
hello_d_main: Saying hello from the instance constructed on the stack
DHelloWorld.HelloWorld: Hello, World!!
nsh>
@kassane
Copy link

kassane commented Jun 6, 2024

@lupyuen , nice test.

Some info about my tests:

Why not ideal for 16-bit/8-bit?

Custom DRT

Others

@lupyuen
Copy link
Author

lupyuen commented Jun 7, 2024

@kassane Thanks! I got so much to learn about D :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment