Skip to content

Fix extraction of Swift SDKs on Windows#9843

Merged
dschaefer2 merged 8 commits intoswiftlang:mainfrom
dschaefer2:winSwiftSDKs
Mar 31, 2026
Merged

Fix extraction of Swift SDKs on Windows#9843
dschaefer2 merged 8 commits intoswiftlang:mainfrom
dschaefer2:winSwiftSDKs

Conversation

@dschaefer2
Copy link
Copy Markdown
Member

@dschaefer2 dschaefer2 commented Mar 23, 2026

First, make sure we're using the Windows tar to extract archives on Windows. It's based on libarchive so also handles zip files. Move hardcoded use of the ZipArchiver to the UniversalArchiver so the platform logic can kick in.

Second fix the args of the extract command to properly extract the Swift SDK tarballs.

Also SandboxTests was calling tar directly which breaks when running the tests in bash.

First, make sure we're using the Windows tar to extract archives
on Windows. It's based on libarchive so also handles zip files.

Second fix the args of the extract command to properly extract
the Swift SDK tarballs.

Also SandboxTests was calling tar directly which breaks when
running the tests in bash.
@dschaefer2
Copy link
Copy Markdown
Member Author

@swift-ci please test

var tarPath: PWSTR?
defer { CoTaskMemFree(tarPath) }
let hr = withUnsafePointer(to: FOLDERID_System) { id in
SHGetKnownFolderPath(id, DWORD(KF_FLAG_DEFAULT.rawValue), nil, &tarPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please refactor this into a free function? Also, you can parameterize the folder ID so it's generalizable. See https://github.com/swiftlang/swift-build/blob/main/Sources/SWBWindowsPlatform/KnownFolders.swift

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure. Should I just clone the swift-build one? This probably should be somewhere where tools can share, but for now...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I'd just copy the swift-build one for now.

Copy link
Copy Markdown
Contributor

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

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

Note to our future selves looking at this years down the road: this was specifically about fixing extraction when using the Git Bash shell, which caused a different, incompatible copy of tar.exe to be present in the path, and this patch makes it always use the copy from System32.

@dschaefer2
Copy link
Copy Markdown
Member Author

The real fix was actually to stop hardcoding the compression format when extracting with tar so that the Windows tar command would handle zip files properly.

@dschaefer2
Copy link
Copy Markdown
Member Author

Our future selves should merge the Zip and Tar archivers so that we standardize on libarchive where we can.

@jakepetroules
Copy link
Copy Markdown
Contributor

Where are you finding .zip based Swift SDKs, btw? All of our official ones are .tar.gz.

@dschaefer2
Copy link
Copy Markdown
Member Author

Ah, true. You are correct, I ran into this running the tests on Windows and making sure we're running the right tar. The registry archives and prebuilts are zips. We'll always have a mix.

@dschaefer2
Copy link
Copy Markdown
Member Author

@swift-ci please test windows

@dschaefer2 dschaefer2 merged commit 0ccd27d into swiftlang:main Mar 31, 2026
61 checks passed
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.

2 participants