0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wasmファイルにローカルアカウントが混入? Dockerビルドで解決!!

Posted at

wasm の中にローカルアカウントが入っている・・・

Cargo.tomlに以下のように記述しています

[profile.release]
opt-level = "s"
debug = false
codegen-units = 1
lto = true
panic = "abort"

記述的には問題ないと思うのですが・・・
この状態で、wasm-pack build --target web --release でビルドを行い、wasmの中を覗いてみる

$ strings ./pkg/wasm_bg.wasm | grep .cargo
/Users/owayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lazy_static-1.4.0/src/inline_lazy.rs
/Users/owayo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-wasm-bindgen-0.6.5/src/lib.rs

がっつりローカルアカウントが入っていますね

Dockerでビルドをする

ローカルアカウントが入らないようDockerでビルドすることにしました。

FROM debian:bookworm

ENV C_VERSION=12

RUN apt-get update && \
  apt-get install --no-install-recommends -y \
  curl \
  gcc-${C_VERSION} \
  g++-${C_VERSION} \
  ca-certificates \
  build-essential \
  pkg-config \
  libssl-dev && \
  rm -rf /var/lib/apt/lists/*

ENV CXX=/usr/bin/g++-${C_VERSION}
ENV CC=/usr/bin/gcc-${C_VERSION}

ENV RUST_BACKTRACE=full
ENV PATH=/root/.cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
  rustup target add wasm32-unknown-unknown && \
  cargo install wasm-pack && \
  cargo install wasm-bindgen-cli && \
  cargo install cargo-generate

WORKDIR /src

のようにして、docker runwasm-pack build --target web --release を実行しました
ビルドされた wasm ファイルを覗いてみます

$ strings ./pkg/wasm_bg.wasm | grep .cargo
/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lazy_static-1.4.0/src/inline_lazy.rs
/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-wasm-bindgen-0.6.5/src/lib.rs

大丈夫ですね

まとめ

wasm-packでビルドする際にローカルアカウントが入ってしまう問題があり、Dockerでビルドすることで解決しました
Dockerでのビルドでつまづいた点がありますが、オマケとして書いておきます

オマケ: fatal error: 'algorithm' file not found の解消方法

Dockerfileを作っているときに以下のようなエラーが出ました

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling cxx v1.0.122
The following warnings were emitted during compilation:

warning: cxx@1.0.122: In file included from /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cxx-1.0.122/src/cxx.cc:1:
warning: cxx@1.0.122: /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cxx-1.0.122/src/../include/cxx.h:2:10: fatal error: 'algorithm' file not found
warning: cxx@1.0.122: #include <algorithm>
warning: cxx@1.0.122:          ^~~~~~~~~~~
warning: cxx@1.0.122: 1 error generated.

error: failed to run custom build command for `cxx v1.0.122`

Caused by:
  process didn't exit successfully: `/src/target/release/build/cxx-835b19e1672f7ac6/build-script-build` (exit status: 1)

試行錯誤した結果、CCCXXを設定することで解消しました
fatal error: 'algorithm' file not found でググっても発生している人は複数いたのですが、解決方法が書かれていなくて苦労しました。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?