Skip to content

Commit

Permalink
Fix compilation on wasm32-wasi target (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron authored Dec 12, 2023
1 parent 6981c34 commit 4af5805
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .evergreen/compile-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ set -o errexit
. ~/.cargo/env
rustup update $RUST_VERSION

if [ ! -z "$TARGET" ]; then
rustup target add $TARGET --toolchain $RUST_VERSION
TARGET="--target=$TARGET"
fi

# pin all dependencies when checking msrv compilation
if [ "$MSRV" = "true" ]; then
if [ "$MSRV" = "true" ]; then
cp .evergreen/Cargo.lock.msrv Cargo.lock
fi

rustup run $RUST_VERSION cargo build
rustup run $RUST_VERSION cargo build $TARGET
15 changes: 14 additions & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ functions:
working_dir: "src"
script: |
${PREPARE_SHELL}
RUST_VERSION=${RUST_VERSION} MSRV=${MSRV} .evergreen/compile-only.sh
RUST_VERSION=${RUST_VERSION} MSRV=${MSRV} TARGET=${TARGET} .evergreen/compile-only.sh
"check rustfmt":
- command: shell.exec
Expand Down Expand Up @@ -203,6 +203,18 @@ axes:
display_name: "nightly"
variables:
RUST_VERSION: "nightly"
- id: "extra-targets"
values:
- id: "current"
display_name: "current target"
- id: "wasi"
display_name: "WASI"
variables:
TARGET: "wasm32-wasi"
- id: "wasm"
display_name: "WASM"
variables:
TARGET: "wasm32-unknown-unknown"

buildvariants:
-
Expand All @@ -216,6 +228,7 @@ buildvariants:
- matrix_name: "compile only"
matrix_spec:
extra-rust-versions: "*"
extra-targets: "*"
display_name: "Compile on Rust ${extra-rust-versions}"
run_on:
- ubuntu1804-test
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ serde_with = { version = "1.3.1", optional = true }
serde_with-3 = { package = "serde_with", version = "3.1.0", optional = true }
time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }
bitvec = "1.0.1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
js-sys = "0.3"

[dev-dependencies]
assert_matches = "1.2"
criterion = "0.3.0"
pretty_assertions = "0.6.1"
proptest = "1.0.0"
serde_bytes = "0.11"
chrono = { version = "0.4", features = ["serde", "clock", "std"], default-features = false }
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::atomic::{AtomicUsize, Ordering},
};

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

use hex::{self, FromHexError};
Expand Down

0 comments on commit 4af5805

Please # to comment.