Added a Makefile build for the HelloPlaydate example target.

This commit is contained in:
2026-07-25 10:09:34 +02:00
parent c208382bf8
commit 29619720f7
5 changed files with 107 additions and 1 deletions
+1
View File
@@ -2,6 +2,7 @@
.build/ .build/
/Packages /Packages
# Example build products # Example build products
Examples/*/build
Examples/*/Source/pdex.dylib Examples/*/Source/pdex.dylib
*.pdx *.pdx
xcuserdata/ xcuserdata/
+26
View File
@@ -0,0 +1,26 @@
REPO_ROOT := $(shell git rev-parse --show-toplevel)
PRODUCT := HelloPlaydate.pdx
include $(REPO_ROOT)/Examples/swift.mk
# MARK: - Build PlayDate Wrapper Swift Module
build/Modules/playdate_device.o: $(REPO_ROOT)/Sources/PlayDate/*.swift
@mkdir -p build/Modules
$(SWIFT_EXEC) $(SWIFT_FLAGS) $(SWIFT_FLAGS_DEVICE) -c $^ -emit-module -o $@
build/Modules/playdate_simulator.o: $(REPO_ROOT)/Sources/PlayDate/*.swift
@mkdir -p build/Modules
$(SWIFT_EXEC) $(SWIFT_FLAGS) $(SWIFT_FLAGS_SIMULATOR) -c $^ -emit-module -o $@
# MARK: - Build Game Swift Object
build/game_device.o: Sources/HelloPlaydate/*.swift | build/Modules/playdate_device.o
$(SWIFT_EXEC) $(SWIFT_FLAGS) $(SWIFT_FLAGS_DEVICE) -c $^ -o $@
$(OBJDIR)/pdex.elf: build/game_device.o
OBJS += build/game_device.o
# The wrapper object carries symbols that are not emitted into the game
# object, such as the posix_memalign shim the Embedded Swift runtime needs.
OBJS += build/Modules/playdate_device.o
build/game_simulator.o: Sources/HelloPlaydate/*.swift | build/Modules/playdate_simulator.o
$(SWIFT_EXEC) $(SWIFT_FLAGS) $(SWIFT_FLAGS_SIMULATOR) -c $^ -o $@
$(OBJDIR)/pdex.${DYLIB_EXT}: build/game_simulator.o
SIMCOMPILER += build/game_simulator.o
Binary file not shown.
+78
View File
@@ -0,0 +1,78 @@
HEAP_SIZE = 8388208
STACK_SIZE = 61800
# Locate the Playdate SDK
SDK = ${PLAYDATE_SDK_PATH}
ifeq ($(SDK),)
SDK = $(shell egrep '^\s*SDKRoot' ~/.Playdate/config | head -n 1 | cut -c9-)
endif
ifeq ($(SDK),)
$(error SDK path not found; set ENV value PLAYDATE_SDK_PATH)
endif
include $(SDK)/C_API/buildsupport/common.mk
# Determine the Swift toolchain by order of preference:
#
# 1. the presence of a TOOLCHAINS environment value
# 2. a Swift toolchain installed for the current user (e.g. 'Install for me only')
# 3. a Swift toolchain installed for all users (e.g. 'Install for all users on this computer')
RELATIVE_TOOLCHAIN_PATH = Library/Developer/Toolchains/swift-latest.xctoolchain
ifneq ($(TOOLCHAINS),)
else ifneq ($(wildcard $(HOME)/$(RELATIVE_TOOLCHAIN_PATH)),)
TOOLCHAINS = $(shell plutil -extract CFBundleIdentifier raw -o - $(HOME)/$(RELATIVE_TOOLCHAIN_PATH)/Info.plist)
else ifneq ($(wildcard /$(RELATIVE_TOOLCHAIN_PATH)),)
TOOLCHAINS = $(shell plutil -extract CFBundleIdentifier raw -o - /$(RELATIVE_TOOLCHAIN_PATH)/Info.plist)
else
$(error Swift toolchain not found; set ENV value TOOLCHAINS (e.g. TOOLCHAINS=org.swift.59202403121a make))
endif
GCC_INCLUDE_PATHS := $(shell $(CC) -E -Wp,-v -xc /dev/null 2>&1 | egrep '^ ' | xargs echo )
SWIFT_EXEC := "$(shell TOOLCHAINS=$(TOOLCHAINS) xcrun -f swiftc)"
TOOLCHAIN_PATH := $(shell echo $(SWIFT_EXEC)|sed s'/.xctoolchain.*/.xctoolchain/')
$(info Using Swift toolchain "$(TOOLCHAINS)" (from $(TOOLCHAIN_PATH)))
C_FLAGS := \
$(addprefix -I ,$(GCC_INCLUDE_PATHS)) \
SWIFT_FLAGS := \
$(addprefix -Xcc , $(C_FLAGS)) \
-O \
-wmo -enable-experimental-feature Embedded \
-Xfrontend -disable-stack-protector \
-Xfrontend -function-sections \
-swift-version 6 \
-Xcc -DTARGET_EXTENSION \
-module-cache-path build/module-cache \
-I $(SDK)/C_API \
-I build/Modules \
-I $(REPO_ROOT)/Sources/CPlaydate \
C_FLAGS_DEVICE := \
-mthumb \
-mcpu=cortex-m7 \
-mfloat-abi=hard \
-mfpu=fpv5-sp-d16 \
-D__FPU_USED=1 \
-falign-functions=16 \
-fshort-enums \
SWIFT_FLAGS_DEVICE := \
$(addprefix -Xcc , $(C_FLAGS_DEVICE)) \
-target armv7em-none-none-eabi \
-Xfrontend -experimental-platform-c-calling-convention=arm_aapcs_vfp \
-module-alias PlayDate=playdate_device \
C_FLAGS_SIMULATOR := \
SWIFT_FLAGS_SIMULATOR := \
$(addprefix -Xcc , $(C_FLAGS_SIMULATOR)) \
-module-alias PlayDate=playdate_simulator \
SIMCOMPILER += \
-nostdlib \
-dead_strip \
-Wl,-exported_symbol,_eventHandlerShim \
-Wl,-exported_symbol,_eventHandler \
+2 -1
View File
@@ -53,4 +53,5 @@ exec "$swift_bin" build \
-Xcc -I"$include_dir" \ -Xcc -I"$include_dir" \
-Xcc -mcpu=cortex-m7 \ -Xcc -mcpu=cortex-m7 \
-Xcc -mfloat-abi=hard \ -Xcc -mfloat-abi=hard \
-Xcc -mfpu=fpv5-sp-d16 -Xcc -mfpu=fpv5-sp-d16 \
-Xcc -fshort-enums