Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make compile pass on windows #238

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions .github/workflows/ci.sh
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
#!/usr/bin/env sh

set -ex
if [ "${NO_RUN}" != "1" ] && [ "${NO_RUN}" != "true" ]; then

CARGO=cargo
if [ "${CROSS}" = "1" ]; then
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10
set -ex

cargo install cross
CARGO=cross
fi
CARGO=cargo
if [ "${CROSS}" = "1" ]; then
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10

# If a test crashes, we want to know which one it was.
export RUST_TEST_THREADS=1
export RUST_BACKTRACE=1
cargo install cross
CARGO=cross
fi

# test monoio mod
cd "${PROJECT_DIR}"/monoio
# If a test crashes, we want to know which one it was.
export RUST_TEST_THREADS=1
export RUST_BACKTRACE=1

# only enable legacy driver
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils" --release
# test monoio mod
cd "${PROJECT_DIR}"/monoio

if [ "${TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${TARGET}" = "i686-unknown-linux-gnu" ]; then
# only enable legacy driver
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils" --release

# only enabled uring driver
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,iouring,macros,utils"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,iouring,macros,utils" --release
if [ "${TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${TARGET}" = "i686-unknown-linux-gnu" ]; then
# only enabled uring driver
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,iouring,macros,utils"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,iouring,macros,utils" --release
fi

# enable uring+legacy driver
"${CARGO}" test --target "${TARGET}"
"${CARGO}" test --target "${TARGET}" --release
if [ "${TARGET}" != "aarch64-unknown-linux-gnu" ] && [ "${TARGET}" != "armv7-unknown-linux-gnueabihf" ] &&
[ "${TARGET}" != "riscv64gc-unknown-linux-gnu" ] && [ "${TARGET}" != "s390x-unknown-linux-gnu" ]; then
# enable uring+legacy driver
"${CARGO}" test --target "${TARGET}"
"${CARGO}" test --target "${TARGET}" --release
fi

if [ "${CHANNEL}" == "nightly" ]; then
if [ "${CHANNEL}" == "nightly" ] && ( [ "${TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${TARGET}" = "i686-unknown-linux-gnu" ] ); then
"${CARGO}" test --target "${TARGET}" --all-features
"${CARGO}" test --target "${TARGET}" --all-features --release
fi

fi
# test monoio-compat mod
cd "${PROJECT_DIR}"/monoio-compat

# test monoio-compat mod
cd "${PROJECT_DIR}"/monoio-compat
"${CARGO}" test --target "${TARGET}"
"${CARGO}" test --target "${TARGET}" --release

"${CARGO}" test --target "${TARGET}"
"${CARGO}" test --target "${TARGET}" --release
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper --release

"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper --release
if [ "${CHANNEL}" == "nightly" ]; then
"${CARGO}" test --target "${TARGET}" --all-features
"${CARGO}" test --target "${TARGET}" --all-features --release
fi

if [ "${CHANNEL}" == "nightly" ]; then
"${CARGO}" test --target "${TARGET}" --all-features
"${CARGO}" test --target "${TARGET}" --all-features --release
# todo maybe we should test examples here ?
fi

# todo maybe we should test examples here ?
31 changes: 17 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
TARGET: ${{ matrix.target }}
OS: ${{ matrix.os }}
PROJECT_DIR: ${{ github.workspace }}
NO_RUN: ${{ matrix.no_run }}
run: sh .github/workflows/ci.sh

strategy:
Expand All @@ -69,11 +70,10 @@ jobs:
x86_64-apple-darwin,
aarch64-apple-darwin,

# unsupported yet
# x86_64-pc-windows-gnu,
# x86_64-pc-windows-msvc,
# i686-pc-windows-gnu,
# i686-pc-windows-msvc,
x86_64-pc-windows-gnu,
x86_64-pc-windows-msvc,
i686-pc-windows-gnu,
i686-pc-windows-msvc,
]
channel: [stable, nightly]
include:
Expand All @@ -99,12 +99,15 @@ jobs:
- target: aarch64-apple-darwin
os: macos-14

# unsupported yet
# - target: x86_64-pc-windows-msvc
# os: windows-latest
# - target: x86_64-pc-windows-gnu
# os: windows-latest
# - target: i686-pc-windows-msvc
# os: windows-latest
# - target: i686-pc-windows-gnu
# os: windows-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
no_run: 1
- target: x86_64-pc-windows-gnu
os: windows-latest
no_run: 1
- target: i686-pc-windows-msvc
os: windows-latest
no_run: 1
- target: i686-pc-windows-gnu
os: windows-latest
no_run: 1
1 change: 1 addition & 0 deletions monoio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ fn token_stream_with_error(mut tokens: TokenStream, error: syn::Error) -> TokenS
tokens
}

#[cfg(unix)]
pub(crate) fn main(args: TokenStream, item: TokenStream) -> TokenStream {
// If any of the steps for this macro fail, we still want to expand to an item that is as close
// to the expected output as possible. This helps out IDEs such that completions and other
Expand Down
19 changes: 12 additions & 7 deletions monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ memchr = "2.7"
bytes = { version = "1", optional = true }
flume = { version = "0.11", optional = true }
mio = { version = "0.8", features = [
"net",
"os-poll",
"os-ext",
"net",
"os-poll",
"os-ext",
], optional = true }
threadpool = { version = "1", optional = true }
tokio = { version = "1", default-features = false, optional = true }
tracing = { version = "0.1", default-features = false, features = [
"std",
"std",
], optional = true }
ctrlc = { version = "3", optional = true }
lazy_static = { version = "1", optional = true }
once_cell = { version = "1.19.0", optional = true }

# windows dependencies(will be added when windows support finished)
[target.'cfg(windows)'.dependencies.windows-sys]
features = ["Win32_Foundation", "Win32_Networking_WinSock"]
version = "0.48.0"
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.48.0", features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_Storage_FileSystem",
"Win32_Security"
] }

# unix dependencies
[target.'cfg(unix)'.dependencies]
Expand Down
20 changes: 12 additions & 8 deletions monoio/src/buf/io_vec_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ pub unsafe trait IoVecBuf: Unpin + 'static {
#[cfg(unix)]
fn read_iovec_ptr(&self) -> *const libc::iovec;

#[cfg(unix)]
/// Returns the count of iovec struct behind the pointer.
///
/// # Safety
/// There must be really that number of iovec here.
#[cfg(unix)]
fn read_iovec_len(&self) -> usize;

/// Returns a raw pointer to WSABUF struct.
#[cfg(windows)]
fn read_wsabuf_ptr(&self) -> *const WSABUF;

