carton: Method with i64 return type fails on Safari 13+14

Using JavaScriptKit as only dependency, trying to instantiate a Date() fails on Safari (13.1.1, 14) with: TypeError: i64 not allowed as return type or argument to an imported function

Stacktrace

TypeError: i64 not allowed as return type or argument to an imported function

wasm-stub
<?>.wasm-function[gettimeofday]
<?>.wasm-function[CFAbsoluteTimeGetCurrent]
<?>.wasm-function[$s10Foundation4DateVACycfC]
<?>.wasm-function[main]
<?>.wasm-function[__original_main]
<?>.wasm-function[_start]
wasm-stub
_start
(anonymous function) — e8900d1b3895f276.js:1:47960
(anonymous function) — e8900d1b3895f276.js:1:184568
asyncFunctionResume
[native code]

Same code runs fine on Chrome and Firefox. Tried with latest blessed carton versions and with latest swiftwasm+JavaScriptKit, same results.

Assuming it’s related to swiftwasm/JavaScriptKit#56. Could/should we incorporate this polyfill in JavaScriptKit?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’ll work on porting wasm_transform_cli in Swift world

Moving it to the carton repo in the meantime, I don’t think any changes in JavaScriptKit will be necessary.

Today and yesterday I’ve been playing with Binaryen bindings, and binaryen is what powers wasm-opt. If we can get its i64-to-i32-lowering pass to work, it could be easily integrated in carton and applied during the build.

I’ve had some success running the i64->i32 transformer directly in rust on the pre-optimized bundle. It fails on optimized bundle and when running in javascript. JSDate does work in Safari, but naturally untenable for reusing ‘real’ Swift code. I guess it also affects a bunch of other WASI methods.

Unfortunately it is, getting same results with carton init --template basic, then in main.swift:

import Foundation
print("Hello, world!")
let date = Date()

(Running with carton dev/bundle)