Skip to content

Commit 7ef2870

Browse files
authored
Merge pull request #190 from bschoenmaeckers/wasi
Add wasi support
2 parents 3e5688c + 5c72c92 commit 7ef2870

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.github/workflows/rust.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ jobs:
108108
tool: wasm-pack
109109
- run: wasm-pack test --node
110110

111+
test-wasi:
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
toolchain:
116+
- stable
117+
- nightly
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Checkout
121+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
122+
with:
123+
persist-credentials: false
124+
- name: Install Rust
125+
run: |
126+
rustup toolchain install ${{ matrix.toolchain }} --profile minimal --no-self-update --target wasm32-wasip1
127+
rustup default ${{ matrix.toolchain }}
128+
- env:
129+
CARGO_BUILD_TARGET: wasm32-wasip1
130+
run: cargo build --release --examples
131+
- name: Install wasmtime
132+
uses: bytecodealliance/actions/wasmtime/setup@6aecabac1eb1dcf7ed94ba9471974415ee2ebef2 # v1
133+
- name: Run example using wasmtime
134+
run: wasmtime ./target/wasm32-wasip1/release/examples/get_timezone.wasm
135+
111136
test-emscripten:
112137
strategy:
113138
fail-fast: false

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ mod ffi_utils;
6464
#[cfg_attr(target_os = "aix", path = "tz_aix.rs")]
6565
#[cfg_attr(target_os = "android", path = "tz_android.rs")]
6666
#[cfg_attr(target_os = "haiku", path = "tz_haiku.rs")]
67+
#[cfg_attr(
68+
all(target_arch = "wasm32", target_os = "wasi"),
69+
path = "tz_wasm32_wasi.rs"
70+
)]
6771
mod platform;
6872

6973
/// Error types

src/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ pub fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
55
#[cfg(not(feature = "fallback"))]
66
compile_error!(
77
"iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \
8-
OpenBSD, Dragonfly, WebAssembly (browser), emscripten, iOS, Illumos, Android, AIX, Solaris and Haiku.",
8+
OpenBSD, Dragonfly, WebAssembly (browser), wasip, emscripten, iOS, Illumos, Android, AIX, Solaris and Haiku.",
99
);

src/tz_wasm32_wasi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
2+
std::env::var("TZ").or_else(|_| Ok("Etc/UTC".to_owned()))
3+
}

0 commit comments

Comments
 (0)