Skip to content

Commit 22aef0f

Browse files
Rollup merge of #155406 - alexcrichton:update-wasi-deps, r=Mark-Simulacrum
std: Update dependency on `wasi` crate This commit updates the crate dependency that the standard library has on the `wasi` crate. This is now updated to depending explicitly on the `wasip1` crate and the `wasip2` crate published on crates.io. These crates are managed in the [same location][repo] as the `wasi` crate and represent a different versioning scheme which doesn't require multi-version WASI support to require depending on the same crate at multiple versions. The code in libstd is updated to reference `wasip1` and `wasip2` directly as well. [repo]: https://github.com/bytecodealliance/wasi-rs
2 parents 5c89655 + 690be3e commit 22aef0f

9 files changed

Lines changed: 65 additions & 59 deletions

File tree

library/Cargo.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ dependencies = [
344344
"std_detect",
345345
"unwind",
346346
"vex-sdk",
347-
"wasi 0.11.1+wasi-snapshot-preview1",
348-
"wasi 0.14.4+wasi-0.2.4",
347+
"wasip1",
348+
"wasip2",
349349
"windows-link 0.0.0",
350350
]
351351

@@ -407,20 +407,20 @@ dependencies = [
407407
]
408408

409409
[[package]]
410-
name = "wasi"
411-
version = "0.11.1+wasi-snapshot-preview1"
410+
name = "wasip1"
411+
version = "1.0.0"
412412
source = "registry+https://github.com/rust-lang/crates.io-index"
413-
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
413+
checksum = "b5e26842486624357dbeb8f0381cf1fb42f022291fd787d4a816768fec8cc760"
414414
dependencies = [
415415
"rustc-std-workspace-alloc",
416416
"rustc-std-workspace-core",
417417
]
418418

419419
[[package]]
420-
name = "wasi"
421-
version = "0.14.4+wasi-0.2.4"
420+
name = "wasip2"
421+
version = "1.0.2+wasi-0.2.9"
422422
source = "registry+https://github.com/rust-lang/crates.io-index"
423-
checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a"
423+
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
424424
dependencies = [
425425
"rustc-std-workspace-alloc",
426426
"rustc-std-workspace-core",
@@ -513,9 +513,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
513513

514514
[[package]]
515515
name = "wit-bindgen"
516-
version = "0.45.1"
516+
version = "0.51.0"
517517
source = "registry+https://github.com/rust-lang/crates.io-index"
518-
checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36"
518+
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
519519
dependencies = [
520520
"rustc-std-workspace-alloc",
521521
"rustc-std-workspace-core",

library/std/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ hermit-abi = { version = "0.5.0", features = [
7979
], public = true }
8080

8181
[target.'cfg(all(target_os = "wasi", target_env = "p1"))'.dependencies]
82-
wasi = { version = "0.11.0", features = [
82+
wasip1 = { version = "1.0.0", features = [
8383
'rustc-dep-of-std',
8484
], default-features = false }
8585

8686
[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies]
87-
wasip2 = { version = '0.14.4', features = [
87+
wasip2 = { version = '1.0.2', features = [
8888
'rustc-dep-of-std',
89-
], default-features = false, package = 'wasi' }
89+
], default-features = false }
9090

9191
[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies]
92-
wasip2 = { version = '0.14.4', features = [
92+
wasip2 = { version = '1.0.2', features = [
9393
'rustc-dep-of-std',
94-
], default-features = false, package = 'wasi' }
94+
], default-features = false }
9595

9696
[target.'cfg(target_os = "uefi")'.dependencies]
9797
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }

library/std/src/os/wasi/fs.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,28 @@ impl FileExt for File {
246246

247247
#[cfg(target_env = "p1")]
248248
fn fdstat_set_flags(&self, flags: u16) -> io::Result<()> {
249-
unsafe { wasi::fd_fdstat_set_flags(self.as_raw_fd() as wasi::Fd, flags).map_err(err2io) }
249+
unsafe {
250+
wasip1::fd_fdstat_set_flags(self.as_raw_fd() as wasip1::Fd, flags).map_err(err2io)
251+
}
250252
}
251253

252254
#[cfg(target_env = "p1")]
253255
fn fdstat_set_rights(&self, rights: u64, inheriting: u64) -> io::Result<()> {
254256
unsafe {
255-
wasi::fd_fdstat_set_rights(self.as_raw_fd() as wasi::Fd, rights, inheriting)
257+
wasip1::fd_fdstat_set_rights(self.as_raw_fd() as wasip1::Fd, rights, inheriting)
256258
.map_err(err2io)
257259
}
258260
}
259261

260262
#[cfg(target_env = "p1")]
261263
fn advise(&self, offset: u64, len: u64, advice: u8) -> io::Result<()> {
262264
let advice = match advice {
263-
a if a == wasi::ADVICE_NORMAL.raw() => wasi::ADVICE_NORMAL,
264-
a if a == wasi::ADVICE_SEQUENTIAL.raw() => wasi::ADVICE_SEQUENTIAL,
265-
a if a == wasi::ADVICE_RANDOM.raw() => wasi::ADVICE_RANDOM,
266-
a if a == wasi::ADVICE_WILLNEED.raw() => wasi::ADVICE_WILLNEED,
267-
a if a == wasi::ADVICE_DONTNEED.raw() => wasi::ADVICE_DONTNEED,
268-
a if a == wasi::ADVICE_NOREUSE.raw() => wasi::ADVICE_NOREUSE,
265+
a if a == wasip1::ADVICE_NORMAL.raw() => wasip1::ADVICE_NORMAL,
266+
a if a == wasip1::ADVICE_SEQUENTIAL.raw() => wasip1::ADVICE_SEQUENTIAL,
267+
a if a == wasip1::ADVICE_RANDOM.raw() => wasip1::ADVICE_RANDOM,
268+
a if a == wasip1::ADVICE_WILLNEED.raw() => wasip1::ADVICE_WILLNEED,
269+
a if a == wasip1::ADVICE_DONTNEED.raw() => wasip1::ADVICE_DONTNEED,
270+
a if a == wasip1::ADVICE_NOREUSE.raw() => wasip1::ADVICE_NOREUSE,
269271
_ => {
270272
return Err(io::const_error!(
271273
io::ErrorKind::InvalidInput,
@@ -275,31 +277,35 @@ impl FileExt for File {
275277
};
276278

277279
unsafe {
278-
wasi::fd_advise(self.as_raw_fd() as wasi::Fd, offset, len, advice).map_err(err2io)
280+
wasip1::fd_advise(self.as_raw_fd() as wasip1::Fd, offset, len, advice).map_err(err2io)
279281
}
280282
}
281283

282284
#[cfg(target_env = "p1")]
283285
fn allocate(&self, offset: u64, len: u64) -> io::Result<()> {
284-
unsafe { wasi::fd_allocate(self.as_raw_fd() as wasi::Fd, offset, len).map_err(err2io) }
286+
unsafe { wasip1::fd_allocate(self.as_raw_fd() as wasip1::Fd, offset, len).map_err(err2io) }
285287
}
286288

287289
#[cfg(target_env = "p1")]
288290
fn create_directory<P: AsRef<Path>>(&self, dir: P) -> io::Result<()> {
289291
let path = osstr2str(dir.as_ref().as_ref())?;
290-
unsafe { wasi::path_create_directory(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
292+
unsafe {
293+
wasip1::path_create_directory(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io)
294+
}
291295
}
292296

293297
#[cfg(target_env = "p1")]
294298
fn remove_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
295299
let path = osstr2str(path.as_ref().as_ref())?;
296-
unsafe { wasi::path_unlink_file(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
300+
unsafe { wasip1::path_unlink_file(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io) }
297301
}
298302

299303
#[cfg(target_env = "p1")]
300304
fn remove_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
301305
let path = osstr2str(path.as_ref().as_ref())?;
302-
unsafe { wasi::path_remove_directory(self.as_raw_fd() as wasi::Fd, path).map_err(err2io) }
306+
unsafe {
307+
wasip1::path_remove_directory(self.as_raw_fd() as wasip1::Fd, path).map_err(err2io)
308+
}
303309
}
304310
}
305311

@@ -388,11 +394,11 @@ pub fn link<P: AsRef<Path>, U: AsRef<Path>>(
388394
new_path: U,
389395
) -> io::Result<()> {
390396
unsafe {
391-
wasi::path_link(
392-
old_fd.as_raw_fd() as wasi::Fd,
397+
wasip1::path_link(
398+
old_fd.as_raw_fd() as wasip1::Fd,
393399
old_flags,
394400
osstr2str(old_path.as_ref().as_ref())?,
395-
new_fd.as_raw_fd() as wasi::Fd,
401+
new_fd.as_raw_fd() as wasip1::Fd,
396402
osstr2str(new_path.as_ref().as_ref())?,
397403
)
398404
.map_err(err2io)
@@ -411,10 +417,10 @@ pub fn rename<P: AsRef<Path>, U: AsRef<Path>>(
411417
new_path: U,
412418
) -> io::Result<()> {
413419
unsafe {
414-
wasi::path_rename(
415-
old_fd.as_raw_fd() as wasi::Fd,
420+
wasip1::path_rename(
421+
old_fd.as_raw_fd() as wasip1::Fd,
416422
osstr2str(old_path.as_ref().as_ref())?,
417-
new_fd.as_raw_fd() as wasi::Fd,
423+
new_fd.as_raw_fd() as wasip1::Fd,
418424
osstr2str(new_path.as_ref().as_ref())?,
419425
)
420426
.map_err(err2io)
@@ -432,9 +438,9 @@ pub fn symlink<P: AsRef<Path>, U: AsRef<Path>>(
432438
new_path: U,
433439
) -> io::Result<()> {
434440
unsafe {
435-
wasi::path_symlink(
441+
wasip1::path_symlink(
436442
osstr2str(old_path.as_ref().as_ref())?,
437-
fd.as_raw_fd() as wasi::Fd,
443+
fd.as_raw_fd() as wasip1::Fd,
438444
osstr2str(new_path.as_ref().as_ref())?,
439445
)
440446
.map_err(err2io)

library/std/src/os/wasi/net/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ pub trait TcpListenerExt {
1818

1919
impl TcpListenerExt for net::TcpListener {
2020
fn sock_accept(&self, flags: u16) -> io::Result<u32> {
21-
unsafe { wasi::sock_accept(self.as_raw_fd() as wasi::Fd, flags).map_err(err2io) }
21+
unsafe { wasip1::sock_accept(self.as_raw_fd() as wasip1::Fd, flags).map_err(err2io) }
2222
}
2323
}

library/std/src/sys/args/wasip1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ pub fn args() -> Args {
1111

1212
fn maybe_args() -> Option<Vec<OsString>> {
1313
unsafe {
14-
let (argc, buf_size) = wasi::args_sizes_get().ok()?;
14+
let (argc, buf_size) = wasip1::args_sizes_get().ok()?;
1515
let mut argv = Vec::with_capacity(argc);
1616
let mut buf = Vec::with_capacity(buf_size);
17-
wasi::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?;
17+
wasip1::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?;
1818
argv.set_len(argc);
1919
let mut ret = Vec::with_capacity(argc);
2020
for ptr in argv {

library/std/src/sys/net/connection/wasip1.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ impl TcpStream {
125125

126126
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
127127
let wasi_how = match how {
128-
Shutdown::Read => wasi::SDFLAGS_RD,
129-
Shutdown::Write => wasi::SDFLAGS_WR,
130-
Shutdown::Both => wasi::SDFLAGS_RD | wasi::SDFLAGS_WR,
128+
Shutdown::Read => wasip1::SDFLAGS_RD,
129+
Shutdown::Write => wasip1::SDFLAGS_WR,
130+
Shutdown::Both => wasip1::SDFLAGS_RD | wasip1::SDFLAGS_WR,
131131
};
132132

133-
unsafe { wasi::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
133+
unsafe { wasip1::sock_shutdown(self.socket().as_raw_fd() as _, wasi_how).map_err(err2io) }
134134
}
135135

136136
pub fn duplicate(&self) -> io::Result<TcpStream> {
@@ -167,19 +167,20 @@ impl TcpStream {
167167

168168
pub fn set_nonblocking(&self, state: bool) -> io::Result<()> {
169169
let fdstat = unsafe {
170-
wasi::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasi::Fd).map_err(err2io)?
170+
wasip1::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasip1::Fd)
171+
.map_err(err2io)?
171172
};
172173

173174
let mut flags = fdstat.fs_flags;
174175

175176
if state {
176-
flags |= wasi::FDFLAGS_NONBLOCK;
177+
flags |= wasip1::FDFLAGS_NONBLOCK;
177178
} else {
178-
flags &= !wasi::FDFLAGS_NONBLOCK;
179+
flags &= !wasip1::FDFLAGS_NONBLOCK;
179180
}
180181

181182
unsafe {
182-
wasi::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasi::Fd, flags)
183+
wasip1::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasip1::Fd, flags)
183184
.map_err(err2io)
184185
}
185186
}
@@ -221,7 +222,7 @@ impl TcpListener {
221222

222223
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
223224
let fd = unsafe {
224-
wasi::sock_accept(self.as_inner().as_inner().as_raw_fd() as _, 0).map_err(err2io)?
225+
wasip1::sock_accept(self.as_inner().as_inner().as_raw_fd() as _, 0).map_err(err2io)?
225226
};
226227

227228
Ok((
@@ -258,19 +259,20 @@ impl TcpListener {
258259

259260
pub fn set_nonblocking(&self, state: bool) -> io::Result<()> {
260261
let fdstat = unsafe {
261-
wasi::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasi::Fd).map_err(err2io)?
262+
wasip1::fd_fdstat_get(self.socket().as_inner().as_raw_fd() as wasip1::Fd)
263+
.map_err(err2io)?
262264
};
263265

264266
let mut flags = fdstat.fs_flags;
265267

266268
if state {
267-
flags |= wasi::FDFLAGS_NONBLOCK;
269+
flags |= wasip1::FDFLAGS_NONBLOCK;
268270
} else {
269-
flags &= !wasi::FDFLAGS_NONBLOCK;
271+
flags &= !wasip1::FDFLAGS_NONBLOCK;
270272
}
271273

272274
unsafe {
273-
wasi::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasi::Fd, flags)
275+
wasip1::fd_fdstat_set_flags(self.socket().as_inner().as_raw_fd() as wasip1::Fd, flags)
274276
.map_err(err2io)
275277
}
276278
}

library/std/src/sys/pal/wasi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn abort_internal() -> ! {
2929

3030
#[inline]
3131
#[cfg(target_env = "p1")]
32-
pub(crate) fn err2io(err: wasi::Errno) -> crate::io::Error {
32+
pub(crate) fn err2io(err: wasip1::Errno) -> crate::io::Error {
3333
crate::io::Error::from_raw_os_error(err.raw().into())
3434
}
3535

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub fn fill_bytes(bytes: &mut [u8]) {
22
unsafe {
3-
wasi::random_get(bytes.as_mut_ptr(), bytes.len()).expect("failed to generate random data")
3+
wasip1::random_get(bytes.as_mut_ptr(), bytes.len()).expect("failed to generate random data")
44
}
55
}

src/tools/tidy/src/deps.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
539539
"shlex",
540540
"unwinding",
541541
"vex-sdk",
542-
"wasi",
542+
"wasip1",
543+
"wasip2",
543544
"windows-link",
544545
"windows-sys",
545546
"windows-targets",
@@ -881,10 +882,7 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, check: &mut Runn
881882
continue;
882883
}
883884

884-
// Skip the `wasi` crate here which the standard library explicitly
885-
// depends on two version of (one for the `wasm32-wasip1` target and
886-
// another for the `wasm32-wasip2` target).
887-
if pkg.name.to_string() != "wasi" && !seen_pkgs.insert(&*pkg.name) {
885+
if !seen_pkgs.insert(&*pkg.name) {
888886
check.error(format!(
889887
"duplicate package `{}` is not allowed for the standard library",
890888
pkg.name

0 commit comments

Comments
 (0)