Stream: git-wasmtime

Topic: wasmtime / issue #7127 [wasmtime-wasi] Compiling Runtime ...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 15:25):

blheatwole opened issue #7127:

rustc: 1.70.0 (90c541806 2023-05-31)
Toolchain: stable-x86_64-pc-windows-msvc
Target: x86_64-pc-windows-msvc

I'm getting error when importing wasmtime-wasi and compiling on windows. The code that produces the error is

                  match rustix::net::shutdown(&dropped.inner, rustix::net::Shutdown::ReadWrite) {
                        ---------------------  ^^^^^^^^^^^^^ the trait `AsSocket` is not implemented for `Arc<tokio::net::TcpStream>`
                        |
                        required by a bound introduced by this call

    = note: required for `&Arc<tokio::net::TcpStream>` to implement `AsSocket`
    = note: required for `&Arc<tokio::net::TcpStream>` to implement `AsFd`

The error is a little misleading. The actual signature of shutdown is:

#[inline]
pub fn shutdown<Fd: AsFd>(sockfd: Fd, how: Shutdown) -> io::Result<()> {
    backend::net::syscalls::shutdown(sockfd.as_fd(), how)
}

So what its complaining about is that shutdown expects an object implementing AsFd but while this is implemented for unix, it isn't for windows which implements AsSocket instead:

#[cfg(unix)]
mod sys {
    use super::TcpStream;
    use std::os::unix::prelude::*;

    impl AsRawFd for TcpStream {
        fn as_raw_fd(&self) -> RawFd {
            self.io.as_raw_fd()
        }
    }

    impl AsFd for TcpStream {
        fn as_fd(&self) -> BorrowedFd<'_> {
            unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
        }
    }
}

cfg_windows! {
    use crate::os::windows::io::{AsRawSocket, RawSocket, AsSocket, BorrowedSocket};

    impl AsRawSocket for TcpStream {
        fn as_raw_socket(&self) -> RawSocket {
            self.io.as_raw_socket()
        }
    }

    impl AsSocket for TcpStream {
        fn as_socket(&self) -> BorrowedSocket<'_> {
            unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
        }
    }
}

This is currently blocking me from using the WASI component-model for Window. (I understand it's preview, so I'm not pushing, but this should be addressed).

The specific use-case is a WASI runtime that provide a secondary API for components to read the Windows Event Log. As such, the runtime does really need to run on Windows and I can't just switch it to linux.

Cargo.toml:

[dependencies]
anyhow = "1.0"
wasmtime = { version = "13.0.0", features = [ 'component-model' ]}
wasmtime-wasi = { version = "13.0.0" }

[dependencies.windows]
version = "0.51.1"
features = [
    "Win32_Foundation",
    "Win32_Security",
    "Win32_System_EventLog",
]

I also tried with the current git main branch, but the issue is still there.

I can get wasmtime-wasi to compile for windows with wasmtime-wasi = { version = "13.0.0", default_features = false, features = ['sync'] } but obviously I lose preview-2 and the component model (which is what I'd really like to use).

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 15:34):

blheatwole commented on issue #7127:

As noted on the WinSock docs

In Winsock applications, a socket descriptor is not a file descriptor and must be used with the Winsock functions.

In UNIX, a socket descriptor is represented by a standard file descriptor. As a result, a socket descriptor on UNIX may be passed to any of the standard file I/O functions (read and write, for example).

Thus it likely that two different versions of shutdown will be needed

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 16:21):

alexcrichton commented on issue #7127:

Thanks for the report! This should be fixed in https://github.com/bytecodealliance/wasmtime/pull/7128, but you can also fix this locally by updating to Rust 1.71.0.

In case you didn't already know x86_64-pc-windows-mscv is a tier 1 platform for Wasmtime meaning it's continuously tested on CI and it should always work. This doesn't mean bugs happen, like this one, but Windows should never be significantly behind any other platform for example. A limitation exposed here, that we're not testing older versions of Rust for all platforms, is an unfortunate limitation of CI resources.

Nevertheless bug reports like this are always appreciated, thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 17:15):

blheatwole commented on issue #7127:

rustup upgrade
cargo clean
cargo build

This has resolved the issue.

Thank you

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 17:15):

blheatwole closed issue #7127:

rustc: 1.70.0 (90c541806 2023-05-31)
Toolchain: stable-x86_64-pc-windows-msvc
Target: x86_64-pc-windows-msvc

I'm getting error when importing wasmtime-wasi and compiling on windows. The code that produces the error is

                  match rustix::net::shutdown(&dropped.inner, rustix::net::Shutdown::ReadWrite) {
                        ---------------------  ^^^^^^^^^^^^^ the trait `AsSocket` is not implemented for `Arc<tokio::net::TcpStream>`
                        |
                        required by a bound introduced by this call

    = note: required for `&Arc<tokio::net::TcpStream>` to implement `AsSocket`
    = note: required for `&Arc<tokio::net::TcpStream>` to implement `AsFd`

The error is a little misleading. The actual signature of shutdown is:

#[inline]
pub fn shutdown<Fd: AsFd>(sockfd: Fd, how: Shutdown) -> io::Result<()> {
    backend::net::syscalls::shutdown(sockfd.as_fd(), how)
}

So what its complaining about is that shutdown expects an object implementing AsFd but while this is implemented for unix, it isn't for windows which implements AsSocket instead:

#[cfg(unix)]
mod sys {
    use super::TcpStream;
    use std::os::unix::prelude::*;

    impl AsRawFd for TcpStream {
        fn as_raw_fd(&self) -> RawFd {
            self.io.as_raw_fd()
        }
    }

    impl AsFd for TcpStream {
        fn as_fd(&self) -> BorrowedFd<'_> {
            unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
        }
    }
}

cfg_windows! {
    use crate::os::windows::io::{AsRawSocket, RawSocket, AsSocket, BorrowedSocket};

    impl AsRawSocket for TcpStream {
        fn as_raw_socket(&self) -> RawSocket {
            self.io.as_raw_socket()
        }
    }

    impl AsSocket for TcpStream {
        fn as_socket(&self) -> BorrowedSocket<'_> {
            unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
        }
    }
}

This is currently blocking me from using the WASI component-model for Window. (I understand it's preview, so I'm not pushing, but this should be addressed).

The specific use-case is a WASI runtime that provide a secondary API for components to read the Windows Event Log. As such, the runtime does really need to run on Windows and I can't just switch it to linux.

Cargo.toml:

[dependencies]
anyhow = "1.0"
wasmtime = { version = "13.0.0", features = [ 'component-model' ]}
wasmtime-wasi = { version = "13.0.0" }

[dependencies.windows]
version = "0.51.1"
features = [
    "Win32_Foundation",
    "Win32_Security",
    "Win32_System_EventLog",
]

I also tried with the current git main branch, but the issue is still there.

I can get wasmtime-wasi to compile for windows with wasmtime-wasi = { version = "13.0.0", default_features = false, features = ['sync'] } but obviously I lose preview-2 and the component model (which is what I'd really like to use).


Last updated: Oct 23 2024 at 20:03 UTC