Skip to content

Commit 4ee4359

Browse files
chore: fix wasi build on windows
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent 8299745 commit 4ee4359

8 files changed

Lines changed: 102 additions & 25 deletions

File tree

‎.github/workflows/test.yaml‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,43 @@ jobs:
1919
- os: ubuntu-26.04
2020
rust: stable
2121
name: "Linux x86 (stable)"
22+
target: x86_64-unknown-linux-gnu
2223
- os: ubuntu-26.04
2324
rust: nightly
2425
name: "Linux x86 (nightly)"
26+
target: x86_64-unknown-linux-gnu
2527
- os: ubuntu-26.04
2628
rust: nightly
2729
name: "Linux x86 (nightly tail calls)"
30+
target: x86_64-unknown-linux-gnu
2831
args: "--features tinywasm/nightly-tail-calls"
2932
- os: ubuntu-26.04
3033
rust: stable
3134
name: "Linux x86 (stable, no default features)"
35+
target: x86_64-unknown-linux-gnu
3236
args: "--no-default-features"
3337
- os: ubuntu-26.04
3438
rust: nightly
3539
name: "Linux x86 (nightly, no default features)"
40+
target: x86_64-unknown-linux-gnu
3641
args: "--no-default-features"
3742
- os: ubuntu-26.04
3843
rust: nightly
3944
name: "Linux x86 (nightly tail calls, no default features)"
45+
target: x86_64-unknown-linux-gnu
4046
args: "--no-default-features --features tinywasm/nightly-tail-calls"
4147
- os: macos-26
4248
rust: stable
4349
name: "macOS arm64 (Apple M1)"
50+
target: aarch64-apple-darwin
4451
- os: windows-2025
4552
rust: stable
4653
name: "Windows x86_64"
54+
target: x86_64-pc-windows-msvc
4755
- os: ubuntu-26.04-arm
4856
rust: stable
4957
name: "Linux arm64"
58+
target: aarch64-unknown-linux-gnu
5059
- os: ubuntu-26.04-arm
5160
rust: stable
5261
name: "Linux armv7"
@@ -65,33 +74,25 @@ jobs:
6574
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0
6675
with:
6776
toolchain: ${{ matrix.rust }}
77+
target: ${{ matrix.target }}
6878
rustflags: ""
79+
build-warnings: warn
6980
components: rustfmt, clippy
70-
if: matrix.target == ''
71-
72-
- name: Run tests
73-
run: cargo test --workspace ${{ matrix.args }} && cargo test --workspace ${{ matrix.args }} --examples
74-
if: matrix.target == ''
75-
76-
- name: Run clippy
77-
run: cargo clippy --workspace ${{ matrix.args }}
78-
if: matrix.target == ''
7981

8082
- name: Install armv7 tools
8183
run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf qemu-user
82-
if: matrix.target != ''
84+
if: matrix.target == 'armv7-unknown-linux-gnueabihf'
8385

84-
- name: Install Rust toolchain (${{ matrix.target }})
85-
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0
86-
with:
87-
toolchain: ${{ matrix.rust }}
88-
target: ${{ matrix.target }}
89-
rustflags: ""
90-
if: matrix.target != ''
91-
92-
- name: Run tests (${{ matrix.target }})
93-
run: cargo test --workspace --target ${{ matrix.target }}
86+
- name: Run tests
87+
run: cargo test --workspace --target ${{ matrix.target }} ${{ matrix.args }}
9488
env:
9589
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
9690
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER: qemu-arm -L /usr/arm-linux-gnueabihf
97-
if: matrix.target != ''
91+
92+
- name: Run examples
93+
run: cargo test --workspace --target ${{ matrix.target }} ${{ matrix.args }} --examples
94+
if: matrix.target != 'armv7-unknown-linux-gnueabihf'
95+
96+
- name: Run clippy
97+
run: cargo clippy --workspace --target ${{ matrix.target }} ${{ matrix.args }}
98+
if: matrix.target != 'armv7-unknown-linux-gnueabihf'

