You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for read me.
I don't know if it's possible to compile and generate the cli-tool and attach it to the version tag like, for example, https://github.com/nicklockwood/SwiftFormat has,
I think lots of people do not use the official swift format because is a pain to use it in CIs and teammates computers.
You have to build it and then save it on a cache ... Or rebuild all times in new computers. The use of SPM is not straight forward in all cases.
changed the title [-]Feature: Generate command line for linux and Mac, and publish it on release note[/-][+]Feature: Generate command line for linux and Mac, and publish it on release TAG[/+]on Oct 13, 2022
changed the title [-]Feature: Generate command line for linux and Mac, and publish it on release TAG[/-][+]Feature: Generate command line for linux and Mac and even for windows, and publish it on release TAG[/+]on Oct 13, 2022
I'm not an expert on swift build system, so I'm not sure if I can provide the best help here. But, regardless if this helps, I'm happy to share my experience.
The first problem we wanted to solve was how to build swift-format, especially since we needed a feature on main that was not yet released. We didn't want to directly use main, as we were afraid of changes in swift-format that would break our workflow. But even without that problem, building swift-format was not always successful (especially on CI). To solve this, we forked swift-format and committed `Package.resolved. See https://github.com/val-lang/swift-format. We always have a controlled version of swift-format, and that always builds.
We depend on swift-format in our Package.swift. Yes, builds are slower (especially for clean builds), but that's ok for us. Please note that for the CI job, we use a debug build of swift-format, as the compilation in release is much slower..
The second major hurdle we had to jump is executing swift-format for our code. We tried using the two build plugins provided in swift-format repo, but they were too slow to run. With a debug build, running them on all the targets could take almost a minute on my machine. Not a great experience :)
We wrote a shell script that would execute swift-format by directories, not by target. In this, we had a shortcut to search for the swift-format executable in known locations. If that fails, we just run swift-format through swift run -c <build_mode> swift-format <args>. This works well in all our needed cases, including CI. See script at: https://github.com/val-lang/val/blob/main/Tools/run-swift-format.sh.
We never tested this for windows builds (we had many problems with our CI Windows build, until we disabled it -- way too unstable). The CI job runs on Ubuntu, and some of us run the tool on Mac.
swift-format is included in the swift.org toolchains you can download from http://swift.org/install/macos/ and is also included in the Xcode 16 Beta toolchain. I assume that you have some toolchain installed on your CI system, which means that you should have swift-format as well now. Does that satisfy your needs?
Can I run swiftformat if the CI has swift installed? If yes, how can I run it?
If not, is there any way to download swiftformat (notice only swiftformat) per version without building it each time on the machine, and without building it on my side, that is to say, is there any binary distro available?
Only the "beta Xcode 16 Beta toolchain" includes it, isn't it? In this case, installing only Xcode 16 does not make available swift-format directly from the terminal, or am I wrong?
Instructions on this new way to install and use swift-format should be on the readme file.
@jesus-mg-ios I was able to run it by selecting the beta CLI toolchain in Xcode > Preferences > Locations > Command Line Tools, then running swift format
Can I run swiftformat if the CI has swift installed? If yes, how can I run it?
If not, is there any way to download swiftformat (notice only swiftformat) per version without building it each time on the machine, and without building it on my side, that is to say, is there any binary distro available?
Only the "beta Xcode 16 Beta toolchain" includes it, isn't it? In this case, installing only Xcode 16 does not make available swift-format directly from the terminal, or am I wrong?
If you have Xcode 16 selected using xcode-select, you should be able to run it using swift format (no space). The swift-format binary should be available in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format for Xcode 16. Alternatively you can run DEVELOPER_DIR=/Applications/Xcode-beta.app swift format, which should effectively set your current Xcode for the current command to the Xcode 16 beta.
On Linux and macOS, swift-format is part of the open source toolchain releases.
Instructions on this new way to install and use swift-format should be on the readme file.
That is true. If you would like to open a PR to fix the README, that would be a very welcome contribution to the project.
Activity
[-]Feature: Generate command line for linux and Mac, and publish it on release note[/-][+]Feature: Generate command line for linux and Mac, and publish it on release TAG[/+][-]Feature: Generate command line for linux and Mac, and publish it on release TAG[/-][+]Feature: Generate command line for linux and Mac and even for windows, and publish it on release TAG[/+]jesus-mg-ios commentedon Oct 18, 2022
#430 #378 #377 Could be resolved if repository owner provides a cli binary in release Tags
jesus-mg-ios commentedon Mar 9, 2023
@dabrahams any thoughts about that?
dabrahams commentedon Mar 9, 2023
I don't, but I bet @lucteo has useful input.
lucteo commentedon Mar 10, 2023
Hi
I'm not an expert on swift build system, so I'm not sure if I can provide the best help here. But, regardless if this helps, I'm happy to share my experience.
The first problem we wanted to solve was how to build swift-format, especially since we needed a feature on main that was not yet released. We didn't want to directly use main, as we were afraid of changes in swift-format that would break our workflow. But even without that problem, building swift-format was not always successful (especially on CI). To solve this, we forked swift-format and committed `Package.resolved. See https://github.com/val-lang/swift-format. We always have a controlled version of swift-format, and that always builds.
We depend on swift-format in our
Package.swift
. Yes, builds are slower (especially for clean builds), but that's ok for us. Please note that for the CI job, we use a debug build of swift-format, as the compilation in release is much slower..The second major hurdle we had to jump is executing swift-format for our code. We tried using the two build plugins provided in swift-format repo, but they were too slow to run. With a debug build, running them on all the targets could take almost a minute on my machine. Not a great experience :)
We wrote a shell script that would execute swift-format by directories, not by target. In this, we had a shortcut to search for the swift-format executable in known locations. If that fails, we just run swift-format through
swift run -c <build_mode> swift-format <args>
. This works well in all our needed cases, including CI. See script at: https://github.com/val-lang/val/blob/main/Tools/run-swift-format.sh.We never tested this for windows builds (we had many problems with our CI Windows build, until we disabled it -- way too unstable). The CI job runs on Ubuntu, and some of us run the tool on Mac.
Hope that helps
Best regards,
LucTeo
Gustl22 commentedon Aug 19, 2023
Possible pipeline:
https://github.com/mtgto/docker-swift-format/tree/main
jesus-mg-ios commentedon Mar 11, 2024
Any updates on it?
ahoppen commentedon Apr 23, 2024
Tracked in Apple’s issue tracker as rdar://126948314
jesus-mg-ios commentedon Jun 9, 2024
Any updates on it? Would be super nice to get it in a short time. I think swift-format could grow in audience if this distribution were added.
ahoppen commentedon Jun 12, 2024
swift-format
is included in the swift.org toolchains you can download from http://swift.org/install/macos/ and is also included in the Xcode 16 Beta toolchain. I assume that you have some toolchain installed on your CI system, which means that you should haveswift-format
as well now. Does that satisfy your needs?jesus-mg-ios commentedon Jun 12, 2024
@ahoppen thanks for your comment. Things that maybe I didn't catch, because as far I can see, docs don't point to your observation -> https://github.com/apple/swift-format?tab=readme-ov-file#getting-swift-format
peterkos commentedon Jun 14, 2024
@jesus-mg-ios I was able to run it by selecting the beta CLI toolchain in
Xcode > Preferences > Locations > Command Line Tools
, then runningswift format
ahoppen commentedon Jun 17, 2024
If you have Xcode 16 selected using
xcode-select
, you should be able to run it usingswift format
(no space). The swift-format binary should be available in/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format
for Xcode 16. Alternatively you can runDEVELOPER_DIR=/Applications/Xcode-beta.app swift format
, which should effectively set your current Xcode for the current command to the Xcode 16 beta.On Linux and macOS, swift-format is part of the open source toolchain releases.
That is true. If you would like to open a PR to fix the README, that would be a very welcome contribution to the project.