From f1150646311786f514cd51cd9a50bdf286906aa8 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 31 Jan 2024 11:16:42 -0500 Subject: [PATCH 1/2] Add the wasm32-wasi-preview2 target Signed-off-by: Ryan Levick --- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/targets/wasm32_wasi_preview2.rs | 64 +++++++++ library/std/src/os/mod.rs | 3 + library/std/src/os/wasi/mod.rs | 3 +- library/std/src/os/wasi_preview2/mod.rs | 5 + library/std/src/sys/pal/mod.rs | 3 + library/std/src/sys/pal/wasi/helpers.rs | 123 ++++++++++++++++ library/std/src/sys/pal/wasi/mod.rs | 132 ++---------------- library/std/src/sys/pal/wasi_preview2/mod.rs | 78 +++++++++++ library/stdarch | 2 +- src/bootstrap/src/core/build_steps/compile.rs | 7 +- src/bootstrap/src/lib.rs | 2 +- src/doc/book | 2 +- src/doc/edition-guide | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../platform-support/wasm32-wasi-preview2.md | 30 ++++ src/llvm-project | 2 +- src/tools/cargo | 2 +- tests/assembly/targets/targets-elf.rs | 3 + tests/ui/check-cfg/well-known-values.stderr | 2 +- 25 files changed, 339 insertions(+), 136 deletions(-) create mode 100644 compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs create mode 100644 library/std/src/os/wasi_preview2/mod.rs create mode 100644 library/std/src/sys/pal/wasi/helpers.rs create mode 100644 library/std/src/sys/pal/wasi_preview2/mod.rs create mode 100644 src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d472c406c4717..eca80d58c562b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1883,6 +1883,7 @@ symbols! { warn, wasm_abi, wasm_import_module, + wasm_preview2, wasm_target_feature, while_let, windows, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 084a8b9db81e3..bea03068f6da3 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1575,6 +1575,7 @@ supported_targets! { ("wasm32-unknown-emscripten", wasm32_unknown_emscripten), ("wasm32-unknown-unknown", wasm32_unknown_unknown), ("wasm32-wasi", wasm32_wasi), + ("wasm32-wasi-preview2", wasm32_wasi_preview2), ("wasm32-wasi-preview1-threads", wasm32_wasi_preview1_threads), ("wasm64-unknown-unknown", wasm64_unknown_unknown), diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs new file mode 100644 index 0000000000000..fc44e5d4cbce9 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs @@ -0,0 +1,64 @@ +//! The `wasm32-wasi-preview2` target is the next evolution of the +//! wasm32-wasi target. While the wasi specification is still under +//! active development, the {review 2 iteration is considered an "island +//! of stability" that should allow users to rely on it indefinitely. +//! +//! The `wasi` target is a proposal to define a standardized set of WebAssembly +//! component imports that allow it to interoperate with the host system in a +//! standardized way. This set of imports is intended to empower WebAssembly +//! binaries with host capabilities such as filesystem access, network access, etc. +//! +//! Wasi Preview 2 relies on the WebAssembly component model which is an extension of +//! the core WebAssembly specification which allows interoperability between WebAssembly +//! modules (known as "components") through high-level, shared-nothing APIs instead of the +//! low-level, shared-everything linear memory model of the core WebAssembly specification. +//! +//! You can see more about wasi at and the component model at +//! . + +use crate::spec::crt_objects; +use crate::spec::LinkSelfContainedDefault; +use crate::spec::{base, Target}; + +pub fn target() -> Target { + let mut options = base::wasm::options(); + + options.os = "wasi".into(); + options.env = "preview2".into(); + options.linker = Some("wasm-component-ld".into()); + + options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained(); + options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained(); + + // FIXME: Figure out cases in which WASM needs to link with a native toolchain. + options.link_self_contained = LinkSelfContainedDefault::True; + + // Right now this is a bit of a workaround but we're currently saying that + // the target by default has a static crt which we're taking as a signal + // for "use the bundled crt". If that's turned off then the system's crt + // will be used, but this means that default usage of this target doesn't + // need an external compiler but it's still interoperable with an external + // compiler if configured correctly. + options.crt_static_default = true; + options.crt_static_respected = true; + + // Allow `+crt-static` to create a "cdylib" output which is just a wasm file + // without a main function. + options.crt_static_allows_dylibs = true; + + // WASI's `sys::args::init` function ignores its arguments; instead, + // `args::args()` makes the WASI API calls itself. + options.main_needs_argc_argv = false; + + // And, WASI mangles the name of "main" to distinguish between different + // signatures. + options.entry_name = "__main_void".into(); + + Target { + llvm_target: "wasm32-unknown-unknown".into(), + pointer_width: 32, + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm32".into(), + options, + } +} diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 6e11b92b618a3..f03e079030503 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -85,6 +85,9 @@ pub mod linux; #[cfg(any(target_os = "wasi", doc))] pub mod wasi; +#[cfg(any(all(target_os = "wasi", target_env = "preview2"), doc))] +pub mod wasi_preview2; + // windows #[cfg(not(all( doc, diff --git a/library/std/src/os/wasi/mod.rs b/library/std/src/os/wasi/mod.rs index bbaf328f457e4..05c8d30073f42 100644 --- a/library/std/src/os/wasi/mod.rs +++ b/library/std/src/os/wasi/mod.rs @@ -28,7 +28,8 @@ //! [`OsStr`]: crate::ffi::OsStr //! [`OsString`]: crate::ffi::OsString -#![stable(feature = "rust1", since = "1.0.0")] +#![cfg_attr(not(target_env = "preview2"), stable(feature = "rust1", since = "1.0.0"))] +#![cfg_attr(target_env = "preview2", unstable(feature = "wasm_preview2", issue = "none"))] #![deny(unsafe_op_in_unsafe_fn)] #![doc(cfg(target_os = "wasi"))] diff --git a/library/std/src/os/wasi_preview2/mod.rs b/library/std/src/os/wasi_preview2/mod.rs new file mode 100644 index 0000000000000..1d44dd72814b8 --- /dev/null +++ b/library/std/src/os/wasi_preview2/mod.rs @@ -0,0 +1,5 @@ +//! Platform-specific extensions to `std` for Preview 2 of the WebAssembly System Interface (WASI). +//! +//! This module is currently empty, but will be filled over time as wasi-libc support for WASI Preview 2 is stabilized. + +#![stable(feature = "raw_ext", since = "1.1.0")] diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs index 041b7c355822a..f927d88d46c34 100644 --- a/library/std/src/sys/pal/mod.rs +++ b/library/std/src/sys/pal/mod.rs @@ -40,6 +40,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "wasi")] { mod wasi; pub use self::wasi::*; + } else if #[cfg(all(target_os = "wasi", target_env = "preview2"))] { + mod wasi_preview2; + pub use self::wasi_preview2::*; } else if #[cfg(target_family = "wasm")] { mod wasm; pub use self::wasm::*; diff --git a/library/std/src/sys/pal/wasi/helpers.rs b/library/std/src/sys/pal/wasi/helpers.rs new file mode 100644 index 0000000000000..82149cef8fad1 --- /dev/null +++ b/library/std/src/sys/pal/wasi/helpers.rs @@ -0,0 +1,123 @@ +use crate::io as std_io; +use crate::mem; + +#[inline] +pub fn is_interrupted(errno: i32) -> bool { + errno == wasi::ERRNO_INTR.raw().into() +} + +pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { + use std_io::ErrorKind; + + let Ok(errno) = u16::try_from(errno) else { + return ErrorKind::Uncategorized; + }; + + macro_rules! match_errno { + ($($($errno:ident)|+ => $errkind:ident),*, _ => $wildcard:ident $(,)?) => { + match errno { + $(e if $(e == ::wasi::$errno.raw())||+ => ErrorKind::$errkind),*, + _ => ErrorKind::$wildcard, + } + }; + } + + match_errno! { + ERRNO_2BIG => ArgumentListTooLong, + ERRNO_ACCES => PermissionDenied, + ERRNO_ADDRINUSE => AddrInUse, + ERRNO_ADDRNOTAVAIL => AddrNotAvailable, + ERRNO_AFNOSUPPORT => Unsupported, + ERRNO_AGAIN => WouldBlock, + // ALREADY => "connection already in progress", + // BADF => "bad file descriptor", + // BADMSG => "bad message", + ERRNO_BUSY => ResourceBusy, + // CANCELED => "operation canceled", + // CHILD => "no child processes", + ERRNO_CONNABORTED => ConnectionAborted, + ERRNO_CONNREFUSED => ConnectionRefused, + ERRNO_CONNRESET => ConnectionReset, + ERRNO_DEADLK => Deadlock, + // DESTADDRREQ => "destination address required", + ERRNO_DOM => InvalidInput, + // DQUOT => /* reserved */, + ERRNO_EXIST => AlreadyExists, + // FAULT => "bad address", + ERRNO_FBIG => FileTooLarge, + ERRNO_HOSTUNREACH => HostUnreachable, + // IDRM => "identifier removed", + // ILSEQ => "illegal byte sequence", + // INPROGRESS => "operation in progress", + ERRNO_INTR => Interrupted, + ERRNO_INVAL => InvalidInput, + ERRNO_IO => Uncategorized, + // ISCONN => "socket is connected", + ERRNO_ISDIR => IsADirectory, + ERRNO_LOOP => FilesystemLoop, + // MFILE => "file descriptor value too large", + ERRNO_MLINK => TooManyLinks, + // MSGSIZE => "message too large", + // MULTIHOP => /* reserved */, + ERRNO_NAMETOOLONG => InvalidFilename, + ERRNO_NETDOWN => NetworkDown, + // NETRESET => "connection aborted by network", + ERRNO_NETUNREACH => NetworkUnreachable, + // NFILE => "too many files open in system", + // NOBUFS => "no buffer space available", + ERRNO_NODEV => NotFound, + ERRNO_NOENT => NotFound, + // NOEXEC => "executable file format error", + // NOLCK => "no locks available", + // NOLINK => /* reserved */, + ERRNO_NOMEM => OutOfMemory, + // NOMSG => "no message of the desired type", + // NOPROTOOPT => "protocol not available", + ERRNO_NOSPC => StorageFull, + ERRNO_NOSYS => Unsupported, + ERRNO_NOTCONN => NotConnected, + ERRNO_NOTDIR => NotADirectory, + ERRNO_NOTEMPTY => DirectoryNotEmpty, + // NOTRECOVERABLE => "state not recoverable", + // NOTSOCK => "not a socket", + ERRNO_NOTSUP => Unsupported, + // NOTTY => "inappropriate I/O control operation", + ERRNO_NXIO => NotFound, + // OVERFLOW => "value too large to be stored in data type", + // OWNERDEAD => "previous owner died", + ERRNO_PERM => PermissionDenied, + ERRNO_PIPE => BrokenPipe, + // PROTO => "protocol error", + ERRNO_PROTONOSUPPORT => Unsupported, + // PROTOTYPE => "protocol wrong type for socket", + // RANGE => "result too large", + ERRNO_ROFS => ReadOnlyFilesystem, + ERRNO_SPIPE => NotSeekable, + ERRNO_SRCH => NotFound, + // STALE => /* reserved */, + ERRNO_TIMEDOUT => TimedOut, + ERRNO_TXTBSY => ResourceBusy, + ERRNO_XDEV => CrossesDevices, + ERRNO_NOTCAPABLE => PermissionDenied, + _ => Uncategorized, + } +} + +pub fn abort_internal() -> ! { + unsafe { libc::abort() } +} + +pub fn hashmap_random_keys() -> (u64, u64) { + let mut ret = (0u64, 0u64); + unsafe { + let base = &mut ret as *mut (u64, u64) as *mut u8; + let len = mem::size_of_val(&ret); + wasi::random_get(base, len).expect("random_get failure"); + } + return ret; +} + +#[inline] +pub(crate) fn err2io(err: wasi::Errno) -> std_io::Error { + std_io::Error::from_raw_os_error(err.raw().into()) +} diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs index e6cbd51e768a7..308dd29600488 100644 --- a/library/std/src/sys/pal/wasi/mod.rs +++ b/library/std/src/sys/pal/wasi/mod.rs @@ -14,9 +14,6 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use crate::io as std_io; -use crate::mem; - #[path = "../unix/alloc.rs"] pub mod alloc; pub mod args; @@ -57,123 +54,12 @@ cfg_if::cfg_if! { mod common; pub use common::*; -#[inline] -pub fn is_interrupted(errno: i32) -> bool { - errno == wasi::ERRNO_INTR.raw().into() -} - -pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { - use std_io::ErrorKind; - - let Ok(errno) = u16::try_from(errno) else { - return ErrorKind::Uncategorized; - }; - - macro_rules! match_errno { - ($($($errno:ident)|+ => $errkind:ident),*, _ => $wildcard:ident $(,)?) => { - match errno { - $(e if $(e == ::wasi::$errno.raw())||+ => ErrorKind::$errkind),*, - _ => ErrorKind::$wildcard, - } - }; - } - - match_errno! { - ERRNO_2BIG => ArgumentListTooLong, - ERRNO_ACCES => PermissionDenied, - ERRNO_ADDRINUSE => AddrInUse, - ERRNO_ADDRNOTAVAIL => AddrNotAvailable, - ERRNO_AFNOSUPPORT => Unsupported, - ERRNO_AGAIN => WouldBlock, - // ALREADY => "connection already in progress", - // BADF => "bad file descriptor", - // BADMSG => "bad message", - ERRNO_BUSY => ResourceBusy, - // CANCELED => "operation canceled", - // CHILD => "no child processes", - ERRNO_CONNABORTED => ConnectionAborted, - ERRNO_CONNREFUSED => ConnectionRefused, - ERRNO_CONNRESET => ConnectionReset, - ERRNO_DEADLK => Deadlock, - // DESTADDRREQ => "destination address required", - ERRNO_DOM => InvalidInput, - // DQUOT => /* reserved */, - ERRNO_EXIST => AlreadyExists, - // FAULT => "bad address", - ERRNO_FBIG => FileTooLarge, - ERRNO_HOSTUNREACH => HostUnreachable, - // IDRM => "identifier removed", - // ILSEQ => "illegal byte sequence", - // INPROGRESS => "operation in progress", - ERRNO_INTR => Interrupted, - ERRNO_INVAL => InvalidInput, - ERRNO_IO => Uncategorized, - // ISCONN => "socket is connected", - ERRNO_ISDIR => IsADirectory, - ERRNO_LOOP => FilesystemLoop, - // MFILE => "file descriptor value too large", - ERRNO_MLINK => TooManyLinks, - // MSGSIZE => "message too large", - // MULTIHOP => /* reserved */, - ERRNO_NAMETOOLONG => InvalidFilename, - ERRNO_NETDOWN => NetworkDown, - // NETRESET => "connection aborted by network", - ERRNO_NETUNREACH => NetworkUnreachable, - // NFILE => "too many files open in system", - // NOBUFS => "no buffer space available", - ERRNO_NODEV => NotFound, - ERRNO_NOENT => NotFound, - // NOEXEC => "executable file format error", - // NOLCK => "no locks available", - // NOLINK => /* reserved */, - ERRNO_NOMEM => OutOfMemory, - // NOMSG => "no message of the desired type", - // NOPROTOOPT => "protocol not available", - ERRNO_NOSPC => StorageFull, - ERRNO_NOSYS => Unsupported, - ERRNO_NOTCONN => NotConnected, - ERRNO_NOTDIR => NotADirectory, - ERRNO_NOTEMPTY => DirectoryNotEmpty, - // NOTRECOVERABLE => "state not recoverable", - // NOTSOCK => "not a socket", - ERRNO_NOTSUP => Unsupported, - // NOTTY => "inappropriate I/O control operation", - ERRNO_NXIO => NotFound, - // OVERFLOW => "value too large to be stored in data type", - // OWNERDEAD => "previous owner died", - ERRNO_PERM => PermissionDenied, - ERRNO_PIPE => BrokenPipe, - // PROTO => "protocol error", - ERRNO_PROTONOSUPPORT => Unsupported, - // PROTOTYPE => "protocol wrong type for socket", - // RANGE => "result too large", - ERRNO_ROFS => ReadOnlyFilesystem, - ERRNO_SPIPE => NotSeekable, - ERRNO_SRCH => NotFound, - // STALE => /* reserved */, - ERRNO_TIMEDOUT => TimedOut, - ERRNO_TXTBSY => ResourceBusy, - ERRNO_XDEV => CrossesDevices, - ERRNO_NOTCAPABLE => PermissionDenied, - _ => Uncategorized, - } -} - -pub fn abort_internal() -> ! { - unsafe { libc::abort() } -} - -pub fn hashmap_random_keys() -> (u64, u64) { - let mut ret = (0u64, 0u64); - unsafe { - let base = core::ptr::addr_of_mut!(ret) as *mut u8; - let len = mem::size_of_val(&ret); - wasi::random_get(base, len).expect("random_get failure"); - } - return ret; -} - -#[inline] -fn err2io(err: wasi::Errno) -> std_io::Error { - std_io::Error::from_raw_os_error(err.raw().into()) -} +mod helpers; +// These exports are listed individually to work around Rust's glob import +// conflict rules. If we glob export `helpers` and `common` together, then +// the compiler complains about conflicts. +pub use helpers::abort_internal; +pub use helpers::decode_error_kind; +use helpers::err2io; +pub use helpers::hashmap_random_keys; +pub use helpers::is_interrupted; diff --git a/library/std/src/sys/pal/wasi_preview2/mod.rs b/library/std/src/sys/pal/wasi_preview2/mod.rs new file mode 100644 index 0000000000000..b61695015bbd9 --- /dev/null +++ b/library/std/src/sys/pal/wasi_preview2/mod.rs @@ -0,0 +1,78 @@ +//! System bindings for the wasi preview 2 target. +//! +//! This is the next evolution of the original wasi target, and is intended to +//! replace that target over time. +//! +//! To begin with, this target mirrors the wasi target 1 to 1, but over +//! time this will change significantly. + +#[path = "../unix/alloc.rs"] +pub mod alloc; +#[path = "../wasi/args.rs"] +pub mod args; +#[path = "../unix/cmath.rs"] +pub mod cmath; +#[path = "../wasi/env.rs"] +pub mod env; +#[path = "../wasi/fd.rs"] +pub mod fd; +#[path = "../wasi/fs.rs"] +pub mod fs; +#[allow(unused)] +#[path = "../wasm/atomics/futex.rs"] +pub mod futex; +#[path = "../wasi/io.rs"] +pub mod io; + +#[path = "../wasi/net.rs"] +pub mod net; +#[path = "../wasi/os.rs"] +pub mod os; +#[path = "../unix/os_str.rs"] +pub mod os_str; +#[path = "../unix/path.rs"] +pub mod path; +#[path = "../unsupported/pipe.rs"] +pub mod pipe; +#[path = "../unsupported/process.rs"] +pub mod process; +#[path = "../wasi/stdio.rs"] +pub mod stdio; +#[path = "../wasi/thread.rs"] +pub mod thread; +#[path = "../unsupported/thread_local_dtor.rs"] +pub mod thread_local_dtor; +#[path = "../unsupported/thread_local_key.rs"] +pub mod thread_local_key; +#[path = "../wasi/time.rs"] +pub mod time; + +cfg_if::cfg_if! { + if #[cfg(target_feature = "atomics")] { + compile_error!("The wasm32-wasi-preview2 target does not support atomics"); + } else { + #[path = "../unsupported/locks/mod.rs"] + pub mod locks; + #[path = "../unsupported/once.rs"] + pub mod once; + #[path = "../unsupported/thread_parking.rs"] + pub mod thread_parking; + } +} + +#[path = "../unsupported/common.rs"] +#[deny(unsafe_op_in_unsafe_fn)] +#[allow(unused)] +mod common; +pub use common::*; + +#[path = "../wasi/helpers.rs"] +mod helpers; +// These exports are listed individually to work around Rust's glob import +// conflict rules. If we glob export `helpers` and `common` together, then +// the compiler complains about conflicts. +pub use helpers::abort_internal; +pub use helpers::decode_error_kind; +use helpers::err2io; +pub use helpers::hashmap_random_keys; +pub use helpers::is_interrupted; diff --git a/library/stdarch b/library/stdarch index 56087ea170d87..f4528dd6e85d9 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 56087ea170d878a7a57b3a5725e0c00f5f5cad70 +Subproject commit f4528dd6e85d97bb802240d7cd048b6e1bf72540 diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 938813044217b..9860d56ff6ece 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -398,10 +398,13 @@ fn copy_self_contained_objects( let srcdir = builder .wasi_root(target) .unwrap_or_else(|| { - panic!("Target {:?} does not have a \"wasi-root\" key", target.triple) + panic!( + "Target {:?} does not have a \"wasi-root\" key in Config.toml", + target.triple + ) }) .join("lib") - .join(target.to_string().replace("-preview1", "")); + .join(target.to_string().replace("-preview1", "").replace("-preview2", "")); for &obj in &["libc.a", "crt1-command.o", "crt1-reactor.o"] { copy_and_stamp( builder, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 965d788bb8371..620bd8770d878 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -89,7 +89,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ (Some(Mode::Std), "netbsd10", None), (Some(Mode::Std), "backtrace_in_libstd", None), /* Extra values not defined in the built-in targets yet, but used in std */ - (Some(Mode::Std), "target_env", Some(&["libnx"])), + (Some(Mode::Std), "target_env", Some(&["libnx", "preview2"])), // (Some(Mode::Std), "target_os", Some(&[])), (Some(Mode::Std), "target_arch", Some(&["spirv", "nvptx", "xtensa"])), /* Extra names used by dependencies */ diff --git a/src/doc/book b/src/doc/book index 19c40bfd2d576..71352deb20727 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 19c40bfd2d57641d962f3119a1c343355f1b3c5e +Subproject commit 71352deb20727b4dda9ebfe8182709d5bf17dfea diff --git a/src/doc/edition-guide b/src/doc/edition-guide index e1eead1181a69..baafacc6d8701 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit e1eead1181a691e56299294d5f1d62fe7a26d317 +Subproject commit baafacc6d8701269dab1e1e333f3547fb54b5a59 diff --git a/src/doc/reference b/src/doc/reference index 3417f866932cb..a0b119535e774 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 3417f866932cb1c09c6be0f31d2a02ee01b4b95d +Subproject commit a0b119535e7740f68494c4f0582f7ad008b00ccd diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 57f1e708f5d58..179256a445d61 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 57f1e708f5d5850562bc385aaf610e6af14d6ec8 +Subproject commit 179256a445d6144f5f371fdefb993f48f33978b0 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index 7b0ef5b0bea5e..ec287e3327776 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit 7b0ef5b0bea5e3ce3b9764aa5754a60e2cc05c52 +Subproject commit ec287e332777627185be4798ad22599ffe7b84aa diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 1f9307203bc3c..3f65da65f7ad9 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -60,6 +60,7 @@ - [*-unknown-openbsd](platform-support/openbsd.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) - [wasm32-wasi-preview1-threads](platform-support/wasm32-wasi-preview1-threads.md) + - [wasm32-wasi-preview2](platform-support/wasm32-wasi-preview2.md) - [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 80d9dc85f162a..c55ba242a37d2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -361,6 +361,7 @@ target | std | host | notes `thumbv7a-pc-windows-msvc` | ? | | `thumbv7a-uwp-windows-msvc` | ✓ | | `thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL +[`wasm32-wasi-preview2`](platform-support/wasm32-wasi-preview2.md) | ✓ | | WebAssembly [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly `x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS diff --git a/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md b/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md new file mode 100644 index 0000000000000..837efd13d417e --- /dev/null +++ b/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md @@ -0,0 +1,30 @@ +# `wasm32-wasi-preview2` + +**Tier: 3** + +The `wasm32-wasi-preview2` target is a new and still (as of January 2024) an +experimental target. This target is an extension to `wasm32-wasi-preview1` target, +originally known as `wasm32-wasi`. It is the next evolution in the development of +wasi (the [WebAssembly System Interface](https://wasi.dev)) that uses the WebAssembly +[component model] to allow for a standardized set of syscalls that are intended to empower +WebAssembly binaries with native host capabilities. + +[component model]: https://github.com/WebAssembly/component-model + +## Target maintainers + +- Alex Crichton, https://github.com/alexcrichton +- Ryan Levick, https://github.com/rylev + +## Requirements + +This target is cross-compiled. The target supports `std` fully. + +## Platform requirements + +The WebAssembly runtime should support the wasi preview 2 API set. + +This target is not a stable target. This means that there are only a few engines +which implement wasi preview 2, for example: + +* Wasmtime - `-W component-model` diff --git a/src/llvm-project b/src/llvm-project index 9ea7f739f257b..700fbf978e6c5 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 9ea7f739f257b049a65deeb1f2455bb2ea021cfa +Subproject commit 700fbf978e6c5bb297d12963206f7487722de480 diff --git a/src/tools/cargo b/src/tools/cargo index 194a60b2952bd..7bb7b539558dc 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 194a60b2952bd5d12ba15dd2577a97eed7d3c587 +Subproject commit 7bb7b539558dc88bea44cee4168b6269bf8177b0 diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 0d8f1bc60252a..e74d0b6d654fc 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -489,6 +489,9 @@ //@ revisions: wasm32_wasi_preview1_threads //@ [wasm32_wasi_preview1_threads] compile-flags: --target wasm32-wasi-preview1-threads //@ [wasm32_wasi_preview1_threads] needs-llvm-components: webassembly +//@ revisions: wasm32_wasip1 +//@ [wasm32_wasip2] compile-flags: --target wasm32-wasip2 +//@ [wasm32_wasip2] needs-llvm-components: webassembly //@ revisions: wasm64_unknown_unknown //@ [wasm64_unknown_unknown] compile-flags: --target wasm64-unknown-unknown //@ [wasm64_unknown_unknown] needs-llvm-components: webassembly diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 5f52421fef5b2..5dda4931d543a 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -136,7 +136,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_env = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `psx`, `relibc`, `sgx`, `uclibc` + = note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, `uclibc` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From 5e9bed7b1e1524936001b37b6ecbf406179d8ebe Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 21 Feb 2024 09:23:28 -0500 Subject: [PATCH 2/2] Rename wasm32-wasi-preview2 to wasm32-wasip2 Signed-off-by: Ryan Levick --- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 2 +- .../targets/{wasm32_wasi_preview2.rs => wasm32_wasip2.rs} | 4 ++-- library/std/src/os/mod.rs | 4 ++-- library/std/src/os/wasi/mod.rs | 4 ++-- library/std/src/os/{wasi_preview2 => wasip2}/mod.rs | 0 library/std/src/sys/pal/mod.rs | 6 +++--- library/std/src/sys/pal/{wasi_preview2 => wasip2}/mod.rs | 2 +- library/stdarch | 2 +- src/bootstrap/src/core/build_steps/compile.rs | 2 +- src/bootstrap/src/lib.rs | 2 +- src/doc/book | 2 +- src/doc/edition-guide | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- src/doc/rustc/src/SUMMARY.md | 2 +- src/doc/rustc/src/platform-support.md | 2 +- .../{wasm32-wasi-preview2.md => wasm32-wasip2.md} | 6 +++--- src/llvm-project | 2 +- src/tools/cargo | 2 +- tests/assembly/targets/targets-elf.rs | 2 +- 22 files changed, 28 insertions(+), 28 deletions(-) rename compiler/rustc_target/src/spec/targets/{wasm32_wasi_preview2.rs => wasm32_wasip2.rs} (96%) rename library/std/src/os/{wasi_preview2 => wasip2}/mod.rs (100%) rename library/std/src/sys/pal/{wasi_preview2 => wasip2}/mod.rs (95%) rename src/doc/rustc/src/platform-support/{wasm32-wasi-preview2.md => wasm32-wasip2.md} (88%) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index eca80d58c562b..5f9373dd81a58 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1881,9 +1881,9 @@ symbols! { vtable_align, vtable_size, warn, + wasip2, wasm_abi, wasm_import_module, - wasm_preview2, wasm_target_feature, while_let, windows, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index bea03068f6da3..651d563227750 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1575,7 +1575,7 @@ supported_targets! { ("wasm32-unknown-emscripten", wasm32_unknown_emscripten), ("wasm32-unknown-unknown", wasm32_unknown_unknown), ("wasm32-wasi", wasm32_wasi), - ("wasm32-wasi-preview2", wasm32_wasi_preview2), + ("wasm32-wasip2", wasm32_wasip2), ("wasm32-wasi-preview1-threads", wasm32_wasi_preview1_threads), ("wasm64-unknown-unknown", wasm64_unknown_unknown), diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs similarity index 96% rename from compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs rename to compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs index fc44e5d4cbce9..30f7636f0bbe5 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasi_preview2.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs @@ -1,4 +1,4 @@ -//! The `wasm32-wasi-preview2` target is the next evolution of the +//! The `wasm32-wasip2` target is the next evolution of the //! wasm32-wasi target. While the wasi specification is still under //! active development, the {review 2 iteration is considered an "island //! of stability" that should allow users to rely on it indefinitely. @@ -24,7 +24,7 @@ pub fn target() -> Target { let mut options = base::wasm::options(); options.os = "wasi".into(); - options.env = "preview2".into(); + options.env = "p2".into(); options.linker = Some("wasm-component-ld".into()); options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained(); diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index f03e079030503..bebf3a797d813 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -85,8 +85,8 @@ pub mod linux; #[cfg(any(target_os = "wasi", doc))] pub mod wasi; -#[cfg(any(all(target_os = "wasi", target_env = "preview2"), doc))] -pub mod wasi_preview2; +#[cfg(any(all(target_os = "wasi", target_env = "p2"), doc))] +pub mod wasip2; // windows #[cfg(not(all( diff --git a/library/std/src/os/wasi/mod.rs b/library/std/src/os/wasi/mod.rs index 05c8d30073f42..e36b93e60ea1c 100644 --- a/library/std/src/os/wasi/mod.rs +++ b/library/std/src/os/wasi/mod.rs @@ -28,8 +28,8 @@ //! [`OsStr`]: crate::ffi::OsStr //! [`OsString`]: crate::ffi::OsString -#![cfg_attr(not(target_env = "preview2"), stable(feature = "rust1", since = "1.0.0"))] -#![cfg_attr(target_env = "preview2", unstable(feature = "wasm_preview2", issue = "none"))] +#![cfg_attr(not(target_env = "p2"), stable(feature = "rust1", since = "1.0.0"))] +#![cfg_attr(target_env = "p2", unstable(feature = "wasip2", issue = "none"))] #![deny(unsafe_op_in_unsafe_fn)] #![doc(cfg(target_os = "wasi"))] diff --git a/library/std/src/os/wasi_preview2/mod.rs b/library/std/src/os/wasip2/mod.rs similarity index 100% rename from library/std/src/os/wasi_preview2/mod.rs rename to library/std/src/os/wasip2/mod.rs diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs index f927d88d46c34..7c87deed3715a 100644 --- a/library/std/src/sys/pal/mod.rs +++ b/library/std/src/sys/pal/mod.rs @@ -40,9 +40,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "wasi")] { mod wasi; pub use self::wasi::*; - } else if #[cfg(all(target_os = "wasi", target_env = "preview2"))] { - mod wasi_preview2; - pub use self::wasi_preview2::*; + } else if #[cfg(all(target_os = "wasi", target_env = "p2"))] { + mod wasip2; + pub use self::wasip2::*; } else if #[cfg(target_family = "wasm")] { mod wasm; pub use self::wasm::*; diff --git a/library/std/src/sys/pal/wasi_preview2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs similarity index 95% rename from library/std/src/sys/pal/wasi_preview2/mod.rs rename to library/std/src/sys/pal/wasip2/mod.rs index b61695015bbd9..b12a8d5ea11c7 100644 --- a/library/std/src/sys/pal/wasi_preview2/mod.rs +++ b/library/std/src/sys/pal/wasip2/mod.rs @@ -49,7 +49,7 @@ pub mod time; cfg_if::cfg_if! { if #[cfg(target_feature = "atomics")] { - compile_error!("The wasm32-wasi-preview2 target does not support atomics"); + compile_error!("The wasm32-wasip2 target does not support atomics"); } else { #[path = "../unsupported/locks/mod.rs"] pub mod locks; diff --git a/library/stdarch b/library/stdarch index f4528dd6e85d9..56087ea170d87 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit f4528dd6e85d97bb802240d7cd048b6e1bf72540 +Subproject commit 56087ea170d878a7a57b3a5725e0c00f5f5cad70 diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 9860d56ff6ece..43ac71b112c0b 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -404,7 +404,7 @@ fn copy_self_contained_objects( ) }) .join("lib") - .join(target.to_string().replace("-preview1", "").replace("-preview2", "")); + .join(target.to_string().replace("-preview1", "").replace("p2", "")); for &obj in &["libc.a", "crt1-command.o", "crt1-reactor.o"] { copy_and_stamp( builder, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 620bd8770d878..f7748621d93ba 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -89,7 +89,7 @@ const EXTRA_CHECK_CFGS: &[(Option, &str, Option<&[&'static str]>)] = &[ (Some(Mode::Std), "netbsd10", None), (Some(Mode::Std), "backtrace_in_libstd", None), /* Extra values not defined in the built-in targets yet, but used in std */ - (Some(Mode::Std), "target_env", Some(&["libnx", "preview2"])), + (Some(Mode::Std), "target_env", Some(&["libnx", "p2"])), // (Some(Mode::Std), "target_os", Some(&[])), (Some(Mode::Std), "target_arch", Some(&["spirv", "nvptx", "xtensa"])), /* Extra names used by dependencies */ diff --git a/src/doc/book b/src/doc/book index 71352deb20727..19c40bfd2d576 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 71352deb20727b4dda9ebfe8182709d5bf17dfea +Subproject commit 19c40bfd2d57641d962f3119a1c343355f1b3c5e diff --git a/src/doc/edition-guide b/src/doc/edition-guide index baafacc6d8701..e1eead1181a69 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit baafacc6d8701269dab1e1e333f3547fb54b5a59 +Subproject commit e1eead1181a691e56299294d5f1d62fe7a26d317 diff --git a/src/doc/reference b/src/doc/reference index a0b119535e774..3417f866932cb 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit a0b119535e7740f68494c4f0582f7ad008b00ccd +Subproject commit 3417f866932cb1c09c6be0f31d2a02ee01b4b95d diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 179256a445d61..57f1e708f5d58 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 179256a445d6144f5f371fdefb993f48f33978b0 +Subproject commit 57f1e708f5d5850562bc385aaf610e6af14d6ec8 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index ec287e3327776..7b0ef5b0bea5e 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit ec287e332777627185be4798ad22599ffe7b84aa +Subproject commit 7b0ef5b0bea5e3ce3b9764aa5754a60e2cc05c52 diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 3f65da65f7ad9..d4ca91977a636 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -60,7 +60,7 @@ - [*-unknown-openbsd](platform-support/openbsd.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) - [wasm32-wasi-preview1-threads](platform-support/wasm32-wasi-preview1-threads.md) - - [wasm32-wasi-preview2](platform-support/wasm32-wasi-preview2.md) + - [wasm32-wasip2](platform-support/wasm32-wasip2.md) - [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index c55ba242a37d2..984cb13f790ca 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -361,7 +361,7 @@ target | std | host | notes `thumbv7a-pc-windows-msvc` | ? | | `thumbv7a-uwp-windows-msvc` | ✓ | | `thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL -[`wasm32-wasi-preview2`](platform-support/wasm32-wasi-preview2.md) | ✓ | | WebAssembly +[`wasm32-wasip2`](platform-support/wasm32-wasip2.md) | ✓ | | WebAssembly [`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly `x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS diff --git a/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md b/src/doc/rustc/src/platform-support/wasm32-wasip2.md similarity index 88% rename from src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md rename to src/doc/rustc/src/platform-support/wasm32-wasip2.md index 837efd13d417e..4466d2c084053 100644 --- a/src/doc/rustc/src/platform-support/wasm32-wasi-preview2.md +++ b/src/doc/rustc/src/platform-support/wasm32-wasip2.md @@ -1,9 +1,9 @@ -# `wasm32-wasi-preview2` +# `wasm32-wasip2` **Tier: 3** -The `wasm32-wasi-preview2` target is a new and still (as of January 2024) an -experimental target. This target is an extension to `wasm32-wasi-preview1` target, +The `wasm32-wasip2` target is a new and still (as of January 2024) an +experimental target. This target is an extension to `wasm32-wasip1` target, originally known as `wasm32-wasi`. It is the next evolution in the development of wasi (the [WebAssembly System Interface](https://wasi.dev)) that uses the WebAssembly [component model] to allow for a standardized set of syscalls that are intended to empower diff --git a/src/llvm-project b/src/llvm-project index 700fbf978e6c5..9ea7f739f257b 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 700fbf978e6c5bb297d12963206f7487722de480 +Subproject commit 9ea7f739f257b049a65deeb1f2455bb2ea021cfa diff --git a/src/tools/cargo b/src/tools/cargo index 7bb7b539558dc..194a60b2952bd 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 7bb7b539558dc88bea44cee4168b6269bf8177b0 +Subproject commit 194a60b2952bd5d12ba15dd2577a97eed7d3c587 diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index e74d0b6d654fc..a741f5deb6e8c 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -489,7 +489,7 @@ //@ revisions: wasm32_wasi_preview1_threads //@ [wasm32_wasi_preview1_threads] compile-flags: --target wasm32-wasi-preview1-threads //@ [wasm32_wasi_preview1_threads] needs-llvm-components: webassembly -//@ revisions: wasm32_wasip1 +//@ revisions: wasm32_wasip2 //@ [wasm32_wasip2] compile-flags: --target wasm32-wasip2 //@ [wasm32_wasip2] needs-llvm-components: webassembly //@ revisions: wasm64_unknown_unknown