0

Recently I knew about web assembly and was messing around with it in rust. Eventually I run into build problem. My toml file looks like this

[package]
name = "clipboard-manager"
version = "0.1.0"
edition = "2018"

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

[features]
default = ["console_error_panic_hook"]

[dependencies]
x11-clipboard = "0.5.2"
wasm-bindgen = "0.2.63"
js-sys = "0.3.55"
console_error_panic_hook = { version = "0.1.6", optional = true }
#libc = "0.2.105"
# log = "0.4.14"
# x11 = "2.19.1"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"

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

And when I want to build .wasm file with wasm-pack build --target web command I get bunch of errors like this

error[E0425]: cannot find function `malloc` in crate `libc`
  --> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/shape.rs:98:29
   |
98 |             let raw = libc::malloc(32 as usize) as *mut xcb_shape_notify_event_t;
   |                             ^^^^^^ not found in `libc`

error[E0425]: cannot find function `malloc` in crate `libc`
   --> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/xfixes.rs:238:29
    |
238 |             let raw = libc::malloc(32 as usize) as *mut xcb_xfixes_selection_notify_event_t;
    |                             ^^^^^^ not found in `libc`

error[E0425]: cannot find function `malloc` in crate `libc`
   --> /mnt/commondisk/filip/Development/personal/clipboard-manager/target/wasm32-unknown-unknown/release/build/xcb-64883900109c6e35/out/xfixes.rs:330:29
    |
330 |             let raw = libc::malloc(32 as usize) as *mut xcb_xfixes_cursor_notify_event_t;
    |                             ^^^^^^ not found in `libc`

I maneged to build wasm module by commenting out x11-clipboard dependency. I tried to build this module with x11-clipboard dependencies and it was also failing until I commented out xcb dependency. It also fails if I add x11 crate. For a while I thought libc could be a problem but I had not problem building module with this dependency.

Does anyone know why some dependencies cause building process failing and how to fix it? If it's impossible to fix can someone explain me why? Thanks in advance!

  • 4
    How do you expect `x11` libraries to work in WASM? AFAIK, there is no equivalent to X server there. – Cerberus Oct 28 '21 at 03:13
  • @Cerberus I was expecting it may not work. I did it for test and I expected that it will compile to `.wasm` and in worst case scenario function calls won't take any actions or will throw error at runtime. Obviously I got it wrong and it did not build at all. So anything X server related can not be compiled to `.wasm` because web assembly doesn't support it? – Filip Izydorczyk Oct 28 '21 at 12:51
  • Yes. If you want to support X11 and wasm, you can use feature-gated dependencies. – PitaJ Oct 28 '21 at 19:12

0 Answers0