swiftlang/swift-package-manager

Automatically generate version marker modules

stephencelis opened this issue · 3 comments

Description

SwiftSyntax maintains version marker modules:

https://github.com/apple/swift-syntax/blob/caab6bb82e0e81395551ec1032984f4b325f7a35/Package.swift#L150-L165

It does so to allow packages to adopt new upstream SwiftSyntax features in certain code paths and not force a SwiftSyntax upgrade to all downstream consumers.

This feature would be helpful to packages in general. A package may want access to a new feature of one of its dependencies but not force projects dependent on it to upgrade. If the dependency automatically had version marker modules available, this would be easy to do:

#if canImport(my_package_1_1_0)
  // Access APIs only available to my-package 1.1.0
#endif

Expected behavior

There should be a way to detect the version of a package dependency available.

Actual behavior

There is no way to do so unless the package does so manually (as SwiftSyntax does).

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

Swift 5.10

@ahoppen Not sure if you have opinions on this since you started maintaining those modules.

FWIW there is a PR to enable -user-module-version to be passed when building dependencies, which would allow you to do #if canImport(my_package, _version: 1.1.0): #7263

The proper way forward here would be to make canImport(:_version:) non-underscored and land that PR.

@ahoppen Oh that's great, thanks for the info!