casaroli opened a new pull request, #19507:
URL: https://github.com/apache/nuttx/pull/19507

   ## Summary
   
   CMake validates a compiler by building **and linking** a small test program.
   For a bare-metal cross toolchain that link cannot succeed on its own terms — 
no
   start files, no default linker script, no libc — and the flags NuttX supplies
   for it assume a toolchain shipped with newlib. `arch/arm/src/cmake/gcc.cmake`
   sets:
   
   ```cmake
   set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
   ```
   
   A perfectly usable `arm-none-eabi-gcc` built without those specs therefore
   fails configuration before a single NuttX source file is considered.
   
   Setting `CMAKE_TRY_COMPILE_TARGET_TYPE` to `STATIC_LIBRARY` in the ARM
   toolchain file makes the detection step compile without linking. This is the
   approach CMake documents for cross-compiling to bare metal, and NuttX does 
not
   currently set it anywhere in the tree.
   
   ## Impact
   
   - **Users:** the CMake build becomes usable with any ARM toolchain that lacks
     `nosys.specs`, including the Homebrew `arm-none-eabi-gcc` and other
     newlib-less builds. Previously it could not configure at all.
   - **Toolchains that do ship `nosys.specs`:** unaffected. The setting applies
     only to CMake's own compiler-detection step, not to the NuttX link.
   - **Build process:** no change to any produced artifact.
   - **Documentation / hardware / security / compatibility:** unaffected.
   
   ## Testing
   
   Board: `mps3-an547:picostest`, CMake + Ninja generator.
   
   Before (master `7df7c6ee`):
   
   ```
   $ cmake -B build -DBOARD_CONFIG=mps3-an547:picostest -GNinja
       arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs': No 
such file or directory
       compilation terminated.
       ninja: build stopped: subcommand failed.
   
     CMake will not be able to correctly generate this project.
   Call Stack (most recent call first):
     CMakeLists.txt:481 (project)
   
   -- Configuring incomplete, errors occurred!
   ```
   
   After this patch, configuration succeeds:
   
   ```
   $ cmake -B build -DBOARD_CONFIG=mps3-an547:picostest -GNinja
   -- Check for working CXX compiler: /opt/homebrew/bin/arm-none-eabi-g++ - 
skipped
   -- Detecting CXX compile features - done
   -- Configuring done (2.5s)
   -- Generating done (0.1s)
   -- Build files have been written to: build
   ```
   
   and the tree then compiles — **1248 objects built**:
   
   ```
   $ ninja -k 0
   ...
   $ grep -c "Building C object" ninja.log
   1248
   ```
   
   The build stops at the final link, for a reason this patch does not address 
and
   does not introduce:
   
   ```
   FAILED: [code=1] nuttx
   arm-none-eabi-g++: fatal error: cannot read spec file 'nosys.specs': No such 
file or directory
   ```
   
   That is the NuttX link itself passing `--specs=nosys.specs`
   (`gcc.cmake:277`), not CMake's detection step. Whether that flag is needed at
   all for a `-nostdlib` NuttX link is a separate question I have deliberately
   left alone. With this patch the compile phase is fully exercised on a
   newlib-less toolchain, where before nothing could be configured.
   
   (`CONFIG_LIBM=y` / `CONFIG_LIBM_TOOLCHAIN=n` was set for the run above, for 
the
   same missing-newlib reason.)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to