swiftwasm / JavaScriptKit

Swift framework to interact with JavaScript through WebAssembly.
https://swiftpackageindex.com/swiftwasm/JavaScriptKit/main/documentation/javascriptkit
MIT License
664 stars 44 forks source link

Cannot Build Package With JavaScriptKit #250

Closed mergesort closed 2 months ago

mergesort commented 3 months ago

I'm looking to take a Swift SDK that I've built and integrate it in a browser extension, to share logic for the API calls I've already built for a Swift/Vapor app. I'm very new to JavaScriptKit but have a lot of Swift experience and know enough TypeScript to code myself into a problem.

With that in mind, I put together a project that integrates my Swift SDK, for the purposes of giving it a test run to see if my proof of concept would work. I wasn't able to get very far though, after I had a Swift package built that integrated a few local dependencies and JavaScriptKit I tried to run swift build --triple wasm32-unknown-wasi in my package, and ran into this error.

➜ swift build --triple wasm32-unknown-wasi
Building for debugging...
error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-wasi"'
1 error generated.
In file included from /Users/mergesort/Desktop/WebIntegrationsAPIApp/IntegrationsBrowserAPI/.build/checkouts/JavaScriptKit/Sources/_CJavaScriptKit/_CJavaScriptKit.c:1:
/Users/mergesort/Desktop/WebIntegrationsAPIApp/IntegrationsBrowserAPI/.build/checkouts/JavaScriptKit/Sources/_CJavaScriptKit/include/_CJavaScriptKit.h:4:10: fatal error: 'stdlib.h' file not found
#include <stdlib.h>
         ^~~~~~~~~~
1 error generated.
[1/4] Write swift-version--58304C5D6DBC2206.txt

I can't yet share all of the code I plan to publish but am happy to share any more information I can that may be helpful, so please let me know if there's anything else I can provide to help debug.

Thank you so much!

kateinoigakukun commented 3 months ago

I guess you are using non-Wasm Swift toolchain. Could you check PATH is configured to use SwiftWasm toolchain as instructed here?

If you properly configured it, you will see SwiftWasm in the version message.

$ swiftc --version
SwiftWasm Swift version 5.9.2 (swift-5.9.2-RELEASE)
mergesort commented 2 months ago

My apologies for missing your reply to this issue. When I install the latest toolchain and run env TOOLCHAINS=swiftwasm swift, I get this error message.

error: failed to launch REPL process: process exited with status -1 (attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries, when the attach failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))

As a result the toolchain continues to be this.

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
kateinoigakukun commented 2 months ago

@mergesort The REPL mode (just a swift command) doesn't work in this version, unfortunately. I recommend to use PATH modification way instead of TOOLCHAINS env var.

mergesort commented 2 months ago

Got it, that worked great. Thank you so much @kateinoigakukun, will close the issue now that I understand the right way to get started!