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

Allow Package.swift not at the root of the repository #5768

Closed
JonasVautherin opened this issue Sep 16, 2022 · 5 comments
Closed

Allow Package.swift not at the root of the repository #5768

JonasVautherin opened this issue Sep 16, 2022 · 5 comments

Comments

@JonasVautherin
Copy link

JonasVautherin commented Sep 16, 2022

Description

A Swift package must be released as a git repository with a Package.swift file at its root, and with a specific layout.

There has been discussions about allowing a custom layout years ago (see #5339), but this is slightly different.

Say I have a library that I provide in multiple languages (e.g. c++, java, python, swift), and I have all my code in one repository, like this:

.
├── README.md
├── cpp/
├── java/
├── py/
└── swift/ 

That works for all but swift, because it wants to be at the root. Wouldn't it make sense to allow for that? Then inside of swift/ it would just be a normal swift package (with Package.swift and the required directory layout). It would just not sit at the root.

It feels like it would not require very big changes in SwiftPM, and the syntax for using such a package could be something like:

.package(url: /* package url */, subdir: "swift", from: "1.0.0"),

Would that make any sense at all?

@tomerd
Copy link
Contributor

tomerd commented Sep 19, 2022

@elsh @neonichu @abertelrud wdyt?

@neonichu
Copy link
Contributor

+1 in general, but I think there are some issues that need to be carefully considered:

  • can multiple packages be referred to like this from the same repository in a single package graph?
  • what implications for the package identity follow from this?

@JonasVautherin
Copy link
Author

May I ask how the package identity works? As far as I know, it works for git repositories and for local folders. Is that identity somehow the "path" to the package?

Also is there a change I could possibly contribute that, or does it look like a complex, fundamental contribution? Would you have pointers to where I should look in the code if I wanted to try it?

@neonichu
Copy link
Contributor

In the common case, the package identity is basically the last path component of the Git URL or local path. My guess is that it would be good to combine subdir and last path component of the URL for these new dependencies, but I haven't fully thought through all implications.

I can provide some pointers, at a high level, we'd need to incorporate the new parameter into the PackageDescription model and adjust the code which locates sources and the manifest to use it. I'm not 100% sure how well encapsulated the path handling is, it might be the case that we just need to change very few callosities or the changes may be all over the place.

In general, since this is a change with impact on the public API of the package manifest, it would need to go through the evolution process. Typically, that would start with a pitch on the Swift forums and later require a formal proposal + implementation.

@JonasVautherin
Copy link
Author

Thanks for the info! I pitched it here: https://forums.swift.org/t/allow-package-swift-to-not-be-at-the-root-of-the-repository/60431

I guess the discussion on the forum can replace this one, so I'll close it.

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

No branches or pull requests

3 participants