Skip to content

cmake: Fix SIM_TOOLCHAIN using CMake on macOS.#18957

Merged
jerpelea merged 1 commit into
apache:masterfrom
toku-mac:fix_cmake_sim_toolchain
May 25, 2026
Merged

cmake: Fix SIM_TOOLCHAIN using CMake on macOS.#18957
jerpelea merged 1 commit into
apache:masterfrom
toku-mac:fix_cmake_sim_toolchain

Conversation

@toku-mac
Copy link
Copy Markdown
Contributor

Summary

Set host-specific Kconfig values before the initial olddefconfig step in the CMake build, and clarify the helper arguments used for that setup.

On macOS, sim:nsh needs HOST_MACOS=y to be present before the sim toolchain choice is resolved. Without that, the first olddefconfig may select the default GCC toolchain instead of the macOS-specific Clang default.

As a result, you encounter the error ld: library not found for -lgcov.

This PR updates the CMake initialization flow so nuttx_sethost() can apply host settings to the temporary .config.compressed before the first olddefconfig.

The helper functions were also refactored to use named arguments:

nuttx_sethost(CONFIG_FILE ...)
nuttx_setconfig(CONFIG_FILE ... SETTINGS ...)

Impact

CONFIG_SIM_TOOLCHAIN_CLANG=y is enabled, which resolves linker errors.

Testing

I confirm that changes are verified on local setup and works as intended:

  • Build Host(s): OS (macOS 26.5), CPU(Apple M1), compiler(Apple clang version 21.0.0)
  • Target(s): arch(sim)
  • Ensure your PATH environment variable is properly configured to allow execution of: menuconfig, olddefconfig, savedefconfig, and setconfig.
  • Use the Rust toolchain version prior to nightly-2026-04-29 to avoid errors related to lib/rustlib/src/rust/library/std/src/sys/net/connection/socket/unix.rs.

Configuration:

rm -rf build-debug
make distclean
cmake -S . -B build-debug -DBOARD_CONFIG=sim:nsh -GNinja

printf "CONFIG_SYSTEM_TIME64=y
CONFIG_FS_LARGEFILE=y
CONFIG_TLS_NELEM=16
CONFIG_DEV_URANDOM=y
CONFIG_EXAMPLES_HELLO_RUST_CARGO=y
CONFIG_EXAMPLES_HELLO_RUST_CARGO_STACKSIZE=8192
" >> build-debug/.config

cmake --build build-debug -t olddefconfig

Testing logs before change:

...
   Compiling proc_macro v0.0.0 (/Users/toku/.rustup/toolchains/nightly-2026-04-29-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling itoa v1.0.18
   Compiling pin-project-lite v0.2.17
   Compiling memchr v2.8.0
   Compiling tokio v1.52.3
   Compiling hello v0.1.0 (/Users/toku/nuttxspace/apps/examples/rust/hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 21.46s
[1224/1229] Linking C executable nuttx
FAILED: [code=1] nuttx
: && /usr/bin/cc -arch arm64 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-dead_strip -Wl,-ld_classic,-no_fixup_chains @CMakeFiles/nuttx.rsp -o nuttx && :
ld: warning: -ld_classic is deprecated and will be removed in a future release
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Testing logs after change:

...
   Compiling proc_macro v0.0.0 (/Users/toku/.rustup/toolchains/nightly-2026-04-29-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling itoa v1.0.18
   Compiling pin-project-lite v0.2.17
   Compiling memchr v2.8.0
   Compiling tokio v1.52.3
   Compiling hello v0.1.0 (/Users/toku/nuttxspace/apps/examples/rust/hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 21.63s
[1222/1227] Linking C executable nuttx
ld: warning: -ld_classic is deprecated and will be removed in a future release
[1224/1227] Generating System.map

PR verification Self-Check

  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is ready for review and can be safely merged into a codebase.

Fix an issue where `SIM_TOOLCHAIN_GCC` was incorrectly set when
configuring `sim:nsh` using CMake on macOS.
Ensure that `nuttx_sethost()` is called before `nuttx_olddefconfig()`.

Signed-off-by: Shoji Tokunaga <toku@mac.com>
@github-actions github-actions Bot added Area: Build system Size: S The size of the change in this PR is small labels May 25, 2026
Copy link
Copy Markdown
Member

@lupyuen lupyuen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested OK on macOS 26.4.1 25E253 arm64 thanks :-)
https://gist.github.com/lupyuen/6016cbcd5ca7068b59e0e6008d04b7b0

$ git clone https://github.com/toku-mac/nuttx --branch fix_cmake_sim_toolchain
$ git clone https://github.com/apache/nuttx-apps apps
$ cd nuttx ; cmake -S . -B build-debug -DBOARD_CONFIG=sim:nsh -GNinja -DCMAKE_MAKE_PROGRAM=/opt/homebrew/bin/ninja
...
$ cmake --build build-debug -t olddefconfig
$ cmake --build build-debug                        
$ build-debug/nuttx 

NuttShell (NSH)
nsh> uname -a
NuttX 0.0.0 db6ec219d1 May 25 2026 18:10:35 sim sim
nsh> hello
Hello, World!!

@jerpelea jerpelea merged commit 08a2de2 into apache:master May 25, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Build system Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants