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
$ swift package init --type executable
$ swift build --triple wasm32-unknown-wasi
wasm-ld: error: /Library/Developer/Toolchains/swift-wasm-5.5-SNAPSHOT-2021-10-02-a.xctoolchain/usr/share/wasi-sysroot/lib/wasm32-wasi/libc.a(__main_argc_argv.o): undefined symbol: main
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
[0/1] Linking tmp.i3oT7EM2.wasm
The latest SwiftPM rename main entry point name of executable target to avoid conflicting "main" with test target since swift-tools-version >= 5.5.
The main symbol is renamed to "{{module_name}}_main" and it's renamed again to be "main" when linking the executable target. The former renaming is done by Swift compiler, and the latter is done by linker, so SwiftPM passes some special linker flags for each platform.
But SwiftPM assumes that wasm-ld supports it by returning an empty array instead of nil even though wasm-ld doesn't support it yet. https://github.com/apple/swift-package-manager/blob/1be68e811d0d814ba7abbb8effee45f1e8e6ec0d/Sources/Build/BuildPlan.swift#L117-L126
Current workaround for this issue is to put an explicit main decl using @_cdecl like this:
// the original code is `print("Hello")`
@_cdecl("main")func main(argc:Int32, argv:Int32)->Int32{print("Hello")return0}
For a short-term solution, we need to disable the renaming in the SwiftPM. But for a long-term solution, this renaming feature should be supported on wasm-ld, so we should send a patch for it into lld.
The text was updated successfully, but these errors were encountered:
With swift-wasm-5.5-SNAPSHOT-2021-10-02-a
The latest SwiftPM rename main entry point name of executable target to avoid conflicting "main" with test target since
swift-tools-version >= 5.5
.The main symbol is renamed to "{{module_name}}_main" and it's renamed again to be "main" when linking the executable target. The former renaming is done by Swift compiler, and the latter is done by linker, so SwiftPM passes some special linker flags for each platform.
But SwiftPM assumes that wasm-ld supports it by returning an empty array instead of nil even though wasm-ld doesn't support it yet. https://github.com/apple/swift-package-manager/blob/1be68e811d0d814ba7abbb8effee45f1e8e6ec0d/Sources/Build/BuildPlan.swift#L117-L126
Current workaround for this issue is to put an explicit
main
decl using@_cdecl
like this:For a short-term solution, we need to disable the renaming in the SwiftPM. But for a long-term solution, this renaming feature should be supported on wasm-ld, so we should send a patch for it into lld.
The text was updated successfully, but these errors were encountered: