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

Package file for multiple modules #168

Closed
russhwolf opened this issue Dec 2, 2022 · 8 comments
Closed

Package file for multiple modules #168

russhwolf opened this issue Dec 2, 2022 · 8 comments

Comments

@russhwolf
Copy link
Contributor

This will need some experimentation. Probably it looks like a single top-level file which declares multiple artifacts, but need to do some testing and understand how it works.

@samhill303
Copy link
Contributor

We likely don't want to code actual package file generator. We want to test whether we can write a package file which can then reference packages for multiple modules

@samhill303 samhill303 changed the title Package file generation for multiple modules Package file for multiple modules Dec 20, 2022
@russhwolf
Copy link
Contributor Author

When consuming a remote package file from a url, it's not possible for it to reference packages at other file paths in the repo, so we can't just use our existing package file generation with a static parent package file.

@KatieGalvin KatieGalvin assigned kpgalligan and unassigned russhwolf Jan 10, 2023
@kpgalligan
Copy link
Collaborator

Played around with some ideas, but yeah, the original plan won't work. We can chat about some alternative ideas. While you can't reference sub-module Package.swift files in the way we were thinking, you can have more than one products in the main Package.swift file. For example, I did a little copy/paste:

// swift-tools-version:5.3
import PackageDescription

let remoteKotlinUrl = "https://maven.pkg.github.com/kpgalligan/KMMRules/kpgalligan/github/kmmrules/lessshared-kmmbridge/0.9.3/lessshared-kmmbridge-0.9.3.zip"
let remoteKotlinChecksum = "b2e0d6a24b8676f740153da82beabb258df72264c82c1e21718921db547314e1"
let packageName = "lessshared"

let remoteKotlinUrl2 = "https://maven.pkg.github.com/kpgalligan/KMMRules/kpgalligan/github/kmmrules/allshared-kmmbridge/0.9.3/allshared-kmmbridge-0.9.3.zip"
let remoteKotlinChecksum2 = "60ce4c9626926ada1e3a2d526151065790307829824353412a87e925a0f96aec"
let packageName2 = "allshared"

let package = Package(
    name: "moreshared",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(
            name: packageName,
            targets: [packageName]
        ),
        .library(
            name: packageName2,
            targets: [packageName2]
        ),
    ],
    targets: [
        .binaryTarget(
            name: packageName,
            url: remoteKotlinUrl,
            checksum: remoteKotlinChecksum
        )
        ,
        .binaryTarget(
            name: packageName2,
            url: remoteKotlinUrl2,
            checksum: remoteKotlinChecksum2
        )
        ,
    ]
)

When you add that, it'll ask which libraries you want to add:

Screen Shot 2023-01-10 at 8 31 20 PM

We're writing metadata to the build dir now (url, version, etc). In theory, we could write out package name and the checksum. Then, say, in the root dir, add an SPM config that points at each module we want to add to it. Then it could build the Package.swift file in one place, from the module builds. As I think about it, there's complications with how to make those module builds dependencies of the main build. Will need to think through it a bit.

I'm reluctant to try anything really "weird", with Package.swift files in module folders, and trying to get around the git management of SPM. From the official docs

Simply put: a package is a git repository with semantically versioned tags, that contains Swift sources and a Package.swift manifest file at its root.

That's the first thing it says about creating packages. I do believe they mean it!

Can think through maybe adding those other modules as module dependencies, but I have no idea how that intersects with task order. Can also look at settings plugins, but that seems like a whole different world.

Third option, treat it as a really special case. Implement the extra metadata discussed above, then change the current plugin to run even if it doesn't have a dependency manager. It'll make the metadata and upload the zips. Then, run a completely different plugin that we point at modules to collect and build the Package.swift file. Fairly hacky, but can be managed in CI, and would be an interim solution.

@kpgalligan kpgalligan removed their assignment Jan 11, 2023
@hanrw
Copy link
Contributor

hanrw commented Feb 12, 2024

same issue may related to this - build -> https://github.com/tddworks/openai-kotlin/actions/runs/7867481586/job/21463248748#step:8:1

Run touchlab/autoversion-finishrelease@main
  with:
    commitMessage: KMM SPM package release for 0.1.0
    tagMessage: KMM release version 0.1.0
    tagVersion: 0.1.0
    branchName: build-0.1.0
  env:
    PODSPEC_SSH_KEY_EXISTS: false
    MODULE: 
    JAVA_HOME: /Users/runner/hostedtoolcache/Java_Adopt_jdk/17.0.10-7/x6[4](https://github.com/tddworks/openai-kotlin/actions/runs/7867481586/job/21463248748#step:16:4)/Contents/Home
Error: fatal: pathspec './Package.swift' did not match any files

@hanrw
Copy link
Contributor

hanrw commented Apr 21, 2024

Hi @kpgalligan, is this issue fixed? i couldn't find any docs for this.

@kpgalligan
Copy link
Collaborator

No. I was closing old issues. I'll reopen it, but we're crushed with regular Touchlab work and other OSS stuff we're doing, so I don't think this will get any thought anytime soon. There's a new version of KMMBridge coming out pretty soon, but it's focused on other things. If there's some extra time, I'll put some thought into this again, but I wouldn't say there's much "extra time" till later in the year (I.E. after KotlinConf).

@kpgalligan kpgalligan reopened this Apr 21, 2024
@hanrw
Copy link
Contributor

hanrw commented Apr 21, 2024

I am just trying to figure out how to fix this issue.
and there are may two options:

  1. which you mention early like:
    we can get the sub-modules that support - kmmbridge
    val kmmbridgeProjects = project.subprojects.filter {
        it.plugins.hasPlugin("co.touchlab.kmmbridge:touchlab-kmmbridge")
    }
products: [
        .library(
            name: packageName,
            targets: [packageName]
        ),
        .library(
            name: packageName2,
            targets: [packageName2]
        ),
    ],
    targets: [
        .binaryTarget(
            name: packageName,
            url: remoteKotlinUrl,
            checksum: remoteKotlinChecksum
        )
        ,
        .binaryTarget(
            name: packageName2,
            url: remoteKotlinUrl2,
            checksum: remoteKotlinChecksum2
        )
        ,
    ]
  1. create a different tag for it(sub-module which with KMMBridge)

@kpgalligan
Copy link
Collaborator

Getting back to older issues. It looks like this PR provides a solution, although I would assume it's fairly manual. However, on recent doc review, those changes aren't in the current docs, so we'll need to update those.

If that PR is not sufficient for some common use cases, we can reopen this.

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

5 participants