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

Dart bindings for web issue with WasiConfig #54

Open
renzullomichele opened this issue May 2, 2024 · 3 comments
Open

Dart bindings for web issue with WasiConfig #54

renzullomichele opened this issue May 2, 2024 · 3 comments

Comments

@renzullomichele
Copy link

renzullomichele commented May 2, 2024

I think there is something strange with Dart bindings for web:
When I try to setup WasiConfig, the first execution in flutter run -d chrome return an error:
TypeError: Cannot read properties of undefined (reading 'WASI').
or if I enable captureStdErr
TypeError: Cannot read properties of undefined (reading 'Fd').
simply doing "r" seems that the "refresh" initialise what failed the first time.
Everything seems to work after but is very strange, because of this issue I gave up with WasiConfig and I decided to "write" by myself wasix import basic like fd_write, fd_seek, clock_time_get, proc_exit so that the config can be null... Any solution? If would be possible to expand the test with loading a valid WasiConfig would be also helpful, because I think my config is set up correctly otherwise the code wouldn't work ever.

Here seems the problem from the debugger, I'm investigating:

  WasmInstanceBuilder builder({
    WasiConfig? wasiConfig,
    WorkersConfig? workersConfig,
  }) {
    _WASI? wasi;
    if (wasiConfig != null) {
      final stdout = wasiConfig.captureStdout ? WasiStdio() : null;
      final stderr = wasiConfig.captureStderr ? WasiStdio() : null;

      final wasiWeb = WASI(
        wasiConfig.args,
        wasiConfig.env
            .map((e) => '${e.name}=${e.value}')
            .toList(growable: false),
        [
          OpenFile(WasiWebFile(Uint8List(0))), // TODO: stdin
          stdout?.fd ?? OpenFile(WasiWebFile(Uint8List(0))),
          stderr?.fd ?? OpenFile(WasiWebFile(Uint8List(0))),
          ...wasiConfig.webBrowserFileSystem.entries.map(
            (e) => PreopenDirectory(
              e.key,
              js_util.jsify(_mapWasiFiles(e.value.items)) as Object,
            ),
          ),
        ],
      );
      wasi = _WASI(wasiWeb, stdout, stderr);
    }

    return _Builder(this, wasi, workersConfig);
  }
@renzullomichele
Copy link
Author

Solved adding in web/index.html

<head>
<script src="/assets/packages/wasm_run/lib/assets/wasm-feature-detect.js" defer></script>
<script type="module" src="/assets/packages/wasm_run/lib/assets/browser_wasi_shim.js" defer></script>
</head>

The Readme was saying that is not necessary in flutter web, I was assuming this process was done under the hood, but apparently is not because Fd is requested as import in my binary when using WASI call that have an fd, like fd_seek ecc...
I think that just updating the Readme will be sufficient

@michelerenzullo
Copy link
Contributor

Created pull request #55

@michelerenzullo
Copy link
Contributor

This Issue can be closed or should be mutated as "fix flutter scripts injector"

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

No branches or pull requests

2 participants