Skip to content

Commit 60a0ede

Browse files
committed
support wasm64 build
Signed-off-by: Kohei Tokunaga <[email protected]>
1 parent e240f6c commit 60a0ede

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

.gitlab-ci.d/buildtest.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,29 @@ coverity:
787787
# Always manual on forks even if $QEMU_CI == "2"
788788
- when: manual
789789

790-
build-wasm:
790+
build-wasm32:
791791
extends: .wasm_build_job_template
792792
timeout: 2h
793793
needs:
794794
job: wasm-emsdk-cross-container
795795
variables:
796-
IMAGE: emsdk-wasm32-cross
797-
CONFIGURE_ARGS: --static --disable-tools --enable-debug --enable-tcg-interpreter
796+
IMAGE: emsdk-wasm-cross
797+
CONFIGURE_ARGS: --static --cpu=wasm32 --disable-tools --enable-debug --enable-tcg-interpreter
798+
799+
build-wasm-wasm64:
800+
extends: .wasm_build_job_template
801+
timeout: 2h
802+
needs:
803+
job: wasm-emsdk-cross-container
804+
variables:
805+
IMAGE: emsdk-wasm-cross
806+
CONFIGURE_ARGS: --static --cpu=wasm64 --wasm64-memory64=1 --disable-tools --enable-debug --enable-tcg-interpreter
807+
808+
build-wasm-wasm64-2:
809+
extends: .wasm_build_job_template
810+
timeout: 2h
811+
needs:
812+
job: wasm-emsdk-cross-container
813+
variables:
814+
IMAGE: emsdk-wasm-cross
815+
CONFIGURE_ARGS: --static --cpu=wasm64 --wasm64-memory64=2 --disable-tools --enable-debug --enable-tcg-interpreter

.gitlab-ci.d/container-cross.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ win64-fedora-cross-container:
9595
wasm-emsdk-cross-container:
9696
extends: .container_job_template
9797
variables:
98-
NAME: emsdk-wasm32-cross
98+
NAME: emsdk-wasm-cross

configure

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ EXTRA_CXXFLAGS=""
182182
EXTRA_OBJCFLAGS=""
183183
EXTRA_LDFLAGS=""
184184

185+
wasm64_memory64=1
186+
185187
# Default value for a variable defining feature "foo".
186188
# * foo="no" feature will only be used if --enable-foo arg is given
187189
# * foo="" feature will be searched for, and if found, will be used
@@ -239,6 +241,8 @@ for opt do
239241
;;
240242
--without-default-features) default_feature="no"
241243
;;
244+
--wasm64-memory64=*) wasm64_memory64="$optarg"
245+
;;
242246
esac
243247
done
244248

@@ -365,7 +369,6 @@ elif check_define __APPLE__; then
365369
host_os=darwin
366370
elif check_define EMSCRIPTEN ; then
367371
host_os=emscripten
368-
cpu=wasm32
369372
cross_compile="yes"
370373
else
371374
# This is a fatal error, but don't report it yet, because we
@@ -425,6 +428,8 @@ elif check_define __aarch64__ ; then
425428
cpu="aarch64"
426429
elif check_define __loongarch64 ; then
427430
cpu="loongarch64"
431+
elif check_define EMSCRIPTEN ; then
432+
error_exit "wasm32 or wasm64 must be specified to the cpu flag"
428433
else
429434
# Using uname is really broken, but it is just a fallback for architectures
430435
# that are going to use TCI anyway
@@ -536,6 +541,9 @@ case "$cpu" in
536541
wasm32)
537542
CPU_CFLAGS="-m32"
538543
;;
544+
wasm64)
545+
CPU_CFLAGS="-m64 -sMEMORY64=$wasm64_memory64"
546+
;;
539547
esac
540548

541549
if test -n "$host_arch" && {

meson.build

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ qapi_trace_events = []
5252
bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
5353
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux', 'emscripten']
5454
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
55-
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'wasm32']
55+
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'wasm32', 'wasm64']
5656

5757
cpu = host_machine.cpu_family()
5858

@@ -393,6 +393,12 @@ elif host_os == 'windows'
393393
if compiler.get_id() == 'clang' and compiler.get_linker_id() != 'ld.lld'
394394
error('On windows, you need to use lld with clang - use msys2 clang64/clangarm64 env')
395395
endif
396+
elif host_os == 'emscripten'
397+
if cpu == 'wasm64'
398+
memory64 = get_option('wasm64_memory64')
399+
qemu_common_flags += ['-DWASM64_MEMORY64=' + memory64]
400+
qemu_ldflags += ['-sMEMORY64=' + memory64, '-DWASM64_MEMORY64=' + memory64]
401+
endif
396402
endif
397403

398404
# Choose instruction set (currently x86-only)
@@ -916,7 +922,7 @@ if have_tcg
916922
if not get_option('tcg_interpreter')
917923
error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
918924
endif
919-
elif host_arch == 'wasm32'
925+
elif host_arch == 'wasm32' or host_arch == 'wasm64'
920926
if not get_option('tcg_interpreter')
921927
error('WebAssembly host requires --enable-tcg-interpreter')
922928
endif

meson_options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,6 @@ option('rust', type: 'feature', value: 'disabled',
382382
description: 'Rust support')
383383
option('strict_rust_lints', type: 'boolean', value: false,
384384
description: 'Enable stricter set of Rust warnings')
385+
386+
option('wasm64_memory64', type: 'combo', choices: ['1', '2'],
387+
description: 'Used only for wasm64 build. Set -sMEMORY64 of Emscripten to 1(default) or 2')

