Skip to content
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

[Windows] Run swift-format tests from build.ps1 #76900

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 7, 2024

The basic idea is that we build all libraries for the executable that will be included in the toolchain using CMake. swift-format then has a mode in its Package manifest that allows it to build just the test and test support targets, requiring all search paths to find those libraries to be passed in. We use that to only build swift-format's test using SwiftPM and re-use all the libraries that were already built using CMake.

Building the test targets and running the tests takes about 1 minute locally on my machine.

@ahoppen
Copy link
Member Author

ahoppen commented Oct 7, 2024

https://github.com/swiftlang/swift-format

@swift-ci Please build toolchain Windows

@ahoppen
Copy link
Member Author

ahoppen commented Oct 8, 2024

swiftlang/swift-format#841

@swift-ci Please build toolchain Windows

ahoppen added a commit to ahoppen/swift-installer-scripts that referenced this pull request Oct 8, 2024
@ahoppen
Copy link
Member Author

ahoppen commented Oct 8, 2024

swiftlang/swift-format#841
swiftlang/swift-installer-scripts#343

@swift-ci Please build toolchain Windows

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Please provide a before and after comparison for the file sizes. This was a HUGE regression the last time I checked. It was about 50MiB larger.

@compnerd
Copy link
Member

compnerd commented Oct 8, 2024

(1) it means we don't need to build SwiftFormat twice
(2) we test the same build that is also included in the toolchain

Sure

(3) it allows us to remove the CMake build of swift-format.

We cannot do this yet. SPM does not properly link the binary, so there are still issues with it and until that is fixed, I don't think that we should be shipping the SPM built version.

@ahoppen
Copy link
Member Author

ahoppen commented Oct 8, 2024

Please provide a before and after comparison for the file sizes. This was a HUGE regression the last time I checked. It was about 50MiB larger.

Sorry, I meant to include these but then forgot. For a local toolchain build I get

  • In a 6.0.0 development toolchain I downloaded and have installed in AppData\Local: swift-format.exe with 187KB + SwiftFormat.dll with 1,894KB = 2,081KB
  • In the toolchain I downloaded from this CI run swift-format.exe is 2,146 KB
  • With the old CMake-based build: swift-format.exe with 763KB + SwiftFormat.dll with 7.974KB = 8,737KB
  • With the new SwiftPM-based build: swift-format.exe with 8,326KB

I don’t know where the difference between my local toolchain build and the toolchain downloaded from CI comes from but the gist is that sizes are very comparable (65KB increase in downloaded toolchains size, 411KB size reduction in local builds).

Note that we are not rebuilding and statically linking all the dependencies here. We are only building swift-format and dynamically linking against the already built versions of swift-syntax, swift-markdown etc.

We cannot do this yet. SPM does not properly link the binary, so there are still issues with it and until that is fixed, I don't think that we should be shipping the SPM built version.

Can you clarify what you mean by SwiftPM not linking correctly? From what I’ve tested so far swift-format.exe built using SwiftPM launches just fine.

@ahoppen
Copy link
Member Author

ahoppen commented Oct 8, 2024

swiftlang/swift-format#841
swiftlang/swift-installer-scripts#343

@swift-ci Please build toolchain Windows

@compnerd
Copy link
Member

compnerd commented Oct 8, 2024

Note that we are not rebuilding and statically linking all the dependencies here. We are only building swift-format and dynamically linking against the already built versions of swift-syntax, swift-markdown etc.

This is ... unexpected. How do we accomplish this? I'd love to see this adopted in SPM as well!

Can you clarify what you mean by SwiftPM not linking correctly? From what I’ve tested so far swift-format.exe built using SwiftPM launches just fine.

Sure - the linker spew that you get when building is due to the binary being miscompiled but the linker workaround it. This is something that @dschaefer2 is planning on looking into and I think that we should wait for that.

@dschaefer2
Copy link
Member

Can you clarify what you mean by SwiftPM not linking correctly? From what I’ve tested so far swift-format.exe built using SwiftPM launches just fine.

Sure - the linker spew that you get when building is due to the binary being miscompiled but the linker workaround it. This is something that @dschaefer2 is planning on looking into and I think that we should wait for that.

Yup, working on that right now. Almost have clean linking happening :).

@ahoppen
Copy link
Member Author

ahoppen commented Oct 8, 2024

This is ... unexpected. How do we accomplish this? I'd love to see this adopted in SPM as well!

I am manually specifying all the search paths with which SwiftPM can find the dynamic libraries built by the previous build stages and explicitly remove all explicit dependencies from swift-format’s package manifest through an environment variable.

https://github.com/swiftlang/swift/pull/76900/files#diff-c861caa2fcc08744108e542ca836b07e342f537566e8c5f7a21a0e9125331ed9R2373-R2389

The basic idea is that we build all libraries for the executable that will be included in the toolchain using CMake. swift-format then has a mode in its Package manifest that allows it to build just the test and test support targets, requiring all search paths to find those libraries to be passed in. We use that to only build swift-format's test using SwiftPM and re-use all the libraries that were already built using CMake.
@ahoppen
Copy link
Member Author

ahoppen commented Oct 11, 2024

I pivoted the approach around a little. Let’s decouple the discussion about how to build the swift-format executable from running tests.

I updated this PR to rely on CMake building everything needed for the toolchain. We then only build the test and test support targets in swift-format using SwiftPM with various search paths to make SwiftPM pick up the pre-built modules and libraries.

@ahoppen ahoppen changed the title [Windows] Build swift-format using SwiftPM from build.ps1 and run tests [Windows] Run swift-format tests from build.ps1 Oct 11, 2024
@ahoppen
Copy link
Member Author

ahoppen commented Oct 12, 2024

#76900

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Oct 12, 2024

swiftlang/swift-format#851

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Oct 13, 2024

swiftlang/swift-format#851

@swift-ci Please smoke test macOS

@ahoppen
Copy link
Member Author

ahoppen commented Oct 13, 2024

swiftlang/swift-format#851

@swift-ci Please smoke test Linux

@ahoppen
Copy link
Member Author

ahoppen commented Oct 14, 2024

Merging this so we get test coverage for swift-format on Windows and because this has no risk to the toolchain build because it doesn’t change how swift-format.exe is built. Happy to address any further feedback in a follow-up PR.

@ahoppen ahoppen merged commit e4725d9 into swiftlang:main Oct 14, 2024
3 checks passed
@ahoppen ahoppen deleted the swift-format-windows-build branch October 14, 2024 21:30
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.

3 participants