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

[Question] Any plans to add SPM packages support? #629

Open
Helloyunho opened this issue Sep 8, 2021 · 7 comments
Open

[Question] Any plans to add SPM packages support? #629

Helloyunho opened this issue Sep 8, 2021 · 7 comments

Comments

@Helloyunho
Copy link

I just tried using a package called Defaults, I added it to the Package.swift file and ran the build. But it seems like Orion doesn't support SPM packages yet.

So, any plans to add SPM packages support? or am I doing wrong?

Here's the Package.swift file:

// ...

let package = Package(
    name: "PreferencesEditor",
    platforms: [.iOS("12.2")],
    products: [
        .library(
            name: "PreferencesEditor",
            targets: ["PreferencesEditor"]
        ),
    ],
    dependencies: [
        .package(name: "Defaults", url: "https://github.com/sindresorhus/Defaults", .upToNextMajor(from: "5.0.0"))
    ],
    targets: [
        .target(
            name: "PreferencesEditorC",
            cSettings: [.unsafeFlags(cFlags)],
            cxxSettings: [.unsafeFlags(cxxFlags)]
        ),
        .target(
            name: "PreferencesEditor",
            dependencies: ["PreferencesEditorC", "Defaults"],
            swiftSettings: [.unsafeFlags(swiftFlags)]
        ),
    ]
)

And here's the error log:

==> Copying resource directories into the bundle wrapper…
==> Compiling Sources/PreferencesEditor/RootListController.swift (arm64e)…
==> Compiling Sources/PreferencesEditor/RootListController.swift (arm64)…
Sources/PreferencesEditor/RootListController.swift:3:8: error: no such module 'Defaults'
import Defaults
       ^

Sources/PreferencesEditor/RootListController.swift:3:8: error: no such module 'Defaults'
import Defaults
       ^

make[3]: *** [/Users/helloyunho/theos/makefiles/instance/rules.mk:332: /Users/helloyunho/preferenceseditor/preferenceseditor/.theos/obj/debug/arm64e/.swift-stamp] Error 1
make[2]: *** [/Users/helloyunho/theos/makefiles/instance/bundle.mk:37: /Users/helloyunho/preferenceseditor/preferenceseditor/.theos/obj/debug/arm64e/PreferencesEditor.bundle/PreferencesEditor] Error 2
make[2]: *** Waiting for unfinished jobs....
make[3]: *** [/Users/helloyunho/theos/makefiles/instance/rules.mk:332: /Users/helloyunho/preferenceseditor/preferenceseditor/.theos/obj/debug/arm64/.swift-stamp] Error 1
make[2]: *** [/Users/helloyunho/theos/makefiles/instance/bundle.mk:37: /Users/helloyunho/preferenceseditor/preferenceseditor/.theos/obj/debug/arm64/PreferencesEditor.bundle/PreferencesEditor] Error 2
make[1]: *** [/Users/helloyunho/theos/makefiles/instance/bundle.mk:26: internal-bundle-all_] Error 2
make: *** [/Users/helloyunho/theos/makefiles/master/rules.mk:162: PreferencesEditor.all.bundle.variables] Error 2
@Helloyunho
Copy link
Author

Oof, guess I need to wait for a bit then

@uroboro
Copy link
Member

uroboro commented Sep 8, 2021

@kabiroberai published Orion as v0.9 to have developer feedback so Orion can be finalized as a tool in itself. Once that’s done, we can start planning support for SPM

@kabiroberai
Copy link
Member

Since 1.0.0 is now in the process of being released I think it's a good time to start thinking about this. I'll transfer this issue to the main Theos repo first since it's applicable to Theos as a whole.

@kabiroberai kabiroberai transferred this issue from theos/orion Nov 16, 2021
@kabiroberai
Copy link
Member

Right – so the thing about SPM (and dependencies in general) is that they're tricky to use correctly with tweaks, since tweaks inhabit another process' address space. This means that there are a few atypical considerations involved:

  • What if the host app already has a copy of the same framework?
  • What if another tweak depends on the same framework?
  • And what if the host app/other tweak uses a different version of the framework than the one you're trying to use?

These issues are partly mitigated by dyld's two-level namespace, but Objective-C classes don't respect the two-level namespace at all and Swift classes care more about the module name, which will indeed end up clashing if you're using the same framework.

For these reasons, it's a non-goal for Theos to make it too easy to add third-party deps to tweaks; however, this is still something we should implement for the goal of Theos for the App Store (#286).

At the moment, the easiest option is probably to turn the dependency into an xcframework using something like swift-create-xcframework, extract the desired .framework, and link against it as you would with any other framework while using Theos. You'll also have to add the framework to your deb, for example by placing it in layout/Library/Frameworks/.

Again, you'll need to make sure that the aforementioned issues are taken care of if you're using this approach. A better option for a small-ish framework like Defaults would be to include the source files in your tweak itself, with something like git submodules.

@NSAntoine
Copy link

@kabiroberai what about libraries such as swift-argument-parser? Would you recommend just including it’s source?

@kabiroberai
Copy link
Member

For swift-argument-parser in particular it's likely you'd be using it in a standalone tool, which falls into the same bucket as full apps. In either case Theos should support SPM packages, but doesn't yet. In the meanwhile, either including its source or using the xcframework approach should work fine. You could even build it as a static library with Xcode and then link that using Theos.

@zx500xl
Copy link

zx500xl commented Sep 12, 2022

At the moment, the easiest option is probably to turn the dependency into an xcframework using something like swift-create-xcframework, extract the desired .framework, and link against it as you would with any other framework while using Theos. You'll also have to add the framework to your deb, for example by placing it in layout/Library/Frameworks/.

I tried to use this approach for tweak but didn't it work so far. I built xcframework from package added it to tweak, it compiled well, but the tweak doesn't even load (without new framework it loads well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@uroboro @zx500xl @Helloyunho @kabiroberai @NSAntoine and others