Skip to content

Commit

Permalink
support both arm64 and x86_64 (#4)
Browse files Browse the repository at this point in the history
* support both `arm64` and `x86_64`
  • Loading branch information
EstevanBR authored Aug 9, 2024
1 parent 51aa4cc commit 19689a7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Sources/CreateProject/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private struct CreateProject {
print(color: .green, "Created \(try FileFactory.createGodotProjectFile(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.createGDExtensionFile(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.createExportPresetsFile(projectName: projectName))")
print(color: .green, "Created \(try FileFactory.copyMakefile())")
print(color: .green, "Created \(try FileFactory.createMakefile(projectName: projectName))")
} catch let error as LocalizedError {
print(color: .red, "Error: \(error.errorDescription ?? error.localizedDescription)")
if let recoverySuggestion = error.recoverySuggestion {
Expand Down
106 changes: 90 additions & 16 deletions Sources/CreateProject/DataFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,22 @@ enum DataFactory {
compatibility_minimum = 4.2
[libraries]
macos.debug = "res://bin/lib\(projectName).so"
macos.release = "res://bin/lib\(projectName).so"
windows.debug.x86_32 = "res://bin/lib\(projectName).so"
windows.release.x86_32 = "res://bin/lib\(projectName).so"
windows.debug.x86_64 = "res://bin/lib\(projectName).so"
windows.release.x86_64 = "res://bin/lib\(projectName).so"
linux.debug.x86_64 = "res://bin/lib\(projectName).so"
linux.release.x86_64 = "res://bin/lib\(projectName).so"
linux.debug.arm64 = "res://bin/lib\(projectName).so"
linux.release.arm64 = "res://bin/lib\(projectName).so"
linux.debug.rv64 = "res://bin/lib\(projectName).so"
linux.release.rv64 = "res://bin/lib\(projectName).so"
android.debug.x86_64 = "res://bin/lib\(projectName).so"
android.release.x86_64 = "res://bin/lib\(projectName).so"
android.debug.arm64 = "res://bin/lib\(projectName).so"
android.release.arm64 = "res://bin/lib\(projectName).so"
macos.debug = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
macos.release = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
windows.debug.x86_32 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
windows.release.x86_32 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
windows.debug.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
windows.release.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.debug.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.release.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.debug.arm64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.release.arm64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.debug.rv64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
linux.release.rv64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
android.debug.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
android.release.x86_64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
android.debug.arm64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
android.release.arm64 = "res://bin/lib\(projectName).\(arch.dynamicExtension)"
"""
.utf8Data
Expand Down Expand Up @@ -230,6 +230,80 @@ enum DataFactory {
"""
.utf8Data
}

static func makeMakefile(projectName: String) throws -> Data {
try """
include .env
.PHONY: all
all: paths build deploy pack
.PHONY: paths
paths:
@echo "Path to Godot executable:\\n\\t$(GODOT)"
@echo "Godot bin/ path:\\n\\t$(GODOT_BIN_PATH)"
@echo "Build path:\\n\\t$(BUILD_PATH)"
@echo "Godot version:\\n\\t`$(GODOT) --version`"
@echo "Library name:\\n\\t$(LIBRARY_NAME)"
@echo "Executable name:\\n\\t$(EXECUTABLE_NAME)"
@echo "Godot project file path:\\n\\t$(GODOT_PROJECT_FILE_PATH)"
.PHONY: build
build:
mkdir -p $(BUILD_PATH)
swift build --product $(LIBRARY_NAME) --build-path $(BUILD_PATH)
swift build --product $(EXECUTABLE_NAME) --build-path $(BUILD_PATH)
.PHONY: deploy
deploy:
rm -rf $(GODOT_BIN_PATH)
mkdir -p $(GODOT_BIN_PATH)
cp $(BUILD_PATH)/debug/libSwiftGodot.\(arch.dynamicExtension) $(GODOT_BIN_PATH)
cp $(BUILD_PATH)/debug/lib\(projectName).\(arch.dynamicExtension) $(GODOT_BIN_PATH)
.PHONY: run
run:
swift run $(EXECUTABLE_NAME) --build-path $(BUILD_PATH)
.PHONY: open
open:
$(GODOT) $(GODOT_PROJECT_FILE_PATH)
.PHONY: pack
pack:
@echo "Going to open Godot to ensure all resources are imported."
-$(GODOT) $(GODOT_PROJECT_FILE_PATH) --headless --quit
@echo "Exporting the .pck file"
$(GODOT) --headless --path $(GODOT_PROJECT_DIRECTORY) --export-pack Packer ../Sources/$(LIBRARY_NAME)Game/Resources/$(LIBRARY_NAME).pck
"""
.utf8Data
}
}

private enum Architecture {
case x86_64
case arm64

var dynamicExtension: String {
switch self {
case .x86_64: "so"
case .arm64: "dylib"
}
}
}

private extension DataFactory {
static var arch: Architecture {
#if arch(x86_64)
.x86_64
#elseif arch(arm64)
.arm64
#else
fatalError("Unknown architecture")
#endif
}
}

private extension String {
Expand Down
14 changes: 7 additions & 7 deletions Sources/CreateProject/FileFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ enum FileFactory {
return path
}

static func copyMakefile() throws -> String {
guard let url = Bundle.module.url(forResource: "Makefile", withExtension: nil) else {
throw Error.noURLForResource(resource: "Makefile", extension: nil)
}
static func createMakefile(projectName: String) throws -> String {
let directory = fileManager.currentDirectoryPath
let destinationPath = directory + "/Makefile"
try fileManager.copyItem(atPath: url.path, toPath: destinationPath)
return destinationPath
let data = try DataFactory.makeMakefile(projectName: projectName)
let path = directory + "/Makefile"
guard fileManager.createFile(atPath: path, contents: data) else {
throw Error.couldNotCreateFile(path: path)
}
return path
}

static func copyGDDFile() throws -> String {
Expand Down

0 comments on commit 19689a7

Please sign in to comment.