Closed eugeniobaglieri closed 5 months ago
At the moment the pdc plugin which is used to compile doesn't look for / support external packages. It shouldn't be too hard to recursively look for dependencies and at least support simple package dependencies, but at the moment I don't have too much time to dedicate to this. Happy to accept any PRs if someone else wants to work on it though.
A workaround is to copy all the source files from the dependency you want to add directly to the template.
HI @finnvoor , I developed something, here:
https://github.com/eugeniobaglieri/PlaydateKit/tree/support_multiple_packages
the code could and should be improved, but at least it seems to work with local packages (and maybe with remote but have to test it, I did not have enough time to setup a package repository). I test it on project structure of kind:
The PlaydateKit's package.swift is defined as:
let simulatorSettings: [SwiftSetting] = [
.enableExperimentalFeature("Embedded"),
.unsafeFlags([
"-Xfrontend", "-disable-objc-interop",
"-Xfrontend", "-disable-stack-protector",
"-Xfrontend", "-function-sections",
"-Xfrontend", "-gline-tables-only",
"-Xcc", "-DTARGET_EXTENSION",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/include-fixed",
"-Xcc", "-I", "-Xcc", "\(gccIncludePrefix)/../../../../arm-none-eabi/include",
"-I", "\(playdateSDKPath)/C_API"
]),
]
let package = Package(
name: "PlaydateKitTemplate",
platforms: [.macOS(.v14)],
products: [.library(name: "PlaydateKitTemplate", targets: ["PlaydateKitTemplate"])],
dependencies: [
.package(name: "PlaydateKit", path: "../PlaydateKit"),
.package(name: "PDKitUtils", path: "../PDKitUtils")
],
targets: [
.target(
name: "PlaydateKitTemplate",
dependencies: [
.product(name: "PlaydateKit", package: "PlaydateKit"),
.product(name: "PDKitUtils", package: "PDKitUtils"),
],
swiftSettings: simulatorSettings
),
]
)
While the PDKutils package is defined as:
let package = Package(
name: "PDKitUtils",
platforms: [.macOS(.v14)],
products: [
.library(name: "PDKitUtils", targets: ["PDKitUtils"])
],
dependencies: [
.package(name: "PlaydateKit", path: "../PlaydateKit"),
],
targets: [
.target(
name: "PDKitUtils",
swiftSettings: simulatorSettings
),
// This is a copy of PDKitUtils it's a simple soft link to PDKitUtils folder, without the simulator settings
// it can be used in the test target
.target(name: "PDKitUtilsStd"),
.testTarget(
name: "PDKitUtilsTests",
dependencies: ["PDKitUtilsStd"]
)
]
)
This doesn't not work with multiple target in the same package Let me know what do you think and feel free to propose changes
This looks like an excellent start. Ideally we would support C packages, recursively compile packages, and support multiple targets in a package, but I think what you have so far covers 95% of what most people want. A single swift dependency with some common utils is probably most common.
I'll look through this a bit more but definitely open a PR and we can get this merged soon.
Hi, is the a way to add a package dependency to the template? If I add an external package or an internal target as dependency, Xcode recognize the dependency without error, but during compile I get always the "module XXX not found" error. Am I missing something?