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

Build for Web fails: error: cannot import from modules (env) with --no-modules #1915

Closed
flowhorn opened this issue May 3, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@flowhorn
Copy link

flowhorn commented May 3, 2024

Describe the bug

I try to integrate the zstd library into the rust code. When doing this, I get this to compile for all targets except for wasm/web.

This is the error message I received:

error: cannot import from modules (`env`) with `--no-modules`
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1

My cargo.toml includes these two dependencies:

[dependencies]
flutter_rust_bridge = "=2.0.0-dev.32"
zstd = { git = "https://github.com/jbms/zstd-rs.git", branch = "fix-wasm32-unknown-unknown" }

I got zstd to compile to the wasm32-unknown-unknown target, but I didn't got this to work with the no-modules restriction, do you have any solution for this? As there is no support for zstd in dart, I thought that this would be useful to use the rust_bridge for, and on other targets this worked perfectly.

Best regards.

Steps to reproduce

Add these dependencies:

[dependencies]
flutter_rust_bridge = "=2.0.0-dev.32"
zstd = { git = "https://github.com/jbms/zstd-rs.git", branch = "fix-wasm32-unknown-unknown" }

utils.rs (+ adding this in mod.rs):

use zstd::stream::{decode_all, encode_all};

#[flutter_rust_bridge::frb(sync)] // Synchronous mode for simplicity of the demo
pub fn compress_zstd(data: Vec<u8>, compression_level: i32) -> Vec<u8> {
    encode_all(data.as_slice(), compression_level).unwrap()
}

#[flutter_rust_bridge::frb(sync)] // Synchronous mode for simplicity of the demo
pub fn decompress_zstd(data: Vec<u8>) -> Vec<u8> {
    decode_all(data.as_slice()).unwrap()
}

Running flutter_rust_bridge_codegen build-web

Logs

error: cannot import from modules (`env`) with `--no-modules`
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit status: 1

Command: wasm-pack build -t no-modules -d /[...]/my_app/web/pkg --no-typescript --out-name rust_lib_my_app --dev rust -- -Z build-std=std,panic_abort
#0      runCommand (package:flutter_rust_bridge/src/cli/run_command.dart:67:5)
<asynchronous suspension>
#1      _executeWasmPack (package:flutter_rust_bridge/src/cli/build_web/executor.dart:143:3)

Expected behavior

No response

Generated binding code

No response

OS

MacOS

Version of flutter_rust_bridge_codegen

2.0.0-dev.32

Flutter info

No response

Version of clang++

Homebrew clang version 18.1.4

Additional context

No response

@flowhorn flowhorn added the bug Something isn't working label May 3, 2024
Copy link

welcome bot commented May 3, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 3, 2024

Hmm, looks like currently frb needs no-modules but may be relaxed - feel free to PR for this! On the other hand, maybe we can ask in zstd repo about whether it can be compiled under no-modules mode.

In addition, it may also be some bug in wasm compile: rust-lang/rust#93557 - could you please try that and see whether it solves the problem?

@fzyzcjy fzyzcjy added await response awaiting Waiting for responses, PR, further discussions, upstream release, etc and removed await response labels May 3, 2024
@flowhorn
Copy link
Author

flowhorn commented May 4, 2024

Thank you for the quick reply and telling about the limitation of no-modules. I will create in issue in the zstd-rs library for using the library with no-modules, as no trick with wasm-pack helped me actually compiling it.
For now I switched to another library for zstd: ruzstd. This worked for me for now.

It's fun to integrate rust code into my app, thank you for your work!

@flowhorn flowhorn closed this as completed May 4, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented May 4, 2024

You are welcome and happy to see it works!

Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants