Skip to content

Add --global flag to CLI for editing and viewing shared mirrors configuration#9950

Open
samuelmurray wants to merge 1 commit into
swiftlang:mainfrom
samuelmurray:add-cli-for-global-mirrors-config
Open

Add --global flag to CLI for editing and viewing shared mirrors configuration#9950
samuelmurray wants to merge 1 commit into
swiftlang:mainfrom
samuelmurray:add-cli-for-global-mirrors-config

Conversation

@samuelmurray
Copy link
Copy Markdown

Add --global flag to CLI for editing and viewing shared mirrors configuration

Motivation:

When working with mirrors in SPM, it's sometimes desirable to have a global (per-user) configuration, rather than a local (per-project). Support for a global mirrors configuration file was added in #3670, but no CLI tool was added for editing the global configuration file.
Similar to how the commands for editing the (package) registries configuration file have a --global flag, it feels natural that the commands for editing the mirrors configuration file have the same flag.
Closes #9947

Modifications:

Add a new flag --global to the following commands

  • swift package config set-mirror
  • swift package config unset-mirror
  • swift package config get-mirror

for interacting with the global mirrors configuration file.
When passing it to set-mirror or unset-mirror, the global configuration file is modified. When passing it to get-mirror, only the global configuration file is read.

Result:

Users can now easily create and maintain a global mirrors configuration file, which was a somewhat hidden feature before.

if !local.isEmpty {
if let local = try self.localMirrors?.get(), !local.isEmpty {
try self._mirrors.append(contentsOf: local)
return
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though unrelated to this PR, I'm curious as to why we return here, instead of merging the two configuration files. The code for package registries use both files, merging the information with local configuration having higher priority. https://github.com/swiftlang/swift-package-manager/blob/main/Sources/Workspace/Workspace%2BConfiguration.swift#L732-L738 Is there reason why we don't do it here?
Would it be considered breaking to change mirrors to also merge instead of disregarding the global configuration?
If you have a global configuration with many values, and want to add some override locally, it's a bit inconvenient (and someway unexpected, to me) that you have to duplicate all other global configuration locally.

@samuelmurray
Copy link
Copy Markdown
Author

When I ran swiftformat on the modified files, it changed a lot of unrelated code (re-organizing imports, removing public modifiers from functions, changing // comments to ///, adding line breaks and trailing commas), so I'm just hoping that my manual (or rather Xcode default) formatting is okay.
Could it be the case that you use a specific version of swiftformat? I got 0.61.0 from brew.

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented Apr 16, 2026

@samuelmurray : Thank you very much for the PR. Since this is modifying the SwiftPM command line interface, we should get feedback by the community via the Swift Evolution process.

Could you please start the process?

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented Apr 16, 2026

When I ran swiftformat on the modified files, it changed a lot of unrelated code (re-organizing imports, removing public modifiers from functions, changing // comments to ///, adding line breaks and trailing commas), so I'm just hoping that my manual (or rather Xcode default) formatting is okay. Could it be the case that you use a specific version of swiftformat? I got 0.61.0 from brew.

Formatting/Linting enforcement is tracked under #9397 tracks this, which is currently blocked on swiftlang/swift-format#1156.

@samuelmurray
Copy link
Copy Markdown
Author

@samuelmurray : Thank you very much for the PR. Since this is modifying the SwiftPM command line interface, we should get feedback by the community via the Swift Evolution process.

Could you please start the process?

Sure! Would you suggest starting with a pitch, or is this small enough that I can file a proposal PR directly?

@dschaefer2
Copy link
Copy Markdown
Member

I would start with a pitch, can be pretty small. The Build and Package Working Group is still trying to figure out how light weight a process we can put in place to get small changes like this through relatively quickly.

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented Apr 17, 2026

Sure! Would you suggest starting with a pitch, or is this small enough that I can file a proposal PR directly?

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented Apr 17, 2026

Sure! Would you suggest starting with a pitch, or is this small enough that I can file a proposal PR directly?

Yes. one step of Swift Evolution proposal is doing a pitch :)

@samuelmurray
Copy link
Copy Markdown
Author

Pitch thread created: https://forums.swift.org/t/pitch-add-cli-to-edit-global-configuration-of-mirrors/86091

@dschaefer2
Copy link
Copy Markdown
Member

Awesome. Thanks!

@samuelmurray
Copy link
Copy Markdown
Author

Proposal PR filed: swiftlang/swift-evolution#3265

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support global mirror configuration

3 participants