diff --git a/Examples/Life/Package.swift b/Examples/Life/Package.swift index 434555d..026a5b6 100644 --- a/Examples/Life/Package.swift +++ b/Examples/Life/Package.swift @@ -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] = [ @@ -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"]) ], diff --git a/Examples/Life/Source/pdex.so b/Examples/Life/Source/pdex.so new file mode 100755 index 0000000..3329e85 Binary files /dev/null and b/Examples/Life/Source/pdex.so differ diff --git a/Examples/SwiftBreak/Package.swift b/Examples/SwiftBreak/Package.swift index 3f84e98..146244c 100644 --- a/Examples/SwiftBreak/Package.swift +++ b/Examples/SwiftBreak/Package.swift @@ -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] = [ @@ -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", ]), ] diff --git a/Examples/SwiftBreak/Source/pdex.so b/Examples/SwiftBreak/Source/pdex.so new file mode 100755 index 0000000..1e3a9a7 Binary files /dev/null and b/Examples/SwiftBreak/Source/pdex.so differ diff --git a/Examples/Template/Package.swift b/Examples/Template/Package.swift index 2127fc8..7f14575 100644 --- a/Examples/Template/Package.swift +++ b/Examples/Template/Package.swift @@ -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] = [ @@ -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", ]), ] diff --git a/Examples/swift.mk b/Examples/swift.mk index 78ea4ec..6b024a2 100644 --- a/Examples/swift.mk +++ b/Examples/swift.mk @@ -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)) \ @@ -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 diff --git a/Package.swift b/Package.swift index 01a75c4..444a19b 100644 --- a/Package.swift +++ b/Package.swift @@ -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] = [ @@ -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", ]), ] @@ -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"]),