Skip to content

Instantly share code, notes, and snippets.

@colemancda
Created May 23, 2022 20:21
Show Gist options
  • Save colemancda/339a5664d4b691b728be1e9879dfa76a to your computer and use it in GitHub Desktop.
Save colemancda/339a5664d4b691b728be1e9879dfa76a to your computer and use it in GitHub Desktop.
Cross compile Swift package and embed into Buildroot
#!/bin/sh
# Configuration
SWIFT_BUILD_MODE="${SWIFT_BUILD_MODE:=release}"
# exit for failures
set -e
# build swift package
echo "Build Swift Package"
HOST_SWIFT_SUPPORT_DIR="${BUILDROOT_SRCDIR}/output/host/usr/share/swift"
SWIFT_BIN="${HOST_SWIFT_SUPPORT_DIR}/bin/swift"
SWIFT_DESTINATION_FILE="${HOST_SWIFT_SUPPORT_DIR}/toolchain.json"
$SWIFT_BIN build --package-path ${SWIFT_PACKAGE_PATH} \
--build-path ${SWIFT_PACKAGE_PATH}/.build \
-c ${SWIFT_BUILD_MODE} \
-Xswiftc -enable-testing \
--destination ${SWIFT_DESTINATION_FILE} \
--build-tests \
-Xswiftc -enable-testing \
# Copy unit tests
cp ${SWIFT_PACKAGE_PATH}/.build/${SWIFT_BUILD_MODE}/*.xctest ${BUILDROOT_SRCDIR}/output/target/usr/bin/
# Rebuild Buildroot
cd $BUILDROOT_SRCDIR
echo "Build Buildroot"
make
cd ../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment