Skip to content
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

Cannot add package dependency #54

Open
eugeniobaglieri opened this issue May 29, 2024 · 3 comments · May be fixed by #55
Open

Cannot add package dependency #54

eugeniobaglieri opened this issue May 29, 2024 · 3 comments · May be fixed by #55
Labels
enhancement New feature or request pdc Related to the pdc plugin

Comments

@eugeniobaglieri
Copy link
Contributor

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?

@eugeniobaglieri eugeniobaglieri changed the title Cannot add package dependencies Cannot add package dependency May 29, 2024
@finnvoor finnvoor added enhancement New feature or request pdc Related to the pdc plugin labels May 30, 2024
@finnvoor
Copy link
Owner

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.

@eugeniobaglieri
Copy link
Contributor Author

eugeniobaglieri commented May 30, 2024

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:

Screenshot 2024-05-30 alle 19 26 33

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

@finnvoor
Copy link
Owner

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.

@eugeniobaglieri eugeniobaglieri linked a pull request May 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pdc Related to the pdc plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants