Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Examples/Life/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import PackageDescription

let gccIncludePrefix =
"/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/lib/gcc/arm-none-eabi/9.2.1"
guard let home = Context.environment["HOME"] else {
fatalError("could not determine home directory")
guard let gccIncludePrefix = Context.environment["GCC_ARM_INCLUDE_PREFIX_PATH"] else {
fatalError("Make sure you have the GCC_ARM_INCLUDE_PREFIX_PATH variable defined.")
}

guard let playdateSdkPath = Context.environment["PLAYDATE_SDK_PATH"] else {
fatalError("Make sure you have the PLAYDATE_SDK_PATH variable defined.")
}

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,15 +21,12 @@ let swiftSettingsSimulator: [SwiftSetting] = [
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdateSdkPath)/C_API",
]),
]

let package = Package(
name: "Life",
platforms: [
.macOS(.v14)
],
products: [
.library(name: "Life", targets: ["Life"])
],
Expand Down
Binary file added Examples/Life/Source/pdex.so
Binary file not shown.
12 changes: 7 additions & 5 deletions Examples/SwiftBreak/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import PackageDescription

let gccIncludePrefix =
"/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/lib/gcc/arm-none-eabi/9.2.1"
guard let home = Context.environment["HOME"] else {
fatalError("could not determine home directory")
guard let gccIncludePrefix = Context.environment["GCC_ARM_INCLUDE_PREFIX_PATH"] else {
fatalError("Make sure you have the GCC_ARM_INCLUDE_PREFIX_PATH variable defined.")
}

guard let playdateSdkPath = Context.environment["PLAYDATE_SDK_PATH"] else {
fatalError("Make sure you have the PLAYDATE_SDK_PATH variable defined.")
}

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -20,7 +22,7 @@ let swiftSettingsSimulator: [SwiftSetting] = [
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdateSdkPath)/C_API",
]),
]

Expand Down
Binary file added Examples/SwiftBreak/Source/pdex.so
Binary file not shown.
12 changes: 7 additions & 5 deletions Examples/Template/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import PackageDescription

let gccIncludePrefix =
"/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/lib/gcc/arm-none-eabi/9.2.1"
guard let home = Context.environment["HOME"] else {
fatalError("could not determine home directory")
guard let gccIncludePrefix = Context.environment["GCC_ARM_INCLUDE_PREFIX_PATH"] else {
fatalError("Make sure you have the GCC_ARM_INCLUDE_PREFIX_PATH variable defined.")
}

guard let playdateSdkPath = Context.environment["PLAYDATE_SDK_PATH"] else {
fatalError("Make sure you have the PLAYDATE_SDK_PATH variable defined.")
}

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,7 +21,7 @@ let swiftSettingsSimulator: [SwiftSetting] = [
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdateSdkPath)/C_API",
]),
]

Expand Down
63 changes: 41 additions & 22 deletions Examples/swift.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@ 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
UNAME_S := $(shell uname -s)

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)))
ifeq ($(UNAME_S),Linux)
SWIFT_EXEC := "swiftc"
endif
ifeq ($(UNAME_S),Darwin)
# 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

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)))
endif

C_FLAGS := \
$(addprefix -I ,$(GCC_INCLUDE_PATHS)) \
Expand Down Expand Up @@ -71,8 +79,19 @@ 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 \

ifeq ($(UNAME_S),Linux)
SIMCOMPILER += \
-nostdlib \
-dead_strip \
# TODO: Figure out to fix this.
#-Wl,-exported_symbol,_eventHandlerShim \
-Wl,-exported_symbol,_eventHandler
endif
ifeq ($(UNAME_S),Darwin)
SIMCOMPILER += \
-nostdlib \
-dead_strip \
-Wl,-exported_symbol,_eventHandlerShim \
-Wl,-exported_symbol,_eventHandler
endif
17 changes: 8 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import PackageDescription

let gccIncludePrefix =
"/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/lib/gcc/arm-none-eabi/9.2.1"
guard let home = Context.environment["HOME"] else {
fatalError("could not determine home directory")
guard let gccIncludePrefix = Context.environment["GCC_ARM_INCLUDE_PREFIX_PATH"] else {
fatalError("Make sure you have the GCC_ARM_INCLUDE_PREFIX_PATH variable defined.")
}

guard let playdateSdkPath = Context.environment["PLAYDATE_SDK_PATH"] else {
fatalError("Make sure you have the PLAYDATE_SDK_PATH variable defined.")
}

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,7 +21,7 @@ let swiftSettingsSimulator: [SwiftSetting] = [
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdateSdkPath)/C_API",
]),
]

Expand All @@ -29,15 +31,12 @@ let cSettingsSimulator: [CSetting] = [
"-I", "\(gccIncludePrefix)/include",
"-I", "\(gccIncludePrefix)/include-fixed",
"-I", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdateSdkPath)/C_API",
])
]

let package = Package(
name: "swift-playdate-examples",
platforms: [
.macOS(.v14)
],
products: [
.library(name: "Playdate", targets: ["Playdate"]),
.library(name: "CPlaydate", targets: ["CPlaydate"]),
Expand Down