‎crates/cli/src/testsuite.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ impl TestSuite {
103103
use std::fs::OpenOptions;
104104
use std::io::Write;
105105

106-
let mut file = OpenOptions::new().create(true).append(true).read(true).open(path)?;
106+
if std::env::var("CI").is_ok_and(|value| value == "true") {
107+
return Ok(());
108+
}
109+
110+
let mut file = OpenOptions::new().create(true).read(true).write(true).open(path)?;
107111
let last_line = BufReader::new(&file).lines().last().transpose()?;
108112

109113
if let Some(last) = last_line

‎crates/wasi/src/p1/abi.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(super) const INTR: Errno = Errno(27);
3131
pub(super) const INVAL: Errno = Errno(28);
3232
pub(super) const IO: Errno = Errno(29);
3333
pub(super) const ISDIR: Errno = Errno(31);
34+
#[cfg(any(unix, target_os = "android"))]
3435
pub(super) const LOOP: Errno = Errno(32);
3536
pub(super) const MFILE: Errno = Errno(33);
3637
pub(super) const MLINK: Errno = Errno(34);
@@ -41,6 +42,7 @@ pub(super) const NOSPC: Errno = Errno(51);
4142
pub(super) const NOTCONN: Errno = Errno(53);
4243
pub(super) const NOTDIR: Errno = Errno(54);
4344
pub(super) const NOTEMPTY: Errno = Errno(55);
45+
#[cfg(unix)]
4446
pub(super) const NOTSOCK: Errno = Errno(57);
4547
pub(super) const NOTSUP: Errno = Errno(58);
4648
pub(super) const OVERFLOW: Errno = Errno(61);
@@ -187,6 +189,7 @@ fn platform_io_errno(_error: &io::Error) -> Errno {
187189
IO
188190
}
189191

192+
#[cfg(unix)]
190193
impl From<rustix::io::Errno> for Errno {
191194
fn from(error: rustix::io::Errno) -> Self {
192195
use rustix::io::Errno as E;

‎crates/wasi/src/p1/imports/fd.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::io::{Read, Seek, SeekFrom, Write};
22

33
use cap_fs_ext::{DirEntryExt, DirExt, MetadataExt};
4+
#[cfg(unix)]
45
use cap_std::fs::FileExt;
56
use tinywasm::FuncContext;
67

@@ -185,9 +186,12 @@ fn read_from_fd(
185186
buffer.resize(iovecs.byte_len, 0);
186187
let read = match &mut descriptor.resource {
187188
Resource::Stdin => std::io::stdin().lock().read(&mut buffer),
189+
#[cfg(unix)]
188190
Resource::File(file) if let Some(offset) = offset => {
189191
file.read_at(&mut buffer, checked_offset(offset, iovecs.byte_len)?)
190192
}
193+
#[cfg(not(unix))]
194+
Resource::File(_) if offset.is_some() => return Ok(NOTSUP),
191195
Resource::File(file) => file.read(&mut buffer),
192196
Resource::TcpStream(stream) => stream.read(&mut buffer),
193197
Resource::UdpSocket(socket) => socket.recv(&mut buffer),
@@ -224,7 +228,10 @@ fn write_to_fd(
224228
let written = match &mut descriptor.resource {
225229
Resource::Stdout => std::io::stdout().lock().write(&data),
226230
Resource::Stderr => std::io::stderr().lock().write(&data),
231+
#[cfg(unix)]
227232
Resource::File(file) if let Some(offset) = offset => file.write_at(&data, checked_offset(offset, data.len())?),
233+
#[cfg(not(unix))]
234+
Resource::File(_) if offset.is_some() => return Ok(NOTSUP),
228235
Resource::File(file) => file.write(&data),
229236
Resource::TcpStream(stream) => stream.write(&data),
230237
Resource::UdpSocket(socket) => socket.send(&data),
@@ -237,6 +244,7 @@ fn write_to_fd(
237244
.map_or_else(|errno| errno, |()| SUCCESS))
238245
}
239246

247+
#[cfg(unix)]
240248
fn checked_offset(offset: u64, len: usize) -> Result<u64, Errno> {
241249
offset.checked_add(len as u64).map(|_| offset).ok_or(OVERFLOW)
242250
}

‎crates/wasi/src/p1/imports/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ mod path;
55
mod poll;
66
mod process;
77
mod random;
8+
#[cfg(unix)]
9+
mod sock;
10+
#[cfg(not(unix))]
11+
#[path = "sock_windows.rs"]
812
mod sock;
913

1014
use tinywasm::{HostFunction, Imports};

‎crates/wasi/src/p1/imports/poll.rs‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io::Seek;
22

3+
#[cfg(unix)]
34
use rustix::event::{PollFd, PollFlags, Timespec};
45
use tinywasm::FuncContext;
56

@@ -12,6 +13,7 @@ use super::WasiResult;
1213
enum Readiness {
1314
Ready,
1415
Clock(u64),
16+
#[cfg(unix)]
1517
Poll,
1618
}
1719

@@ -20,12 +22,16 @@ struct PendingEvent {
2022
readiness: Readiness,
2123
}
2224

25+
#[cfg(unix)]
2326
struct PollTarget {
2427
event_index: usize,
2528
fd: i32,
2629
event_type: u8,
2730
}
2831

32+
#[cfg(not(unix))]
33+
struct PollTarget;
34+
2935
impl PendingEvent {
3036
fn new(userdata: u64, error: Errno, event_type: u8, available: u64, readiness: Readiness) -> Self {
3137
let mut bytes = [0; 32];
@@ -134,11 +140,21 @@ fn subscribe_fd(
134140
pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, available, Readiness::Ready));
135141
return Ok(());
136142
}
137-
poll_targets.push(PollTarget { event_index: pending_events.len(), fd, event_type });
138-
pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, 0, Readiness::Poll));
139-
Ok(())
143+
#[cfg(not(unix))]
144+
{
145+
let _ = poll_targets;
146+
pending_events.push(PendingEvent::new(userdata, NOTSUP, event_type, 0, Readiness::Ready));
147+
Ok(())
148+
}
149+
#[cfg(unix)]
150+
{
151+
poll_targets.push(PollTarget { event_index: pending_events.len(), fd, event_type });
152+
pending_events.push(PendingEvent::new(userdata, SUCCESS, event_type, 0, Readiness::Poll));
153+
Ok(())
154+
}
140155
}
141156

157+
#[cfg(unix)]
142158
fn wait_for_events(
143159
ctx: &FuncContext<'_>,
144160
poll_targets: &[PollTarget],
@@ -217,3 +233,21 @@ fn wait_for_events(
217233
}
218234
Ok(u64::try_from(started.elapsed().as_nanos()).unwrap_or(u64::MAX))
219235
}
236+
237+
#[cfg(not(unix))]
238+
fn wait_for_events(
239+
_ctx: &FuncContext<'_>,
240+
poll_targets: &[PollTarget],
241+
_pending_events: &mut [PendingEvent],
242+
timeout_ns: Option<u64>,
243+
) -> WasiResult<u64> {
244+
if !poll_targets.is_empty() {
245+
return Err(NOTSUP.into());
246+
}
247+
if let Some(nanoseconds) = timeout_ns {
248+
std::thread::sleep(std::time::Duration::from_nanos(nanoseconds));
249+
Ok(nanoseconds)
250+
} else {
251+
Ok(0)
252+
}
253+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use tinywasm::FuncContext;
2+
3+
use crate::p1::abi::{Errno, NOTSUP};
4+
5+
use super::WasiResult;
6+
7+
pub(super) fn sock_accept(_ctx: FuncContext<'_>, _args: (i32, i32, i32)) -> WasiResult<Errno> {
8+
Ok(NOTSUP)
9+
}
10+
11+
pub(super) fn sock_recv(_ctx: FuncContext<'_>, _args: (i32, i32, i32, i32, i32, i32)) -> WasiResult<Errno> {
12+
Ok(NOTSUP)
13+
}
14+
15+
pub(super) fn sock_send(_ctx: FuncContext<'_>, _args: (i32, i32, i32, i32, i32)) -> WasiResult<Errno> {
16+
Ok(NOTSUP)
17+
}
18+
19+
pub(super) fn sock_shutdown(_ctx: FuncContext<'_>, _args: (i32, i32)) -> WasiResult<Errno> {
20+
Ok(NOTSUP)
21+
}

‎crates/wasi/tests/p1.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ fn provides_clocks_randomness_and_timer_polling() -> tinywasm::Result<()> {
236236
Ok(())
237237
}
238238

239+
#[cfg(unix)]
239240
#[test]
240241
fn polls_accepts_and_uses_tcp_streams() -> tinywasm::Result<()> {
241242
use std::io::{Read, Write};
@@ -282,6 +283,7 @@ fn polls_accepts_and_uses_tcp_streams() -> tinywasm::Result<()> {
282283
Ok(())
283284
}
284285

286+
#[cfg(unix)]
285287
#[test]
286288
fn sends_and_receives_udp_datagrams() -> tinywasm::Result<()> {
287289
let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();

0 commit comments

Comments
 (0)