Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swjs_create_typed_array error on carton test #322

Closed
ephemer opened this issue Apr 25, 2022 · 10 comments · Fixed by #333
Closed

swjs_create_typed_array error on carton test #322

ephemer opened this issue Apr 25, 2022 · 10 comments · Fixed by #333
Labels
question Further information is requested

Comments

@ephemer
Copy link
Contributor

ephemer commented Apr 25, 2022

Hey there, thanks for carton! We (flowkey) have been a sponsor for a while but I only got to really test things out today for the first time. I was able to get one of our fairly complex internal libraries building with it within a few hours (removing dependencies on Dispatch and Foundation).

Now I'm trying to get the tests running and so far I've been getting the following error:

carton test

Error: Process failed with non-zero exit status and following output:
 and following error output:
error: failed to run `/xyz/abc/.build/wasm32-unknown-wasi/debug/...PackageTests.wasm`
╰─▶ 1: Error while importing "javascript_kit"."swjs_create_typed_array": unknown import. Expected Function(FunctionType { params: [I32, I32, I32], results: [I32] })

swift test works fine on the same project.

I have a javascript kit dependency like so: .package(url: "https://github.com/swiftwasm/JavaScriptKit", from: "0.13.0") and it's a dependency of my test target like this: .product(name: "JavaScriptKit", package: "JavaScriptKit").

Is there something obvious I'm missing or is it more likely to be a case of "disable all tests and enable them one-by-one until something turns up"? I will try the latter tomorrow but thought I'd write here in case something had changed in a recent version of JavaScriptKit or something.

@ephemer ephemer changed the title Error on carton test swjs_create_typed_array error on carton test Apr 25, 2022
@MaxDesiatov
Copy link
Collaborator

cc @kateinoigakukun @j-f1

@ephemer
Copy link
Contributor Author

ephemer commented Apr 26, 2022

Maybe it's because I have no modules that actually import JavaScriptKit (even if it is listed as a SPM dependency). I will give this a shot later

@MaxDesiatov
Copy link
Collaborator

Thanks. In case the error persists, could you share some isolated sample code for reproduction?

@ephemer
Copy link
Contributor Author

ephemer commented Apr 26, 2022

FYI I did the following:

  • carton init
  • commented out all the mac-specific code in the dummy test file it creates (which fails to build for wasm). I just left in one test with XCTAssertEqual(true, true)
  • fixed the duplicate main.swift which causes linking issues: commented out the product and renamed the non-test target's file to something other than main.swift, removed the top-level expression.
  • ran carton test

...and I get the same issue mentioned in the original post.

That's about as minimal as you can get – there is literally no code in either the library or the tests now and the same issue occurs. @MaxDesiatov @kateinoigakukun @j-f1. I'm on macOS arm64 if it makes a difference.

I couldn't find any local file that defines "javascript_kit": "swjs_create_typed_array" so I don't know how to start debugging this, unfortunately :(

edit: Performing the above but starting with carton init --template tokamak doesn't make a difference

@MaxDesiatov
Copy link
Collaborator

@ephemer could you clarify which version of carton you're using? Also, with regards to JavaScriptKit, the latest version is 0.14.0. Would you be able to confirm that the error is still reproducible for you with the latest versions of carton and JavaScriptKit?

@MaxDesiatov MaxDesiatov added the question Further information is requested label Apr 27, 2022
@ephemer
Copy link
Contributor Author

ephemer commented Apr 28, 2022

I'm using the latest version of everything AFAIK: I just started using the entire SwiftWasm ecosystem this week.

I checked and I'm using the following versions:

carton 0.14.1
JavaScriptKit version 0.14.0

@kateinoigakukun
Copy link
Member

The default environment of carton test is command-line mode, so JSKit doesn't work. Please use carton test --environment defaultBrowser instead.

@MaxDesiatov
Copy link
Collaborator

Should we close this as a duplicate of swiftwasm/WasmTransformer#18 then?

@kateinoigakukun
Copy link
Member

Or we maybe have to provide a way to test with Node.js

@ephemer
Copy link
Contributor Author

ephemer commented May 3, 2022

Thanks a lot for your responses here! That clears things up.

I would be totally fine with avoiding JSKit in the tests. More than anything, this Issue laments the fact that it's not obvious that we have to do that. The issue is that carton init; carton test breaks, and that is pretty confusing unless you happen to know about the issue and about the carton test --environment defaultBrowser option.

Ideally the error reporting would make this clear – at the moment it's impossible to even know where to start to look.

edit: so I wouldn't necessarily recommend either path (stripping WASI code or allowing testing with nodejs) – I would just make it clear somewhere (in the docs under Testing would suffice) that JavaScriptKit can only be linked if you add that command line flag, otherwise devs should avoid it in test targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants