I recently upgraded to the 2.3.0 version of the Pico SDK via the VSCode "Raspberry Pi Pico" extension. Version 2.3.0 of the SDK sets -fno-math-errno when both !PICO_RP2040 and !PICO_RISCV are set in CMake; this is a change from version 2.2.0 of the SDK.
swiftc doesn't understand -fno-math-errno, so it errors out when building a project for the RP2350 processor.
The offending line in the Pico SDK is currently on line 143 of CMakeLists.txt file in pico_float. If I comment out that line, -fno-math-errno is no longer set in the environment, and I can build rpi-pico-blink-sdk for the RP2350 with no issues.
I spent some time trying to remove -fno-math-errno from the swiftc command, but I haven't had any luck. I even tried to grab a copy of INTERFACE_COMPILE_OPTIONS in CMakeLists.txt so I could remove -fno-math-errno, but with no success.
To reproduce:
Download and set up Raspberry Pi Pico SDK version 2.3.0; if you use the VSCode "Raspberry Pi Pico" plugin, it also downloads ARM GCC version 15_2_Rel1
Clone or check out a fresh branch of swift-embedded-examples
Open up the CMakeLists.txt in the rpi-pico-blink-sdk directory of the repo
Add set(PICO_BOARD pico2 CACHE STRING "Board type") BEFORE include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) at the top of that file
Run the build: cd rpi-pico-blink-sdk && cmake -B build -G Ninja . -DCMAKE_EXPORT_COMPILE_COMMANDS=On && cmake --build build
I did try setting set(PICO_DEFAULT_FLOAT_IMPL pico_dcp) in the toplevel CMakeLists.txt file to use a different float implementation, but swiftc also doesn't understand when -msoft-float is passed to it as an argument:
This clears out the -fno-math-errno flag everywhere (for both compiled Pico SDK C and Swift), which allows the rpi-pico-blink-sdk demo to build again with PICO_BOARD=pico2.
It's a C flag, not a Swift flag, so yes, your build system should not just be blindly passing it down to the Swift compiler.
Now, the Swift compiler does use Clang's C compiler as a library for processing headers. You do probably want to configure that compiler with the same flags as you pass to ARM GCC. Generally, you can tell Swift to forward an argument to the C compiler by prefixing it with -Xcc, e.g. -Xcc -fno-math-errno.
I don't know enough about cmake to talk about how to achieve that there, like whether target_compile_options is specifically supposed to be used just for C compiler options or what.
The compiler options for Swift need to have -fno-math-errno removed, but left in for compiling the Pico C SDK code. This block in the toplevel CMakeLists.txt in the rpi-pico-blink-sdk handles stripping out -fno-math-errno from the swiftc command:
# Same treatment for the RP2350-only VFP float library, which adds -fno-math-errno
# unguarded. The target does not exist on RP2040, hence the if(TARGET) check.
if(TARGET pico_float_pico_vfp)
set_target_properties(pico_float_pico_vfp PROPERTIES INTERFACE_COMPILE_OPTIONS "")
target_compile_options(pico_float_pico_vfp INTERFACE "$<$<COMPILE_LANGUAGE:C>:SHELL: -fno-math-errno>")
endif()
The addition of the pico_float_pico_vfp target in version 2.3.0 of the Pico SDK is what introduced -fno-math-errno.