scripts/meson-buildoptions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ meson_options_help() {
7979
printf "%s\n" ' --sysconfdir=VALUE Sysconf data directory [etc]'
8080
printf "%s\n" ' --tls-priority=VALUE Default TLS protocol/cipher priority string'
8181
printf "%s\n" ' [NORMAL]'
82+
printf "%s\n" ' --wasm64-memory64=CHOICE Used only for wasm64 build. Set -sMEMORY64 of'
83+
printf "%s\n" ' Emscripten to 1(default) or 2 [1] (choices: 1/2)'
8284
printf "%s\n" ' --with-coroutine=CHOICE coroutine backend to use (choices:'
8385
printf "%s\n" ' auto/sigaltstack/ucontext/wasm/windows)'
8486
printf "%s\n" ' --with-pkgversion=VALUE use specified string as sub-version of the'
@@ -565,6 +567,7 @@ _meson_option_parse() {
565567
--disable-vte) printf "%s" -Dvte=disabled ;;
566568
--enable-vvfat) printf "%s" -Dvvfat=enabled ;;
567569
--disable-vvfat) printf "%s" -Dvvfat=disabled ;;
570+
--wasm64-memory64=*) quote_sh "-Dwasm64_memory64=$2" ;;
568571
--enable-werror) printf "%s" -Dwerror=true ;;
569572
--disable-werror) printf "%s" -Dwerror=false ;;
570573
--enable-whpx) printf "%s" -Dwhpx=enabled ;;

tests/docker/dockerfiles/emsdk-wasm32-cross.docker renamed to tests/docker/dockerfiles/emsdk-wasm-cross.docker

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# syntax = docker/dockerfile:1.5
22

3-
ARG EMSDK_VERSION_QEMU=3.1.50
3+
ARG EMSDK_VERSION_QEMU=4.0.10
44
ARG ZLIB_VERSION=1.3.1
55
ARG GLIB_MINOR_VERSION=2.84
66
ARG GLIB_VERSION=${GLIB_MINOR_VERSION}.0
77
ARG PIXMAN_VERSION=0.44.2
8-
ARG FFI_VERSION=v3.4.7
8+
ARG FFI_VERSION=memory64-2
99
ARG MESON_VERSION=1.5.0
10+
ARG TARGET_CPU=wasm32
11+
ARG WASM64_MEMORY64=0
1012

11-
FROM emscripten/emsdk:$EMSDK_VERSION_QEMU AS build-base
13+
FROM emscripten/emsdk:$EMSDK_VERSION_QEMU AS build-base-common
14+
ARG TARGET_CPU
1215
ARG MESON_VERSION
1316
ENV TARGET=/builddeps/target
1417
ENV CPATH="$TARGET/include"
@@ -33,8 +36,8 @@ RUN <<EOF
3336
cat <<EOT > /cross.meson
3437
[host_machine]
3538
system = 'emscripten'
36-
cpu_family = 'wasm32'
37-
cpu = 'wasm32'
39+
cpu_family = '${TARGET_CPU}'
40+
cpu = '${TARGET_CPU}'
3841
endian = 'little'
3942

4043
[binaries]
@@ -46,6 +49,16 @@ pkgconfig = ['pkg-config', '--static']
4649
EOT
4750
EOF
4851

52+
FROM build-base-common AS build-base-wasm32
53+
54+
FROM build-base-common AS build-base-wasm64
55+
ARG WASM64_MEMORY64
56+
ENV CFLAGS="$CFLAGS -sMEMORY64=${WASM64_MEMORY64}"
57+
ENV CXXFLAGS="$CFLAGS"
58+
ENV LDFLAGS="$LDFLAGS -sMEMORY64=${WASM64_MEMORY64}"
59+
60+
FROM build-base-${TARGET_CPU} AS build-base
61+
4962
FROM build-base AS zlib-dev
5063
ARG ZLIB_VERSION
5164
RUN mkdir -p /zlib
@@ -56,17 +69,19 @@ RUN emconfigure ./configure --prefix=$TARGET --static
5669
RUN emmake make install -j$(nproc)
5770

5871
FROM build-base AS libffi-dev
72+
ARG TARGET_CPU
73+
ARG WASM64_MEMORY64
5974
ARG FFI_VERSION
6075
RUN mkdir -p /libffi
61-
RUN git clone https://github.com/libffi/libffi /libffi
76+
RUN git clone https://github.com/ktock/libffi /libffi
6277
WORKDIR /libffi
6378
RUN git checkout $FFI_VERSION
6479
RUN autoreconf -fiv
65-
RUN emconfigure ./configure --host=wasm32-unknown-linux \
80+
RUN emconfigure ./configure --host=${TARGET_CPU}-unknown-linux \
6681
--prefix=$TARGET --enable-static \
6782
--disable-shared --disable-dependency-tracking \
6883
--disable-builddir --disable-multi-os-directory \
69-
--disable-raw-api --disable-docs
84+
--disable-raw-api --disable-docs WASM64_MEMORY64=${WASM64_MEMORY64}
7085
RUN emmake make install SUBDIRS='include' -j$(nproc)
7186

7287
FROM build-base AS pixman-dev

0 commit comments

Comments
 (0)