Skip to content

Commit 12a81c4

Browse files
committed
Added support for wasm32-wasi target
1 parent d523d40 commit 12a81c4

File tree

6 files changed

+80
-14
lines changed

6 files changed

+80
-14
lines changed

.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ jobs:
5959
- target: x86_64-pc-windows-gnu
6060
rust: stable
6161
os: ubuntu-latest
62-
# - target: asmjs-unknown-emscripten
63-
# rust: stable
64-
# os: ubuntu-latest
62+
- target: wasm32-wasi
63+
rust: stable
64+
os: ubuntu-latest
6565
- target: i686-pc-windows-msvc
6666
rust: stable-i686-msvc
6767
os: windows-2016

ci/docker/asmjs-unknown-emscripten/Dockerfile

-3
This file was deleted.

ci/docker/wasm32-wasi/Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
ca-certificates \
5+
curl wget \
6+
make \
7+
perl \
8+
gcc \
9+
xz-utils \
10+
libc6-dev
11+
12+
# cargo-wasi setup (cargo-wasi depends on wasmtime to be present)
13+
RUN curl https://wasmtime.dev/install.sh -sSf | bash
14+
ENV PATH="$PATH:/root/.wasmtime/bin"
15+
16+
# Install WASI-SDK
17+
ENV WASI_VERSION=14
18+
ENV WASI_VERSION_FULL=${WASI_VERSION}.0
19+
RUN wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
20+
RUN tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz -C /root
21+
22+
# WASI env setup
23+
ENV WASI_SDK_PATH=/root/wasi-sdk-${WASI_VERSION_FULL}
24+
ENV CC_wasm32-wasi="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"
25+
ENV CARGO_TARGET_WASM32_WASI_LINKER="${WASI_SDK_PATH}/bin/clang"
26+
27+
ENV RUSTFLAGS=-Ctarget-feature=-crt-static
28+

ci/run-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ docker run \
2222
--env CARGO_HOME=/cargo \
2323
--workdir /usr/code \
2424
openssl-src-ci \
25-
bash -c "PATH=\$PATH:/rust/bin ci/run.sh $target"
25+
bash -c "PATH=\"\$PATH:/rust/bin:/cargo/bin\" ci/run.sh $target"
2626

ci/run.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
target=$1
44
testcrate_dir="$(pwd)/testcrate"
5+
56
set -ex
67

7-
if [ "$1" = "aarch64-apple-darwin" ] ; then
8-
export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUNNER=echo
9-
fi
8+
export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUNNER=echo
9+
export CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime
1010

11-
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $1 -vv
12-
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $1 -vv --release
11+
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $target -vvv
12+
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $target -vvv --release
1313

1414
if [ "$1" = "x86_64-unknown-linux-gnu" ] ; then
15-
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $1 -vv --all-features
15+
cargo test --manifest-path "$testcrate_dir/Cargo.toml" --target $target -vvv --all-features
1616

1717
# Run a few tests here:
1818
#
@@ -35,5 +35,5 @@ if [ "$1" = "x86_64-unknown-linux-gnu" ] ; then
3535
rm "$crate"
3636
cd target/ci/package/openssl-src-*
3737
cp -r "$testcrate_dir" .
38-
cargo test --manifest-path "testcrate/Cargo.toml" --target $1 -vv
38+
cargo test --manifest-path "testcrate/Cargo.toml" --target $target -vv
3939
fi

src/lib.rs

+41
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,42 @@ impl Build {
428428
configure.arg("-D__STDC_NO_ATOMICS__");
429429
}
430430

431+
if target.contains("wasi") {
432+
configure.args([
433+
// Termios isn't available whatsoever on WASM/WASI so we disable that
434+
// fatal error: 'termios.h' file not found
435+
"no-ui-console",
436+
// WASI doesn't support UNIX sockets so we preemptively disable it
437+
"no-sock",
438+
// WASI doesn't have a concept of syslog, so we disable it
439+
// fatal error: 'syslog.h' file not found
440+
"-DNO_SYSLOG",
441+
// WASI doesn't support (p)threads. Disabling preemptively.
442+
"no-threads",
443+
// WASI/WASM aren't really friends with ASM, so we disable it as well.
444+
"no-asm",
445+
// Disables the AFALG engine (AFALG-ENGine)
446+
// Since AFALG depends on `AF_ALG` support on the linux kernel side
447+
// it makes sense that we can't use it.
448+
"no-afalgeng",
449+
"-DOPENSSL_NO_AFALGENG=1",
450+
// wasm lacks signal support; to enable minimal signal emulation, compile with
451+
// -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal
452+
"-D_WASI_EMULATED_SIGNAL",
453+
// WASI lacks process-associated clocks; to enable emulation of the `times` function using the wall
454+
// clock, which isn't sensitive to whether the program is running or suspended, compile with
455+
// -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks
456+
"-D_WASI_EMULATED_PROCESS_CLOCKS",
457+
// WASI lacks a true mmap; to enable minimal mmap emulation, compile
458+
// with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman
459+
"-D_WASI_EMULATED_MMAN",
460+
// WASI lacks process identifiers; to enable emulation of the `getpid` function using a
461+
// placeholder value, which doesn't reflect the host PID of the program, compile with
462+
// -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid
463+
"-D_WASI_EMULATED_GETPID",
464+
]);
465+
}
466+
431467
if target.contains("musl") {
432468
// Hack around openssl/openssl#7207 for now
433469
configure.arg("-DOPENSSL_NO_SECURE_MEMORY");
@@ -578,6 +614,11 @@ impl Artifacts {
578614
println!("cargo:lib={}", self.lib_dir.display());
579615
if self.target.contains("msvc") {
580616
println!("cargo:rustc-link-lib=user32");
617+
} else if self.target == "wasm32-wasi" {
618+
println!("cargo:rustc-link-lib=wasi-emulated-signal");
619+
println!("cargo:rustc-link-lib=wasi-emulated-process-clocks");
620+
println!("cargo:rustc-link-lib=wasi-emulated-mman");
621+
println!("cargo:rustc-link-lib=wasi-emulated-getpid");
581622
}
582623
}
583624
}

0 commit comments

Comments
 (0)