Skip to content

BridgeJS: Fix building the BridgeJS and PackageToJS plugins on Windows - #838

Merged
kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
sebgod:bridgejs-windows-kill-import
Dec 1, 2026
Merged

kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
sebgod:bridgejs-windows-kill-import

Conversation

@sebgod

@sebgod sebgod commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

On a Windows host, a package that uses the BridgeJS or PackageToJS plugin doesn't build, because three host-side files import symbols that don't exist there:

  • TS2Swift.swift imports func Foundation.kill unconditionally. Its one use is already in the #else branch of #if os(Windows), which calls TerminateProcess (Allow Swift projects that use JavaScriptKit to compile on Windows #673), so the import moves into the #else of the file's existing #if os(Windows) / import WinSDK block.
  • BridgeJSTool.swift and PackageToJSPlugin.swift import stderr from Darwin, Glibc, Musl or Android, with no Windows branch. ucrt defines stderr only as a macro, which Swift can't import; Foundation exports it on Windows, so the new branch imports Foundation.stderr.

Nothing changes on other platforms.

Testing

Windows 11, Swift 6.4.1 (swift-6.4.1-RELEASE_wasm SDK), repository cloned with core.symlinks=true, Node 26.13.1, npm ci:

main (1edf6b3) this PR
swift build --package-path Plugins/BridgeJS fails: function 'kill' does not exist in module 'Foundation', then cannot find 'stderr' in scope (BridgeJSTool.swift) builds
Examples/ExportSwift: swift build --swift-sdk … fails: plugin compilation, cannot find 'stderr' in scope (PackageToJSPlugin.swift) builds
Examples/ExportSwift: swift package --swift-sdk … js --use-cdn fails the same way packages (MyApp.wasm, bridge-js.js, index.js, …)
BridgeJSTool generate on Examples/ImportTS (runs ts2swift through Node) doesn't build generates BridgeJS.swift and BridgeJS.Macros.swift

./Utilities/format.swift's swift-format reports no changes to the three files.

Not fixed here

These are separate issues I hit on Windows while testing; happy to open issues or follow-up PRs:

  • which() in TS2Swift.swift looks for node, not node.exe, so Node is never found on PATH on Windows; bridge-js.config.local.json works around it (JAVASCRIPTKIT_NODE_EXEC doesn't reach the tool under SwiftPM).
  • Run by the build plugin, BridgeJSTool gets PATH but not SystemRoot. Without it Winsock can't initialise, and Process.run() traps in Foundation ("Could not create wakeup socket pair for CFSocket") when ts2swift starts. With PATH and SystemRoot set it works, as in the last row above.
  • The test targets don't build on Windows (mkdtemp in TemporaryDirectory.swift), so I couldn't run swift test --package-path ./Plugins/BridgeJS there; CI's Linux and macOS runs cover this change, which is a no-op on those platforms.
  • Examples/ImportTS has no tsconfig.json, which the build plugin requires, so it doesn't build on any platform. I added one locally to test the last row.

Written with Claude Code; the tests above were run on my Windows machine.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PTxV5VQUn7st6eUgooE127

@sebgod

sebgod commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

it seems one runner didn't come online properly

@kateinoigakukun
kateinoigakukun merged commit 0dd53fb into swiftwasm:main Dec 1, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants