-
Notifications
You must be signed in to change notification settings - Fork 64
Pico SDK - Fix Compiler Definitions & RISC-V RP2350 support #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As I previously mentioned, this PR addresses #59. The Pico SDK examples resulted in build errors with the new 2.0.0 SDK due to the required compiler flags not being passed to This PR also addresses issues when building for RP2350's RISC-V mode, though it's currently pending an SDK update. With Pico SDK version 2.0.1, issues (raspberrypi/pico-sdk#1922) will be fixed. One can pre-test the new version by switching to the SDK |
Similar to apple/swift-embedded-examples#63, this addresses issues regarding compiler definitions when using the Pico SDK with swiftc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know enough cmake to really comment on this approach, @etcwilde do you mind providing some feedback?
Refactored the CLANG_ARCH_ABI_FLAGS back into each if/else block.
To be honest, I didn't know that much CMake either - I learned while writing this. Feedback is definitely welcome 😅👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments.
You might be able to get the gather_compile_definitions_recursive
down to a single generator expression. I don't love that part because it's something that CMake will already do for you if we weren't using a custom command.
(Probably for someone else, but it might be worth looking into switching the custom command in favor of a normal add_library
invocation instead and linking things normally)
I was wondering why this was used, and I found this here:
Regarding a native CMake implementation:
We should be able to replace the special |
No, if you can make this work with CMake's native Swift support, that would be amazing |
I've looked into this a bit this weekend, and I was able to successfully compile this simple test program (I know it doesn't change the architecture based on the environment variable yet, this is just a starting point): cmake_minimum_required(VERSION 3.13)
# Include and initialize the Pico SDK
set(CMAKE_Swift_COMPILER_WORKS TRUE) # ignore the "ld: library 'System' not found" simple test program error
include(/Users/cmd/pico/pico-sdk/external/pico_sdk_import.cmake)
# Set the project name and specify Swift as the language
project(swift-blinky LANGUAGES Swift C CXX ASM)
pico_sdk_init()
# Specify Swift compiler flags
set(CMAKE_Swift_FLAGS "-target armv6m-none-none-eabi -Xcc -mfloat-abi=soft -Xcc -fshort-enums -Xfrontend -function-sections -enable-experimental-feature Embedded -wmo -parse-as-library -c")
# Add the Swift source file
add_executable(swift-blinky
Main.swift
) So compiling embedded Swift works perfectly fine, but now, the challenging part comes: integrating with the Pico SDK. I ran into some issues likely caused by using Swift (and clang) with the ARM GNU GCC toolchain used by the SDK (since I'm seeing arguments specific to GCC in the When I add So I guess what's left is to customize that last linking step and make it work properly. If anyone has some tips on this, I'd be happy to hear them! 😃 |
I ran into this trying to get the pico-w blinky example running. It worked perfectly for me. My two cents here: Perfect might be the enemy of good here. |
Right, using the CMake native support turned out to be a bit harder than expected. Might still be possible, though. Perhaps we can and try to address all issues (if there are any remianing ones) with the current apporach, so people can use the new Pico SDK without issues, and work on the CMake native Swift approach in another issue / PR? On the other hand, people having issues will probably find #59 when searching for fixes / known issues, which is also linked to this PR. Just like you did, I suppose 😆 |
I think this looks good to merge with hopes of adopting the swift cmake support later. I'd like to get @kubamracek to review this before merging though. |
Agree with all that's being said, and I'll throw in that we do have a couple of existence proofs of using the CMake native Swift support, e.g. here https://github.com/apple/swift-embedded-examples/blob/main/esp32-led-blink-sdk/main/CMakeLists.txt. But yes, let's merge this PR now as is. |
I'll look into that 👍 |
I closed this by mistake, sorry. I deleted my patch-1 branch by mistake. |
@rauhul Please review changes completed and approve. Support for RISC-V on the 2350 for an embedded Swift example would be awesome! |
Small reminder that this still requires a Pico SDK update in order to run on the RISC-V cores (the patch is in the development branch, should release with 2.0.1). So if you want to try this yourself, you currently need to use the development (nightly) branch of the Pico SDK. Maybe I should add this info in the example's README and update it when the new SDK version comes out. |
@iCMDdev agreed - this would save developers some headaches. Any idea when the Pico SDK 2.0.1 will be released? |
I'm not sure...
Done, what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks
Thanks for merging! 🎉 |
This is a PR for fixing the issues outlined in #59.