Add CI: host tests, consumer smoke test, Embedded Swift check
Three jobs in GitHub Actions: - Build & test on macOS against SDK headers fetched from Panic (cached), with the pkg-config module generated into PKG_CONFIG_PATH. - A consumer smoke test (Scripts/consumer-test.sh) generating a scratch package that depends on play-date, guarding setting propagation. - An Embedded Swift cross-compile for armv7em-none-none-eabi (Scripts/build-embedded.sh) on a swift.org snapshot toolchain — the check that enforces the Embedded Swift subset promise. Verified locally: the full module compiles for the device triple with no violations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Cross-compiles the PlayDate target for Playdate hardware (Embedded Swift,
|
||||
# ARM Cortex-M7) as a compile-only check that the bindings stay within the
|
||||
# Embedded Swift subset. Linking is left to game projects.
|
||||
#
|
||||
# Requirements:
|
||||
# - A Swift toolchain with the embedded stdlib for armv7em-none-none-eabi
|
||||
# (a swift.org development snapshot; Xcode's toolchain does not ship it).
|
||||
# Override the binary with SWIFT_BIN, otherwise `swift` from PATH is used.
|
||||
# - Arm GNU toolchain (arm-none-eabi) C headers, because pd_api.h includes
|
||||
# libc headers that bare-metal builds resolve against newlib. Override the
|
||||
# directory with ARM_NONE_EABI_INCLUDE, otherwise common install locations
|
||||
# are searched.
|
||||
# - The "playdate" pkg-config module (Scripts/install-pkgconfig.sh).
|
||||
|
||||
set -eu
|
||||
|
||||
swift_bin="${SWIFT_BIN:-swift}"
|
||||
|
||||
include_dir="${ARM_NONE_EABI_INCLUDE:-}"
|
||||
if [ -z "$include_dir" ]; then
|
||||
for candidate in \
|
||||
/usr/local/playdate/gcc-arm-none-eabi-*/arm-none-eabi/include \
|
||||
/Applications/ArmGNUToolchain/*/arm-none-eabi/arm-none-eabi/include \
|
||||
/usr/lib/arm-none-eabi/include \
|
||||
/usr/include/newlib; do
|
||||
if [ -f "$candidate/stdlib.h" ]; then
|
||||
include_dir="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$include_dir" ] || [ ! -f "$include_dir/stdlib.h" ]; then
|
||||
echo "error: arm-none-eabi C headers not found." >&2
|
||||
echo "Install the Arm GNU toolchain or set ARM_NONE_EABI_INCLUDE." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Using swift: $swift_bin ($($swift_bin --version 2>/dev/null | head -1))"
|
||||
echo "Using arm-none-eabi headers: $include_dir"
|
||||
|
||||
# --build-system native stops after compilation; the default build system
|
||||
# also tries to merge objects with the host linker, which cannot process
|
||||
# bare-metal ELF objects.
|
||||
exec "$swift_bin" build \
|
||||
--build-system native \
|
||||
--target PlayDate \
|
||||
--triple armv7em-none-none-eabi \
|
||||
-Xswiftc -enable-experimental-feature -Xswiftc Embedded \
|
||||
-Xswiftc -wmo \
|
||||
-Xcc -I"$include_dir" \
|
||||
-Xcc -mcpu=cortex-m7 \
|
||||
-Xcc -mfloat-abi=hard \
|
||||
-Xcc -mfpu=fpv5-sp-d16
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Verifies the package works as a SwiftPM dependency: generates a scratch
|
||||
# executable package that depends on play-date, imports both modules, and
|
||||
# runs it. This guards the pkg-config setup — target settings that don't
|
||||
# propagate to consumers (or manifest validation failures) surface here,
|
||||
# not on this package's own build.
|
||||
|
||||
set -eu
|
||||
|
||||
package_dir="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
scratch_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "$scratch_dir"' EXIT
|
||||
|
||||
mkdir -p "$scratch_dir/Sources/consumer"
|
||||
|
||||
cat > "$scratch_dir/Package.swift" <<EOF
|
||||
// swift-tools-version: 6.4
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "consumer",
|
||||
dependencies: [
|
||||
.package(path: "$package_dir"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "consumer",
|
||||
dependencies: [.product(name: "PlayDate", package: "play-date")]
|
||||
),
|
||||
]
|
||||
)
|
||||
EOF
|
||||
|
||||
cat > "$scratch_dir/Sources/consumer/main.swift" <<'EOF'
|
||||
import CPlaydate
|
||||
import PlayDate
|
||||
|
||||
// Touch a type from each module to prove both import and link.
|
||||
let event = Playdate.SystemEvent(event: kEventInit, argument: 0)
|
||||
let buttons: Playdate.System.Buttons = [.a, .up]
|
||||
print(event != nil && buttons.contains(.a) ? "ok" : "broken")
|
||||
EOF
|
||||
|
||||
cd "$scratch_dir"
|
||||
output="$(swift run 2>&1 | tail -1)"
|
||||
echo "consumer output: $output"
|
||||
[ "$output" = "ok" ]
|
||||
Reference in New Issue
Block a user