Skip to content

Allow static linking of the SwiftPMDataModel target #3520

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

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented May 31, 2021

Motivation:

The SwiftPMDataModel target can't be linked statically at the moment, because it uses type: .dynamic explicitly in the Package.swift manifest file. Dynamic linking makes distribution of CLI tools relying on SwiftPM much harder, since you have to redistribute this dynamic libraries too, with little to no benefit.

Modifications:

New SwiftPMDataModel-auto target is added, which uses the same approach as the SwiftPM-auto target of not specifying the linking type explicitly.

Result:

Tools that utilize the SwiftPM package can use the SwiftPMDataModel-auto target for static linking instead of SwiftPMDataModel.

@MaxDesiatov

This comment has been minimized.

@abertelrud
Copy link
Contributor

This looks good to me, although I wonder if it would make sense to factor out the list of dependencies into a separate array to make sure that they stay in sync. I suppose the same is true for the existing libSwiftPM. I guess another option would be to dynamically add the "auto" versions of the products using code below the main Package() stanza, deriving the "-auto" form from each of a set of products (or perhaps the other way around, deriving a dynamic-library product from each library named with "-auto"). Not sure if you want to get that creative with this particular PR, but factoring the array seems like it would be good because otherwise they can easily get out of sync.

It's unfortunate that we need both products at all, but until we allow clients to control how dependencies are built, we probably do need to keep both.

@abertelrud abertelrud self-assigned this Jun 1, 2021
@MaxDesiatov MaxDesiatov force-pushed the maxd/SwiftPMDataModel-auto branch 3 times, most recently from 095b33e to d4df98b Compare June 1, 2021 16:19
@MaxDesiatov
Copy link
Contributor Author

@abertelrud thanks, that's a great suggestion, which is now implemented.

@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud
Copy link
Contributor

Thanks, @MaxDesiatov, this looks like a more robust approach to me. @neonichu or @tomerd any concerns here? I think the greatest danger would have been separate hardcoded lists of targets.

@neonichu
Copy link
Contributor

neonichu commented Jun 1, 2021

While we are at making things more robust, should we also express "SwiftPM" as "SwiftPMDataModel" plus the three build related targets?

@abertelrud
Copy link
Contributor

While we are at making things more robust, should we also express "SwiftPM" as "SwiftPMDataModel" plus the three build related targets?

That does assume that SwiftPM will always be a superset of SwiftPMDataModel, which I suppose is a safe bet. And you're only talking about target lists, right, and not actually having one product depend on another?

@neonichu
Copy link
Contributor

neonichu commented Jun 1, 2021

That does assume that SwiftPM will always be a superset of SwiftPMDataModel, which I suppose is a safe bet.

That was the intent of the split, right? I guess it could still change in the future, but I think until then this would make sense and could avoid issues if someone is only testing one of the products.

And you're only talking about target lists, right, and not actually having one product depend on another?

Yep, only the target list. We do not support depending on products from the same package today, so that would require further changes.

@MaxDesiatov
Copy link
Contributor Author

While we are at making things more robust, should we also express "SwiftPM" as "SwiftPMDataModel" plus the three build related targets?

Sorry, I'm not sure I understand. How would that look like?

@tomerd
Copy link
Contributor

tomerd commented Jun 2, 2021

While we are at making things more robust, should we also express "SwiftPM" as "SwiftPMDataModel" plus the three build related targets?

I think @neonichu is suggesting that instead of repeating the definition of the shared parts between SwiftPM and SwiftPMDataModel we would do something like:

let swiftPM = (name: "SwiftPM" , targets: [...])
let swiftPMDataModel = (name: "SwiftPMDataModel" , targets: swiftPM.targets + [...])
let autoProducts = [swiftPM, swiftPMDataModel]

@tomerd
Copy link
Contributor

tomerd commented Jun 2, 2021

@neonichu or @tomerd any concerns here? I think the greatest danger would have been separate hardcoded lists of targets.

yea this approach seems cleaner and safer

I do have one question tho: what is SwiftPMDataModel used for in the first place / why do we have this product? cc @yim-lee

@abertelrud
Copy link
Contributor

@neonichu or @tomerd any concerns here? I think the greatest danger would have been separate hardcoded lists of targets.

yea this approach seems cleaner and safer

I do have one question tho: what is SwiftPMDataModel used for in the first place / why do we have this product? cc @yim-lee

SwiftPMDataModel is the subset of SwiftPM that includes just its data model, allowing some clients (such as IDEs) that use SwiftPM's data model but not its build system to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here, though that could break some clients.

@MaxDesiatov MaxDesiatov force-pushed the maxd/SwiftPMDataModel-auto branch from d4df98b to 7dd4894 Compare June 2, 2021 20:31
@MaxDesiatov MaxDesiatov force-pushed the maxd/SwiftPMDataModel-auto branch from 7dd4894 to 49b04da Compare June 2, 2021 20:33
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@MaxDesiatov
Copy link
Contributor Author

Thanks for the clarification. I've updated the PR and added comments to these new product declarations based on your feedback, if you don't mind.

@neonichu neonichu merged commit 50c958b into main Jun 2, 2021
@neonichu neonichu deleted the maxd/SwiftPMDataModel-auto branch June 2, 2021 23:36
@MaxDesiatov
Copy link
Contributor Author

As far as I'm aware, this PR can't break things for macOS builds, as those rely on CMake, but on other platforms allowing static linking of this product would be a great improvement for for tools that rely on SwiftPM. Given that this change is not too disruptive, could it be accepted in the 5.5 release branch? Is it worth creating a PR to chery-pick it to that branch?

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

Successfully merging this pull request may close these issues.

4 participants