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

Wasm-pack build error when use winnow debug feature #430

Open
2 tasks done
baoyachi opened this issue Jan 22, 2024 · 8 comments
Open
2 tasks done

Wasm-pack build error when use winnow debug feature #430

baoyachi opened this issue Jan 22, 2024 · 8 comments
Labels
C-bug Category: Things not working as expected

Comments

@baoyachi
Copy link
Contributor

baoyachi commented Jan 22, 2024

Please complete the following tasks

rust version

rustc 1.74.0 (79e9716c9 2023-11-13)

winnow version

0.5.34

Minimal reproducible code

I hope to use debug in wasm to debug and output information. Currently, using the debug feature will result in errors. Can we collect trace information somewhere, not necessarily at the terminal

  • Cargo.toml file
[package]
name = "demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
winnow = {version = "0.5.34",features = ["debug"]}
  • lib.rs
fn hello() {}

cargo tree

➜  demo git:(main) ✗ cargo tree
demo v0.1.0 (/Users/baoyachi/demo)
└── winnow v0.5.34
    ├── anstream v0.3.2
    │   ├── anstyle v1.0.4
    │   ├── anstyle-parse v0.2.3
    │   │   └── utf8parse v0.2.1
    │   ├── anstyle-query v1.0.2
    │   ├── colorchoice v1.0.0
+    │   ├── is-terminal v0.4.10
    │   │   └── rustix v0.38.30
    │   │       ├── bitflags v2.4.2
+    │   │       ├── errno v0.3.8
    │   │       │   └── libc v0.2.152
    │   │       └── libc v0.2.152
    │   └── utf8parse v0.2.1
    ├── anstyle v1.0.4
    ├── is-terminal v0.4.10 (*)
    └── terminal_size v0.2.6
        └── rustix v0.37.27
            ├── bitflags v1.3.2
            ├── errno v0.3.8 (*)
            ├── io-lifetimes v1.0.11
            │   └── libc v0.2.152
            └── libc v0.2.152

Steps to reproduce the bug with the above code

wasm-pack build --target bundler

Actual Behaviour

➜  demo git:(main) ✗ wasm-pack build --target bundler 
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
   Compiling errno v0.3.8
error[E0583]: file not found for module `sys`
  --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:26:1
   |
26 | mod sys;
   | ^^^^^^^^
   |
   = help: to create the module `sys`, create file "/Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/sys.rs" or "/Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/sys/mod.rs"

error[E0425]: cannot find function `with_description` in module `sys`
  --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:47:14
   |
47 |         sys::with_description(*self, |desc| {
   |              ^^^^^^^^^^^^^^^^ not found in `sys`

error[E0425]: cannot find function `with_description` in module `sys`
  --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:58:14
   |
58 |         sys::with_description(*self, |desc| match desc {
   |              ^^^^^^^^^^^^^^^^ not found in `sys`

error[E0425]: cannot find value `STRERROR_NAME` in module `sys`
  --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:64:22
   |
64 |                 sys::STRERROR_NAME,
   |                      ^^^^^^^^^^^^^ not found in `sys`

error[E0425]: cannot find function `errno` in module `sys`
  --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:95:10
   |
95 |     sys::errno()
   |          ^^^^^ not found in `sys`

error[E0425]: cannot find function `set_errno` in module `sys`
   --> /Users/baoyachi/.cargo/registry/src/errno-0.3.8/src/lib.rs:100:10
    |
100 |     sys::set_errno(err)
    |          ^^^^^^^^^ not found in `sys`

Some errors have detailed explanations: E0425, E0583.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `errno` (lib) due to 6 previous errors
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "/Users/baoyachi/demo" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
➜  demo git:(main) ✗ 

Expected Behaviour

Expected build ok.

Additional Context

No response

@baoyachi baoyachi added the C-bug Category: Things not working as expected label Jan 22, 2024
@baoyachi
Copy link
Contributor Author

If possible, I can provide support. @epage

@epage
Copy link
Collaborator

epage commented Jan 22, 2024

If its just is-terminal, an MSRV bump will make that dependency go away.

I haven't settled on an MSRV policy yet for this package but wanted a bit wider of a window since people were used to that with nom. We are now 5 releases past 1.70, so maybe its ok?

I'm also curious why you are wanting to support debug in wasm? debug is not for production code and I would assume development could easily run a parser on the host as well as a wasm target.

@baoyachi
Copy link
Contributor Author

Currently, I have used winnow to develop a parsing engine for a domain-specific language (DSL). The DSL parsing scripts are authored within a web page, and when I need to understand the entire parsing process to pinpoint and troubleshoot issues, winnow's trace functionality effectively helps me display this information on the webpage itself. I no longer need to repeatedly debug the Rust program; instead, I can directly view verbose tracing output to resolve problems.

So, if winnow's trace capability could be enhanced such that it collects tracing information at specific points without necessarily outputting to the terminal, and instead relays this information back to JavaScript through WebAssembly (WASM), the web page would then be able to display the verbose trace output.

@epage
Copy link
Collaborator

epage commented Jan 24, 2024

Is this a "development" page where the traces being there, but disabled, is fine? Or is this where you compile two different instances of the parser, one with debug and one without, and switch between them?

@baoyachi
Copy link
Contributor Author

Yes, in the binary file compiled by Rust, the winnow debug feature is disabled for the service running on the real server. However, in the compiled wasm, the winnow debug feature is enabled.

@epage
Copy link
Collaborator

epage commented Jan 24, 2024

I'm hesitant. This was originally designed to just be for quick, one-off debugging.

To expose this for use cases like this would require

  • Defining a public trait for this information
  • Defining a registration mechanism for a trait object
    • This would also slow things down but not likely as much as the output slows things down in the first place, so its likely not noticeable

Thats a large API surface for what feels like a fairly small use case that we then would be striving to maintain compatibility on.

Maybe an approach to take is to allow you to experiment on such a design behind a unstable-debug-sink feature and then we can evaluate whether its worth stabilizing or removing.

EDIT: I wish we had language-level registration system...

@baoyachi
Copy link
Contributor Author

baoyachi commented Mar 6, 2024

EDIT: I wish we had language-level registration system...

Can you provide some examples or ideas for the registration system here. Or provide a reference

@epage
Copy link
Collaborator

epage commented Mar 6, 2024

Can you provide some examples or ideas for the registration system here. Or provide a reference

I don't remember enough of the details but there has been talk along these lines for async runtime registration.

I wonder if distributed_slice (rust-lang/testing-devex-team#3) could be used as it allows a dependent to inject a value into a dependency. You could have a static value that and then inject a reference it into the slice. We could pick the first item found or do a const assert if there are multiple items.

@epage epage reopened this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Things not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants