Pico SDK 2.3.0 adds '-fno-math-errno' to RP2350, which 'swiftc' doesn't understand

Hi,

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.

FAILED: [code=1] CMakeFiles/swift-blinky.dir/Main.swift.o 
/Users/me/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2026-05-18-a.xctoolchain/usr/bin/swiftc [...]
error: unknown argument: '-fno-math-errno'

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:

  1. 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
  2. Clone or check out a fresh branch of swift-embedded-examples
  3. Open up the CMakeLists.txt in the rpi-pico-blink-sdk directory of the repo
  4. 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
  5. Run the build: cd rpi-pico-blink-sdk && cmake -B build -G Ninja . -DCMAKE_EXPORT_COMPILE_COMMANDS=On && cmake --build build

Thanks,

Brian

One other thing...

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:

error: unknown argument: '-msoft-float'

To answer my own question, I added the following CMake directives to the top-level CMakeLists.txt file in rpi-pico-blink-sdk folder:

if(TARGET pico_float_pico_vfp)
    set_target_properties(pico_float_pico_vfp PROPERTIES INTERFACE_COMPILE_OPTIONS "")
endif()

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.

Attribution: I found the above code snippet in the "PicoSDK" project on GitHub.

These are C compiler flags, which Swift can happily forward to its internal Clang but cannot accept directly.

What would be the solution here then?

Pass that flag only to the ARM GCC compiler for building the Pico SDK libs, and not pass that flag to the Swift compiler?

Tell the Swift compiler to ignore the flag and pass it on to Clang?

How would you do either of these things, or is there a different solution altogether?

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.

Yep, that's about where my knowledge is at too.

I have a few ideas, I will keep trying.

Thanks for looking at this and offering suggestions.

I was able to find a fix for this with the help of Claude.

The fix has been submitted as a PR here: Fix RP2350 Swift build by scoping '-fno-math-errno' by trundlebits · Pull Request #237 · swiftlang/swift-embedded-examples · GitHub

The tl;dr version:

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.