Skip to content

Added Linux build support. #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added Linux build support.
  • Loading branch information
TylerJaacks committed Jul 25, 2024
commit 690e307f35719c1804d50f99bac2cd910885de04
16 changes: 8 additions & 8 deletions Examples/Life/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

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")
// TODO: Give this variable a better name both for the code and the enviroment variable.
guard let gccIncludePrefix = Context.environment["GCC_ARM_PLAYDATE_PATH"] else {
fatalError("Make sure you have the GCC_ARM_PLAYDATE_PATH variable defined.")
}

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

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,15 +22,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", "\(playdate_sdk_path)/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.
13 changes: 8 additions & 5 deletions Examples/SwiftBreak/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

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")
// TODO: Give this variable a better name both for the code and the enviroment variable.
guard let gccIncludePrefix = Context.environment["GCC_ARM_PLAYDATE_PATH"] else {
fatalError("Make sure you have the GCC_ARM_PLAYDATE_PATH variable defined.")
}

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

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -20,7 +23,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", "\(playdate_sdk_path)/C_API",
]),
]

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

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")
// TODO: Give this variable a better name both for the code and the enviroment variable.
guard let gccIncludePrefix = Context.environment["GCC_ARM_PLAYDATE_PATH"] else {
fatalError("Make sure you have the GCC_ARM_PLAYDATE_PATH variable defined.")
}

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

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,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", "\(playdate_sdk_path)/C_API",
]),
]

Expand Down
64 changes: 42 additions & 22 deletions Examples/swift.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@ 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)
# TODO: Maybe find this via environment variable or something.
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 @@ -72,8 +81,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
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

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")
// TODO: Give this variable a better name both for the code and the enviroment variable.
guard let gccIncludePrefix = Context.environment["GCC_ARM_PLAYDATE_PATH"] else {
fatalError("Make sure you have the GCC_ARM_PLAYDATE_PATH variable defined.")
}

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

let swiftSettingsSimulator: [SwiftSetting] = [
Expand All @@ -19,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", "\(playdate_sdk_path)/C_API",
]),
]

Expand All @@ -29,15 +32,12 @@ let cSettingsSimulator: [CSetting] = [
"-I", "\(gccIncludePrefix)/include",
"-I", "\(gccIncludePrefix)/include-fixed",
"-I", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(home)/Developer/PlaydateSDK/C_API",
"-I", "\(playdate_sdk_path)/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