Skip to content

Conversation

@ShikiSuen
Copy link

@ShikiSuen ShikiSuen commented Apr 17, 2025

This PR targets the main branch.

  • On Windows, it's not guaranteed that USERPROFILE is equivalent to %SYSTEMDRIVE%\Users\%USERNAME%. It is therefore possible that UserDefaults tries to write to a non-existent location, in which case it will never work. When this happens, all writes silently no-op.

  • This PR uses the Shell API SHGetKnownFolderPath to programmatically get the location of %LOCALAPPDATA% instead of manually building the path.

@ShikiSuen
Copy link
Author

cc @compnerd Could you please take a look at this PR to see whether there are anything else to fix?

@ShikiSuen
Copy link
Author

Could anyone please review this?

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.

Sorry about the delay. This looks good to me!

@compnerd
Copy link
Member

compnerd commented Jun 2, 2025

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Jun 2, 2025

11:32:19  /home/build-user/build/buildbot_linux/none-swift_package_sandbox_linux-x86_64/tests/test-foundation-package/Output/test-foundation-networking-static-stdlib.test.tmp/test-foundation-networking | /home/build-user/build/buildbot_linux/llvm-linux-x86_64/bin/FileCheck /home/build-user/swift-integration-tests/test-foundation-package/test-foundation-networking-static-stdlib.test
11:32:19  # executed command: /home/build-user/build/buildbot_linux/none-swift_package_sandbox_linux-x86_64/tests/test-foundation-package/Output/test-foundation-networking-static-stdlib.test.tmp/test-foundation-networking
11:32:19  # .---command stderr------------
11:32:19  # | generic witness table at 0x55f2db72de98 contains out-of-bounds requirement descriptor 0x11
11:32:19  # `-----------------------------
11:32:19  # error: command failed with exit status: -6

This seems unlikely to be related ... @slavapestov any idea what this might be about?

@compnerd
Copy link
Member

compnerd commented Jun 5, 2025

@swift-ci please test

@ShikiSuen
Copy link
Author

Could anyone please take a look at this PR to see what is going on?

@ShikiSuen
Copy link
Author

Swift 6.2 is released for months and this PR is till gets ignored.
cc @compnerd for attention.

@compnerd
Copy link
Member

compnerd commented Dec 1, 2025

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Dec 1, 2025

@ShikiSuen I think that we just need to get this through the CI systems, but this should be good to go otherwise. Please create a new PR with the same changes for the release/6.3 branch

@compnerd compnerd changed the title [Continued] Use SHGetKnownFolderPath to get path to localappdata for current user Windows: Use SHGetKnownFolderPath to compute LocalAppData Dec 1, 2025
@brianmichel
Copy link

Oh @ShikiSuen we'd love to use this! Thank you for the fix, can't wait to see it in 6.3!

@compnerd
Copy link
Member

compnerd commented Dec 1, 2025

@swift-ci please test Windows platform

@ShikiSuen ShikiSuen changed the base branch from main to release/6.3 December 2, 2025 03:11
@ShikiSuen
Copy link
Author

@ShikiSuen I think that we just need to get this through the CI systems, but this should be good to go otherwise. Please create a new PR with the same changes for the release/6.3 branch

I've modified this PR targeting release/6.3 branch now.

Oh @ShikiSuen we'd love to use this! Thank you for the fix, can't wait to see it in 6.3!

I've modified this PR targeting release/6.3 branch now.

@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@ShikiSuen no, that won't work - this must go to main first. We want a cherry-pick for 6.3

@ShikiSuen ShikiSuen force-pushed the SHGetKnownFolderPath-Continued branch from 4750898 to e71d604 Compare December 2, 2025 03:44
@ShikiSuen ShikiSuen changed the base branch from release/6.3 to main December 2, 2025 03:47
@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@swift-ci please test

@ShikiSuen ShikiSuen force-pushed the SHGetKnownFolderPath-Continued branch from e71d604 to 56a4e3f Compare December 2, 2025 03:50
@ShikiSuen
Copy link
Author

ShikiSuen commented Dec 2, 2025

@compnerd The current PR (5201) is now rebased using and targeting the main branch.

(PR 5295 I pushed just now is targeting the 6.0.3 branch.)

