Slim source distributions via SwiftPM registries: a use case for exact version matching

This is a motivating use case and a request for feedback, not an Evolution proposal for a new registry protocol, version ordering rule, or dependency override API.

Motivation

Swift packages sometimes contain substantial development-only content, such as test fixtures, golden images, benchmarks, or unrelated projects in a monorepo. These files are useful to package maintainers but may be unnecessary for applications consuming the package.

Downloading a source archive instead of cloning Git history (as explored in PR #9870) can reduce acquisition overhead, but it does not eliminate unnecessary files in the selected revision. A slim distribution addresses this separate problem by changing which files are included in the published archive.

One possible approach is to distribute a smaller source archive through a Swift Package Registry, without requiring upstream maintainers to change their repositories. An organization could derive and validate such an archive from a known upstream release, then publish it under a distinct immutable version identifier.

For example, an internal registry could publish 1.2.0+corp.0 and later 1.2.0+corp.1, both derived from upstream 1.2.0. A final application could explicitly select the desired distribution using .exact("1.2.0+corp.1").

This is another practical use case for PR #10410, which addresses exact version matching with build metadata. If this workflow is viable with just #10410 and existing registry features, that would be an ideal outcome, no new Evolution proposal needed.

Proposed workflow

Suppose an organization maintains a distribution pipeline for an upstream Git package:

Upstream Git: Library 1.2.0
          |
          v
Internal packaging pipeline (trim & validate)
          |
          +--> 1.2.0+corp.0
          +--> 1.2.0+corp.1  # Packaging correction
                     |
                     v
              Final application

The division of responsibilities is straightforward:

  • Distributor / internal registry owns: source trimming, package validation for supported targets, provenance, and publishing immutable releases.
  • SwiftPM owns: resolving dependency constraints, fetching the requested immutable archive, and applying configured integrity checks. SwiftPM does not judge source equivalence or decide which files to omit.

This workflow assumes that a registry can publish a valid source archive derived from an upstream release without requiring byte-for-byte equivalence to the corresponding Git checkout. The distributor is responsible for validating the reduced archive, including any manifest-referenced files needed by supported consumers.

For an application using a SwiftPM root manifest, the dependency declarations could look like this:

// Transitive dependencies (published upstream):
.package(url: "https://github.com/vendor/Library.git", from: "1.2.0")

// Final application (under consumer control):
.package(id: "internal.Library", exact: "1.2.0+corp.1")

1.2.0+corp.0 and 1.2.0+corp.1 share identical SemVer precedence, so both satisfy transitive version ranges admitting 1.2.0. However, when the final application requires .exact("1.2.0+corp.1"), a different immutable archive must not be selected.

This is not a general dependency override mechanism: the root's exact requirement must still satisfy all transitive constraints. An incompatible range or a transitive exact requirement for a different identifier would remain a conflict.

An important prerequisite: SwiftPM must successfully unify the upstream SCM dependency and the registry package into a single logical identity, for example through --replace-scm-with-registry. Whether this reliably works for the described dependency graph needs to be verified. Integration with Xcode-managed dependencies may also require separate validation.

Why PR #10410 matters

Under SemVer 2.0.0, build metadata must be ignored when comparing precedence. However, when a consumer explicitly requests an exact identifier, the complete version identifier distinguishes which immutable registry release was requested.

Today, SwiftPM's existing .exact(...) requirement can lose this distinction and match another published identifier at the same precedence position, potentially selecting the wrong archive.

The history of this fix is directly relevant:

Under the proposed #10410 behavior:

SemVer precedence:
  1.2.0 == 1.2.0+corp.0 == 1.2.0+corp.1

Complete parsed version-identifier identity:
  1.2.0 != 1.2.0+corp.0 != 1.2.0+corp.1

Final app requirement:
  .exact("1.2.0+corp.1") -> selects only 1.2.0+corp.1

Transitive range requirement:
  from: "1.2.0"           -> also admits 1.2.0+corp.1

If the distributor discovers a packaging error in 1.2.0+corp.0, it publishes a new immutable release, 1.2.0+corp.1. The application explicitly updates its .exact pin.

There is no need for corp.1 to sort after corp.0 in precedence, nor does this require a new override API or a separate distribution-revision axis in SwiftPM.

The essential requirement is that an explicitly selected version identifier consistently identifies the same immutable release throughout resolution, downloading, and subsequent builds. This is why #10410 matters beyond the semantics of a single version comparison.

Questions for maintainers and the community

  1. Use case alignment: Is this a reasonable use case for #10410? Specifically, selecting an immutable, derived source distribution by its complete version identifier while retaining ordinary SemVer range compatibility.
  2. SCM-to-registry identity mapping: Can existing SCM-to-registry identity mapping support this workflow? For example, when transitive dependencies reference the upstream Git URL but the final application pins a registry version.
  3. Boundary conditions: Are there other SwiftPM or registry constraints that would prevent this workflow, assuming the distributor independently handles packaging, validation, and provenance?

Key references

1 Like

One additional motivation for raising this use case alongside PR #10410 is the growing pressure on public developer infrastructure.

GitHub just announced that public repository clones over HTTPS may temporarily require authentication during unusual traffic. Maven Central has faced similar pressure from excessive automated downloads.

With increasingly automated CI and agentic development workflows, relying entirely on live access to public source hosts creates operational risks for enterprise builds.

An internal registry with cached or independently published source distributions could help reduce that dependency. PR #10410 would make it possible to pin a specific immutable derived release using its complete version identifier, which is particularly useful for the slim distribution scenario described here.

My thoughts, as a community member:

  1. Yes, I think this is reasonable. Internal registries can be useful for environments with restricted internet access, even without going into source trimming. It make a lot of sense that the internal registry should want to use some build metadata, as a registry should have immutable releases. From the specification:

Once a release has been published, any resources associated with that release, including its source archive, MUST NOT change.

So, any error that makes the version in the internal registry incompatible with the upstream version, would have to be published using new build metadata. And as you point out, the end user should be able to specify the "fixed" version from the registry.

  1. I would think yes? To my understanding, as long as the client is configured to use the registry, and the published version in the registry contains metadata connecting it to the git repo, it should work. The repositoryURLs metadata exists for this reason. I haven't looked into the SwiftPM code, but I would be surprised if using build metadata would prevent this.

Purely transitive dependencies would be a bit trickier. Say your app A depends on package B, which in turn depends on package C - but A has no direct dependency on C. If you publish both B and C to your internal registry, a user building A can access both B and C via the registry, thanks to SCM-to-registry mapping. And as you point out, it could choose which version (including build metadata) of B to use; but it can't do that for C, without adding an explicit dependency. So, if the registry has two versions of C differing only on build metadata, I don't see a good way for a user of A to specify which one to use.

However, this is not too dissimilar from if there were several versions of C (with SemVer-differing versions), some of which were known to contain bugs. Without adding a dependency from A to C, it would be difficult to resolve to a specific version of C.

Sorry, but can you summarize how this is different than what registries currently do? I thought registries already provided slim, build-necessary-only archives. Is that not the case? If it's not, it seems like that's a good first step, regardless of any other mapping or versioning concerns: packages should be able to publish optimized archives.

1 Like

I agree that publishing optimized archives through existing registries is the right starting point. Registry archives avoid downloading Git history, but they do not necessarily exclude tracked test fixtures, benchmarks, or other files unnecessary for downstream builds.

A registry standardizes how source archives are distributed, not how their contents are selected or optimized. The registry specification accepts a publisher-supplied source archive; it does not require automatic selection of build-necessary files.

The main use case I have in mind is a final application with dozens of package dependencies. Unnecessary content can accumulate across that dependency graph, and application teams cannot realistically coordinate packaging changes across every upstream project.

An organization-owned packaging pipeline could prepare, validate, and publish trimmed archives from upstream releases, then reuse those distributions across its applications and CI builds, without requiring upstream maintainers to change their packaging.

The connection to PR #10410 is exact version-identifier matching. If a packaging correction is needed, the organization could publish 1.2.0+corp.1 while keeping 1.2.0+corp.0 immutable. The application could then explicitly select .exact("1.2.0+corp.1"), assuming the exact-matching fix is applied.

In short, trimming belongs to the packaging pipeline; exact matching identifies the intended immutable release.

Thanks, that is a useful limitation to make explicit.

For the workflow I described, I think it is reasonable for the application to add an explicit exact requirement for C when it needs a particular packaging revision, even if C would otherwise only be a transitive dependency through B.

That requirement would still need to satisfy B's version constraints. Assuming SCM-to-registry mapping identifies both references to C as the same package, the application could explicitly select .exact("1.2.0+corp.1").

Without an explicit requirement, I would not expect +corp.1 to be preferred over +corp.0, since build metadata does not affect SemVer precedence.

For this use case, requiring an explicit dependency is an acceptable trade-off.

1 Like