Skip to content

Commit 1fdad73

Browse files
abr-egntyranron
andauthored
Fix compilation on wasm32-wasi target (#445) (#446)
Co-authored-by: Kai Ren <[email protected]>
1 parent e012ed3 commit 1fdad73

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.evergreen/compile-only.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ set -o errexit
55
. ~/.cargo/env
66
rustup update $RUST_VERSION
77

8+
if [ ! -z "$TARGET" ]; then
9+
rustup target add $TARGET --toolchain $RUST_VERSION
10+
TARGET="--target=$TARGET"
11+
fi
12+
813
# pin all dependencies when checking msrv compilation
9-
if [ "$MSRV" = "true" ]; then
14+
if [ "$MSRV" = "true" ]; then
1015
cp .evergreen/Cargo.lock.msrv Cargo.lock
1116
fi
1217

13-
rustup run $RUST_VERSION cargo build
18+
rustup run $RUST_VERSION cargo build $TARGET

.evergreen/config.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ functions:
9090
working_dir: "src"
9191
script: |
9292
${PREPARE_SHELL}
93-
RUST_VERSION=${RUST_VERSION} MSRV=${MSRV} .evergreen/compile-only.sh
93+
RUST_VERSION=${RUST_VERSION} MSRV=${MSRV} TARGET=${TARGET} .evergreen/compile-only.sh
9494
9595
"check rustfmt":
9696
- command: shell.exec
@@ -203,6 +203,18 @@ axes:
203203
display_name: "nightly"
204204
variables:
205205
RUST_VERSION: "nightly"
206+
- id: "extra-targets"
207+
values:
208+
- id: "current"
209+
display_name: "current target"
210+
- id: "wasi"
211+
display_name: "WASI"
212+
variables:
213+
TARGET: "wasm32-wasi"
214+
- id: "wasm"
215+
display_name: "WASM"
216+
variables:
217+
TARGET: "wasm32-unknown-unknown"
206218

207219
buildvariants:
208220
-
@@ -216,6 +228,7 @@ buildvariants:
216228
- matrix_name: "compile only"
217229
matrix_spec:
218230
extra-rust-versions: "*"
231+
extra-targets: "*"
219232
display_name: "Compile on Rust ${extra-rust-versions}"
220233
run_on:
221234
- ubuntu1804-test

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@ serde_with = { version = "1.3.1", optional = true }
6969
serde_with-3 = { package = "serde_with", version = "3.1.0", optional = true }
7070
time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }
7171
bitvec = "1.0.1"
72-
7372
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
7473
js-sys = "0.3"
74+
7575
[dev-dependencies]
7676
assert_matches = "1.2"
7777
criterion = "0.3.0"
7878
pretty_assertions = "0.6.1"
7979
proptest = "1.0.0"
8080
serde_bytes = "0.11"
8181
chrono = { version = "0.4", features = ["serde", "clock", "std"], default-features = false }
82+
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
83+
getrandom = { version = "0.2", features = ["js"] }
8284

8385
[package.metadata.docs.rs]
8486
all-features = true

src/oid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
sync::atomic::{AtomicUsize, Ordering},
1010
};
1111

12-
#[cfg(not(target_arch = "wasm32"))]
12+
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
1313
use std::{convert::TryInto, time::SystemTime};
1414

1515
use hex::{self, FromHexError};

0 commit comments

Comments
 (0)