@ShikiSuen ShikiSuen changed the title Windows: Use SHGetKnownFolderPath to compute LocalAppData Windows: Use SHGetKnownFolderPath to compute LocalAppData. (targeting main). Dec 2, 2025
@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@swift-ci please test Windows platform

@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@ShikiSuen this might require more work - it seems that the tests are failing due to an abnormal termination with this change.

@compnerd compnerd changed the title Windows: Use SHGetKnownFolderPath to compute LocalAppData. (targeting main). Windows: Use SHGetKnownFolderPath to compute LocalAppData Dec 2, 2025
@ShikiSuen
Copy link
Author

ShikiSuen commented Dec 2, 2025

@compnerd I saw the test on WinNT is still running:
https://ci-external.swift.org/job/swift-corelibs-foundation-PR-windows/800/consoleFull

I searched keyword CFKnownLocations. throughout the current log stream and didn't find anything failed.

image

@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

@compnerd I saw the test on WinNT is still running: https://ci-external.swift.org/job/swift-corelibs-foundation-PR-windows/800/consoleFull

I searched keyword CFKnownLocations. throughout the current log stream and didn't find anything failed.

I re-triggered the tests, so the link is gone. The search result is not important - the fact that the test process terminated abnormally is. That means that there is an invalid memory access or assertion being triggered now.

@ShikiSuen
Copy link
Author

@compnerd I need to know which assertion in which file fails the unit tests.
Any crash report will help.

P.S.: I'm not familiar with Win32 development. However, I personally suggest that CI for PRs should do A/B tests consecutively to identify whether a CI failure really is caused by the contents of the PR. Also, if it fail, it'd better to be a repeatable failure. Still, to my experience, network dependencies, if have, can fail CI unit tests reandomly.

@compnerd
Copy link
Member

compnerd commented Dec 2, 2025

Unfortunately, SPM doesn't always report that. You would need to try to see if you can reproduce the issue locally.

@ShikiSuen
Copy link
Author

@compnerd Are unit test cases in CI run sequencially or in parallel?


Let me note some intelligence collected from the failed checks:

Test Case 'TestNSLocale.test_staticProperties' started at 2025-12-02 19:11:18.892

Error: Error: swift exited with code 1.
Invocation:
  swift test --scratch-path T:\x86_64-unknown-windows-msvc\FoundationTests --package-path C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift-corelibs-foundation -c debug -debug-info-format none --multiroot-data-file C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build_swift\resources\SwiftPM-Unified-Build.xcworkspace --test-product swift-corelibs-foundationPackageTests
Call stack:
  at Invoke-Program, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1075
  at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2055
  at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
  at Build-SPMProject, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2020
  at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3186
  at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
  at Test-Foundation, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3178
  at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 855
  at Record-OperationTime, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 671
  at Invoke-BuildStep, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 854
  at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 4510

    at Invoke-Program, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1079
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2055
    at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
    at Build-SPMProject, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2020
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3186
    at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
    at Test-Foundation, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3178
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 855
    at Record-OperationTime, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 671
    at Invoke-BuildStep, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 854
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 4510
  From System.Management.Automation.RuntimeException: Error: swift exited with code 1.
  Invocation:
    swift test --scratch-path T:\x86_64-unknown-windows-msvc\FoundationTests --package-path C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift-corelibs-foundation -c debug -debug-info-format none --multiroot-data-file C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build_swift\resources\SwiftPM-Unified-Build.xcworkspace --test-product swift-corelibs-foundationPackageTests
  Call stack:
    at Invoke-Program, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1075
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2055
    at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
    at Build-SPMProject, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 2020
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3186
    at Invoke-IsolatingEnvVars, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 1094
    at Test-Foundation, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 3178
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 855
    at Record-OperationTime, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 671
    at Invoke-BuildStep, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 854
    at <ScriptBlock>, C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift\utils\build.ps1: line 4510

@ShikiSuen
Copy link
Author

@compnerd By the way: This PR at this moment added #include <shlobj_core.h> to CFKnownLocations.c. Should there be any extra work to do with this? I guess this might be the prime cause why the CI fails.

@ShikiSuen
Copy link
Author

@swift-ci Please test Windows platform.

@compnerd
Copy link
Member

compnerd commented Dec 3, 2025

@swift-ci please test windows platform

@compnerd
Copy link
Member

compnerd commented Dec 3, 2025

@swift-ci please test Windows platform

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.

4 participants