From: Marc-André Lureau <marcandre.lur...@redhat.com>

Note that Debian packaging & testing is currently lacking:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=979665 Furthermore,
emsdk is based on Ubuntu Jammy. So we use rustup for now.

bindgen doesn't use clang & libclang from /emsdk, it probably should but
libclang is missing https://github.com/emscripten-core/emsdk/issues/1605

Finally, there is a linking issue I don't understand and I can't solve yet:
wasm-ld: error: unable to find library -llibqemuutil.a
...

A manual test like this work:
emmake rustc -v --target wasm32-unknown-emscripten -C
linker=/emsdk/upstream/emscripten/emcc --crate-type bin --edition=2021
-C link-arg=-m32 test.rs -Clink-arg=libfoo.a

Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
---
 configure                                     |  4 +++
 .gitlab-ci.d/buildtest-template.yml           |  2 +-
 .gitlab-ci.d/buildtest.yml                    |  2 +-
 .../dockerfiles/emsdk-wasm32-cross.docker     | 27 ++++++++++++++++++-
 tests/docker/test-wasm                        | 12 +++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100755 tests/docker/test-wasm

diff --git a/configure b/configure
index 78445cbb4b..fdae1b4133 100755
--- a/configure
+++ b/configure
@@ -1228,6 +1228,10 @@ if test "$rust" != disabled && test -z 
"$rust_target_triple"; then
     rust_machine=apple
     ;;
 
+  emscripten)
+    rust_arch=wasm32
+    ;;
+
   linux)
     # detect android/glibc/musl
     if check_define __ANDROID__; then
diff --git a/.gitlab-ci.d/buildtest-template.yml 
b/.gitlab-ci.d/buildtest-template.yml
index d866cb12bb..307b927927 100644
--- a/.gitlab-ci.d/buildtest-template.yml
+++ b/.gitlab-ci.d/buildtest-template.yml
@@ -148,5 +148,5 @@
       fi || exit 1;
     - section_end configure
     - section_start build "Building QEMU"
-    - emmake make -j"$JOBS"
+    - 
CPATH="$CPATH:/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl:/emsdk/upstream/emscripten/cache/sysroot/include/compat:/emsdk/upstream/lib/clang/18/include:/emsdk/upstream/emscripten/cache/sysroot/include"
 emmake make -j"$JOBS"
     - section_end build
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
index 34d8c1a496..dc0a0282b2 100644
--- a/.gitlab-ci.d/buildtest.yml
+++ b/.gitlab-ci.d/buildtest.yml
@@ -794,4 +794,4 @@ build-wasm:
     - job: wasm-emsdk-cross-container
   variables:
     IMAGE: emsdk-wasm32-cross
-    CONFIGURE_ARGS: --static --disable-tools --enable-debug 
--enable-tcg-interpreter
+    CONFIGURE_ARGS: --static --disable-tools --enable-debug 
--enable-tcg-interpreter --enable-rust
diff --git a/tests/docker/dockerfiles/emsdk-wasm32-cross.docker 
b/tests/docker/dockerfiles/emsdk-wasm32-cross.docker
index 6b1642a207..85d0a0fd8d 100644
--- a/tests/docker/dockerfiles/emsdk-wasm32-cross.docker
+++ b/tests/docker/dockerfiles/emsdk-wasm32-cross.docker
@@ -17,10 +17,11 @@ ENV EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
 ENV CFLAGS="-O3 -pthread -DWASM_BIGINT"
 ENV CXXFLAGS="$CFLAGS"
 ENV LDFLAGS="-sWASM_BIGINT -sASYNCIFY=1 -L$TARGET/lib"
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \
     autoconf \
     build-essential \
     libglib2.0-dev \
+    libfdt-dev \
     libtool \
     pkgconf \
     ninja-build \
@@ -46,6 +47,30 @@ pkgconfig = ['pkg-config', '--static']
 EOT
 EOF
 
+RUN apt-get update && apt-get install -y wget clang libclang-dev
+ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo
+ENV 
RUSTC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc
+ENV 
RUSTDOC=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustdoc
+ENV 
CARGO=/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo
+RUN set -eux && \
+  rustArch='x86_64-unknown-linux-gnu' && \
+  
rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' 
&& \
+  
url="https://static.rust-lang.org/rustup/archive/1.27.1/${rustArch}/rustup-init";
 && \
+  wget "$url" && \
+  echo "${rustupSha256} *rustup-init" | sha256sum -c - && \
+  chmod +x rustup-init && \
+  ./rustup-init -y --no-modify-path --profile default --default-toolchain 
nightly --default-host ${rustArch} && \
+  /usr/local/cargo/bin/rustup target add wasm32-unknown-emscripten && \
+  chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \
+  /usr/local/cargo/bin/rustup --version && \
+  /usr/local/cargo/bin/rustup run nightly cargo --version && \
+  /usr/local/cargo/bin/rustup run nightly rustc --version && \
+  test "$CARGO" = "$(/usr/local/cargo/bin/rustup +nightly which cargo)" && \
+  test "$RUSTDOC" = "$(/usr/local/cargo/bin/rustup +nightly which rustdoc)" && 
\
+  test "$RUSTC" = "$(/usr/local/cargo/bin/rustup +nightly which rustc)"
+ENV PATH=$CARGO_HOME/bin:$PATH
+RUN /usr/local/cargo/bin/rustup run nightly cargo install bindgen-cli
+
 FROM build-base AS zlib-dev
 ARG ZLIB_VERSION
 RUN mkdir -p /zlib
diff --git a/tests/docker/test-wasm b/tests/docker/test-wasm
new file mode 100755
index 0000000000..5f3e4c401c
--- /dev/null
+++ b/tests/docker/test-wasm
@@ -0,0 +1,12 @@
+#!/bin/bash -e
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. common.rc
+
+cd "$BUILD_DIR"
+
+export 
CPATH="$CPATH:/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl:/emsdk/upstream/emscripten/cache/sysroot/include/compat:/emsdk/upstream/lib/clang/18/include:/emsdk/upstream/emscripten/cache/sysroot/include"
+
+emconfigure $QEMU_SRC/configure --disable-docs --static --disable-tools 
--enable-debug --enable-tcg-interpreter --disable-sdl --enable-rust
+emmake make $MAKEFLAGS
-- 
2.51.0

Reply via email to