rustwasm / wasm-pack

πŸ“¦βœ¨ your favorite rust -> wasm workflow tool!
https://rustwasm.github.io/wasm-pack/
Apache License 2.0
6.31k stars 409 forks source link

`wasm-pack build` errors in a Docker container, but only on MacOS #1416

Open JamieMair opened 3 months ago

JamieMair commented 3 months ago

πŸ› Bug description

wasm-pack build fails after [INFO]: Installing wasm-bindgen... with the error:

49.39 Error: No such file or directory (os error 2)
49.39 Caused by: No such file or directory (os error 2)

Our Dockerfile builds with no issues on a Linux host, but the exact same Dockerfile fails on MacOS.

πŸ€” Expected Behavior

The command should run with no issues and produce the npm package in a local directory inside the Docker image.

πŸ‘Ÿ Steps to reproduce

Here is a snippet of the Dockerfile used when the issue occurs:

FROM rust:1.79-alpine AS wasmbuild

# Install protoc and other deps
RUN apk add --no-cache protobuf-dev build-base curl openssl binaryen

# Required for building the WASM module
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Compile and build the web-assembly project
WORKDIR /usr/src/mypkg
COPY mypkg .

RUN wasm-pack build

I have tried replacing the curl install with

RUN cargo install wasm-bindgen-cli
RUN cargo install wasm-pack

but the same issue happens.

Below is a snippet of the output

 > [frontend wasmbuild 8/8] RUN wasm-pack build:
3.502 [INFO]: Checking for the Wasm target...
3.901 info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
5.929 info: installing component 'rust-std' for 'wasm32-unknown-unknown'
7.621 [INFO]: Compiling to Wasm...
7.828    Compiling proc-macro2 v1.0.86
7.828    Compiling unicode-ident v1.0.12
7.828    Compiling anyhow v1.0.86
7.829    Compiling either v1.13.0
7.829    Compiling once_cell v1.19.0
7.836    Compiling log v0.4.22
7.836    Compiling wasm-bindgen-shared v0.2.92
7.836    Compiling rustix v0.38.34
7.958    Compiling memchr v2.7.4
8.167    Compiling itertools v0.12.1
8.180    Compiling prettyplease v0.2.20
8.373    Compiling regex-syntax v0.8.4
8.448    Compiling linux-raw-sys v0.4.14
9.149    Compiling bitflags v2.6.0
9.168    Compiling bytes v1.7.1
9.501    Compiling bumpalo v3.16.0
9.778    Compiling aho-corasick v1.1.3
9.867    Compiling equivalent v1.0.1
9.917    Compiling hashbrown v0.14.5
10.96    Compiling quote v1.0.36
11.35    Compiling indexmap v2.3.0
11.39    Compiling fastrand v2.1.0
12.04    Compiling syn v2.0.72
12.09    Compiling cfg-if v1.0.0
12.21    Compiling fixedbitset v0.4.2
14.41    Compiling petgraph v0.6.5
14.80    Compiling regex-automata v0.4.7
15.20    Compiling multimap v0.10.0
15.51    Compiling wasm-bindgen v0.2.92
15.77    Compiling heck v0.5.0
16.28    Compiling dunce v1.0.5
16.38    Compiling tempfile v3.11.0
19.04    Compiling glob v0.3.1
20.66    Compiling syllable v0.1.0
20.81    Compiling unicode-segmentation v1.11.0
20.82    Compiling wordsworth v0.1.1
25.73    Compiling regex v1.10.6
26.77    Compiling wasm-bindgen-backend v0.2.92
32.40    Compiling wasm-bindgen-macro-support v0.2.92
34.07    Compiling prost-derive v0.12.6
36.10    Compiling wasm-bindgen-macro v0.2.92
38.75    Compiling prost v0.12.6
39.65    Compiling prost-types v0.12.6
44.24    Compiling prost-build v0.12.6
44.79    Compiling console_error_panic_hook v0.1.7
46.37    Compiling mypkg v0.1.0 (/usr/src/mypkg)
47.55 warning: function `set_panic_hook` is never used
47.55  --> src/utils.rs:1:8
47.55   |
47.55 1 | pub fn set_panic_hook() {
47.55   |        ^^^^^^^^^^^^^^
47.55   |
47.55   = note: `#[warn(dead_code)]` on by default
47.55 
47.97 warning: `wasm-readability` (lib) generated 1 warning
47.97     Finished `release` profile [optimized] target(s) in 40.29s
47.99 [INFO]: Installing wasm-bindgen...
49.39 Error: No such file or directory (os error 2)
49.39 Caused by: No such file or directory (os error 2)

🌍 Your environment

Docker Host OS: MacOS (with Apple Silicon CPU) Docker Image OS: Alpine Linux wasm-pack version: Latest (as of 5th August 2024), exact unknown rustc version: 1.79

JamieMair commented 3 months ago

Might relate to https://github.com/rustwasm/wasm-pack/issues/913

fossdd commented 2 months ago

I'm having similar issues when building kanidm's UI in Alpine's CI containers on aarch64.

Using QEMU instead of a container, works. Using x86_64 for building instead of aarch64, works aswell. Using wasm-pack 0.12.1 works but not 0.13.0. We're using Linux hosts, so I believe this is a aarch64 issue and not specific to macOS.

Maybe it is even Alpine related.

fossdd commented 2 months ago

Ah, I guess the error is maybe due to the recent split in Alpine of rustc-dev. It worked for me to install rustc-dev and re-run it. I opened a MR at Alpine to address this issue: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/71265