Skip to content

Commit f0ad80c

Browse files
committed
Fix compilation on wasm32-wasi.
WASI doesn't yet have `F_DUPFD_CLOEXEC`, so mark `try_clone` as unsupported on wasm32-wasi for now. And, add a CI check for WASI.
1 parent 44d01be commit f0ad80c

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

.github/workflows/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,26 @@ jobs:
7676
toolchain: ${{ matrix.rust }}
7777
- run: cargo test --workspace --all-features
7878
- run: cargo test --workspace --no-default-features
79+
80+
check_nightly:
81+
name: Check on Rust nightly
82+
runs-on: ${{ matrix.os }}
83+
strategy:
84+
matrix:
85+
build: [nightly]
86+
include:
87+
- build: nightly
88+
os: ubuntu-latest
89+
rust: nightly
90+
91+
steps:
92+
- uses: actions/checkout@v2
93+
with:
94+
submodules: true
95+
- uses: ./.github/actions/install-rust
96+
with:
97+
toolchain: ${{ matrix.rust }}
98+
- run: >
99+
rustup target add
100+
wasm32-wasi
101+
- run: cargo check --workspace --release -vv --target=wasm32-wasi

src/types.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,33 @@ impl OwnedFd {
137137
pub fn try_clone(&self) -> std::io::Result<Self> {
138138
#[cfg(feature = "close")]
139139
{
140-
// We want to atomically duplicate this file descriptor and set the
141-
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
142-
// is a POSIX flag that was added to Linux in 2.6.24.
143-
#[cfg(not(target_os = "espidf"))]
144-
let cmd = libc::F_DUPFD_CLOEXEC;
145-
146-
// For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
147-
// will never be supported, as this is a bare metal framework with
148-
// no capabilities for multi-process execution. While F_DUPFD is also
149-
// not supported yet, it might be (currently it returns ENOSYS).
150-
#[cfg(target_os = "espidf")]
151-
let cmd = libc::F_DUPFD;
152-
153-
let fd = match unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) } {
154-
-1 => return Err(std::io::Error::last_os_error()),
155-
fd => fd,
156-
};
157-
Ok(unsafe { Self::from_raw_fd(fd) })
140+
#[cfg(unix)]
141+
{
142+
// We want to atomically duplicate this file descriptor and set the
143+
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
144+
// is a POSIX flag that was added to Linux in 2.6.24.
145+
#[cfg(not(target_os = "espidf"))]
146+
let cmd = libc::F_DUPFD_CLOEXEC;
147+
148+
// For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics
149+
// will never be supported, as this is a bare metal framework with
150+
// no capabilities for multi-process execution. While F_DUPFD is also
151+
// not supported yet, it might be (currently it returns ENOSYS).
152+
#[cfg(target_os = "espidf")]
153+
let cmd = libc::F_DUPFD;
154+
155+
let fd = match unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) } {
156+
-1 => return Err(std::io::Error::last_os_error()),
157+
fd => fd,
158+
};
159+
160+
Ok(unsafe { Self::from_raw_fd(fd) })
161+
}
162+
163+
#[cfg(target_os = "wasi")]
164+
{
165+
unreachable!("try_clone is not yet suppported on wasi");
166+
}
158167
}
159168

160169
// If the `close` feature is disabled, we expect users to avoid cloning

0 commit comments

Comments
 (0)