/// Returns the count of WSABUF struct behind the pointer.
#[cfg(windows)]
fn read_wsabuf_len(&self) -> usize;
}
Expand Down Expand Up @@ -110,7 +112,7 @@ impl From<Vec<Vec<u8>>> for VecBuf {
.iter()
.map(|v| WSABUF {
buf: v.as_ptr() as _,
len: v.len(),
len: v.len() as _,
})
.collect();
Self { wsabufs, raw: vs }
Expand Down Expand Up @@ -187,7 +189,6 @@ impl From<VecBuf> for Vec<Vec<u8>> {
/// See the safety note of the methods.
#[allow(clippy::unnecessary_safety_doc)]
pub unsafe trait IoVecBufMut: Unpin + 'static {
#[cfg(unix)]
/// Returns a raw mutable pointer to iovec struct.
/// struct iovec {
/// void *iov_base; /* Starting address */
Expand All @@ -200,15 +201,18 @@ pub unsafe trait IoVecBufMut: Unpin + 'static {
/// The implementation must ensure that, while the runtime owns the value,
/// the pointer returned by `write_iovec_ptr` **does not** change.
/// Also, the value pointed must be a valid iovec struct.
#[cfg(unix)]
fn write_iovec_ptr(&mut self) -> *mut libc::iovec;

/// Returns the count of iovec struct behind the pointer.
#[cfg(unix)]
fn write_iovec_len(&mut self) -> usize;

/// Returns a raw mutable pointer to WSABUF struct.
#[cfg(windows)]
fn write_wsabuf_ptr(&mut self) -> *mut WSABUF;

/// Returns the count of WSABUF struct behind the pointer.
#[cfg(windows)]
fn write_wsabuf_len(&mut self) -> usize;

Expand Down Expand Up @@ -252,19 +256,19 @@ unsafe impl IoVecBufMut for VecBuf {
#[cfg(windows)]
unsafe impl IoVecBufMut for VecBuf {
fn write_wsabuf_ptr(&mut self) -> *mut WSABUF {
self.write_wsabuf_ptr() as *mut _
self.read_wsabuf_ptr() as *mut _
}

fn write_wsabuf_len(&mut self) -> usize {
self.write_wsabuf_len()
self.read_wsabuf_len()
}

unsafe fn set_init(&mut self, mut len: usize) {
for (idx, wsabuf) in self.wsabufs.iter_mut().enumerate() {
if wsabuf.len <= len {
if wsabuf.len as usize <= len {
// set_init all
self.raw[idx].set_len(wsabuf.len);
len -= wsabuf.len;
self.raw[idx].set_len(wsabuf.len as _);
len -= wsabuf.len as usize;
} else {
if len > 0 {
self.raw[idx].set_len(len);
Expand Down
21 changes: 14 additions & 7 deletions monoio/src/buf/raw_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,21 @@ impl RawBuf {
/// make sure the pointer and length is valid when RawBuf is used.
#[inline]
pub unsafe fn new_from_iovec_mut<T: IoVecBufMut>(data: &mut T) -> Option<Self> {
if data.write_iovec_len() == 0 {
return None;
}
#[cfg(unix)]
{
if data.write_iovec_len() == 0 {
return None;
}
let iovec = *data.write_iovec_ptr();
Some(Self::new(iovec.iov_base as *const u8, iovec.iov_len))
}
#[cfg(windows)]
{
if data.write_wsabuf_len() == 0 {
return None;
}
let wsabuf = *data.write_wsabuf_ptr();
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len))
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len as _))
}
}

Expand All @@ -103,7 +106,7 @@ impl RawBuf {
return None;
}
let wsabuf = *data.read_wsabuf_ptr();
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len))
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len as _))
}
}
}
Expand All @@ -129,6 +132,10 @@ impl RawBufVectored {
pub const unsafe fn new(ptr: *const libc::iovec, len: usize) -> Self {
Self { ptr, len }
}

/// Create a new RawBuf with given pointer and length.
/// # Safety
/// make sure the pointer and length is valid when RawBuf is used.
#[cfg(windows)]
#[inline]
pub const unsafe fn new(ptr: *const WSABUF, len: usize) -> Self {
Expand Down Expand Up @@ -175,13 +182,13 @@ unsafe impl IoVecBufMut for RawBufVectored {

#[cfg(windows)]
#[inline]
fn write_wsabuf_ptr(&self) -> *mut WSABUF {
fn write_wsabuf_ptr(&mut self) -> *mut WSABUF {
self.ptr as *mut WSABUF
}

#[cfg(windows)]
#[inline]
fn write_wsabuf_len(&self) -> usize {
fn write_wsabuf_len(&mut self) -> usize {
self.len
}

Expand Down
11 changes: 8 additions & 3 deletions monoio/src/buf/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ unsafe impl<T: IoVecBuf> IoBuf for IoVecWrapper<T> {
#[cfg(windows)]
{
let wsabuf = unsafe { *self.raw.read_wsabuf_ptr() };
wsabuf.len
wsabuf.len as _
}
}
}
Expand All @@ -325,9 +325,14 @@ impl<T: IoVecBufMut> IoVecWrapperMut<T> {
/// Create a new IoVecWrapperMut with something that impl IoVecBufMut.
#[inline]
pub fn new(mut iovec_buf: T) -> Result<Self, T> {
#[cfg(unix)]
if iovec_buf.write_iovec_len() == 0 {
return Err(iovec_buf);
}
#[cfg(windows)]
if iovec_buf.write_wsabuf_len() == 0 {
return Err(iovec_buf);
}
Ok(Self { raw: iovec_buf })
}

Expand All @@ -348,7 +353,7 @@ unsafe impl<T: IoVecBufMut> IoBufMut for IoVecWrapperMut<T> {
#[cfg(windows)]
{
let wsabuf = unsafe { *self.raw.write_wsabuf_ptr() };
wsabuf.buf as *mut u8
wsabuf.buf
}
}

Expand All @@ -361,7 +366,7 @@ unsafe impl<T: IoVecBufMut> IoBufMut for IoVecWrapperMut<T> {
#[cfg(windows)]
{
let wsabuf = unsafe { *self.raw.write_wsabuf_ptr() };
wsabuf.len
wsabuf.len as _
}
}

Expand Down
Loading
Loading