Description
Description
Example use case:
JavaScriptKit provides interop via @_expose(wasm)
declarations.
However, when an embedded swift app is depending on it, these symbols are missing from the final binary. After a brief discussion with @rauhul it is pretty clear why:
- all swift module dependencies are actually only "compiled" into the final module via swiftmodules
- the object files of the swift dependencies cannot be used for linking (otherwise we'd get duplicate symbols)
- since the app module does not actually reference the swift declaration, it will not end up in an object file used for linking
I suspect this is true for any "unused" top-level swift declaration that should end up in the binary, and I guess this is also the reason for @_cdecl
s not working (see #74328)
Reproduction
see a package with this issue here (with the work-around of referencing the expose as an underscored public swift symbol)
https://github.com/swiftwasm/JavaScriptKit/blob/dd0c977dde0ad056b5b0665bc66335b8c77ce59e/Examples/Embedded/Sources/EmbeddedApp/_thingsThatShouldNotBeNeeded.swift#L3-L8
Expected behavior
ideally all @_expose
and @_cdecl
symbols end up "somewhere" so they are available for linking.
maybe it is possible to "just" add them to an object file in the entry module?
we also talked about the @_used
attribute, but I am not sure it should be needed. (eg: a cdecl can always NOT be linked, that is fine, but it needs to be available at link-time)
Environment
Apple Swift version 6.1-dev (LLVM 5c0d283c37132bf, Swift b5af518)
Target: arm64-apple-macosx15.0
Additional information
forum post with all the context
https://forums.swift.org/t/web-app-with-embedded-swift-poc-demo/75486