In the previous post, we learned how to use Swift embedded to build the blink example using a wrapper for the C++ library. In this post, we’ll learn how to compile and run the blink example written in Swift without using an external library. I suggest you read the previous post for the toolchain installation process.
Follow these steps:
- Download the code from https://github.com/apple/swift-embedded-examples/tree/main/pico-blink
- Install the python dependencies: pip3 install -r ../Tools/requirements.txt
- Copy the .a from this zip https://github.com/user-attachments/files/15878757/libclang_rt.soft_static_armv6m_macho_embedded.a.zip in the Sources/Support directory
- In the build.sh change the line 38 in this:
$CLANG Sources/Support/libclang_rt.soft_static_armv6m_macho_embedded.a .build/release/Support.build/{Support.c,crt0.S}.o .build/release/Blinky.build/*.o -target armv6m-apple-none-macho -o $BUILDROOT/blinky $LD_FLAGS
To build:
TOOLCHAINS='<toolchain-name>' ./build.sh
On my mac i have as TOOLCHAINS:
export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a.xctoolchain/Info.plist)
After the build you can copy the .build/blink.uf2 in your raspberry.
If your mac doesn’t discover the raspberry, disconnect the usb cable, press the bootselect button and reconnect the usb cable.
Now if the example works, start to study the code.