Skip to content

Commit 0f8b724

Browse files
authored
feat: make compile pass on windows (#238)
* try pass compile in windows * add condition * fix clippy * fix clippy
1 parent 2f73931 commit 0f8b724

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+658
-238
lines changed

.github/workflows/ci.sh

+40-36
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,60 @@
11
#!/usr/bin/env sh
22

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

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

10-
cargo install cross
11-
CARGO=cross
12-
fi
7+
CARGO=cargo
8+
if [ "${CROSS}" = "1" ]; then
9+
export CARGO_NET_RETRY=5
10+
export CARGO_NET_TIMEOUT=10
1311

14-
# If a test crashes, we want to know which one it was.
15-
export RUST_TEST_THREADS=1
16-
export RUST_BACKTRACE=1
12+
cargo install cross
13+
CARGO=cross
14+
fi
1715

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

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

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

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

31-
# enable uring+legacy driver
32-
"${CARGO}" test --target "${TARGET}"
33-
"${CARGO}" test --target "${TARGET}" --release
33+
if [ "${TARGET}" != "aarch64-unknown-linux-gnu" ] && [ "${TARGET}" != "armv7-unknown-linux-gnueabihf" ] &&
34+
[ "${TARGET}" != "riscv64gc-unknown-linux-gnu" ] && [ "${TARGET}" != "s390x-unknown-linux-gnu" ]; then
35+
# enable uring+legacy driver
36+
"${CARGO}" test --target "${TARGET}"
37+
"${CARGO}" test --target "${TARGET}" --release
38+
fi
3439

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

40-
fi
45+
# test monoio-compat mod
46+
cd "${PROJECT_DIR}"/monoio-compat
4147

42-
# test monoio-compat mod
43-
cd "${PROJECT_DIR}"/monoio-compat
48+
"${CARGO}" test --target "${TARGET}"
49+
"${CARGO}" test --target "${TARGET}" --release
4450

45-
"${CARGO}" test --target "${TARGET}"
46-
"${CARGO}" test --target "${TARGET}" --release
51+
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper
52+
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper --release
4753

48-
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper
49-
"${CARGO}" test --target "${TARGET}" --no-default-features --features hyper --release
54+
if [ "${CHANNEL}" == "nightly" ]; then
55+
"${CARGO}" test --target "${TARGET}" --all-features
56+
"${CARGO}" test --target "${TARGET}" --all-features --release
57+
fi
5058

51-
if [ "${CHANNEL}" == "nightly" ]; then
52-
"${CARGO}" test --target "${TARGET}" --all-features
53-
"${CARGO}" test --target "${TARGET}" --all-features --release
59+
# todo maybe we should test examples here ?
5460
fi
55-
56-
# todo maybe we should test examples here ?

.github/workflows/ci.yml

+17-14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
TARGET: ${{ matrix.target }}
5252
OS: ${{ matrix.os }}
5353
PROJECT_DIR: ${{ github.workspace }}
54+
NO_RUN: ${{ matrix.no_run }}
5455
run: sh .github/workflows/ci.sh
5556

5657
strategy:
@@ -69,11 +70,10 @@ jobs:
6970
x86_64-apple-darwin,
7071
aarch64-apple-darwin,
7172

72-
# unsupported yet
73-
# x86_64-pc-windows-gnu,
74-
# x86_64-pc-windows-msvc,
75-
# i686-pc-windows-gnu,
76-
# i686-pc-windows-msvc,
73+
x86_64-pc-windows-gnu,
74+
x86_64-pc-windows-msvc,
75+
i686-pc-windows-gnu,
76+
i686-pc-windows-msvc,
7777
]
7878
channel: [stable, nightly]
7979
include:
@@ -99,12 +99,15 @@ jobs:
9999
- target: aarch64-apple-darwin
100100
os: macos-14
101101

102-
# unsupported yet
103-
# - target: x86_64-pc-windows-msvc
104-
# os: windows-latest
105-
# - target: x86_64-pc-windows-gnu
106-
# os: windows-latest
107-
# - target: i686-pc-windows-msvc
108-
# os: windows-latest
109-
# - target: i686-pc-windows-gnu
110-
# os: windows-latest
102+
- target: x86_64-pc-windows-msvc
103+
os: windows-latest
104+
no_run: 1
105+
- target: x86_64-pc-windows-gnu
106+
os: windows-latest
107+
no_run: 1
108+
- target: i686-pc-windows-msvc
109+
os: windows-latest
110+
no_run: 1
111+
- target: i686-pc-windows-gnu
112+
os: windows-latest
113+
no_run: 1

monoio-macros/src/entry.rs

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ fn token_stream_with_error(mut tokens: TokenStream, error: syn::Error) -> TokenS
377377
tokens
378378
}
379379

380+
#[cfg(unix)]
380381
pub(crate) fn main(args: TokenStream, item: TokenStream) -> TokenStream {
381382
// If any of the steps for this macro fail, we still want to expand to an item that is as close
382383
// to the expected output as possible. This helps out IDEs such that completions and other

monoio/Cargo.toml

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,28 @@ memchr = "2.7"
2424
bytes = { version = "1", optional = true }
2525
flume = { version = "0.11", optional = true }
2626
mio = { version = "0.8", features = [
27-
"net",
28-
"os-poll",
29-
"os-ext",
27+
"net",
28+
"os-poll",
29+
"os-ext",
3030
], optional = true }
3131
threadpool = { version = "1", optional = true }
3232
tokio = { version = "1", default-features = false, optional = true }
3333
tracing = { version = "0.1", default-features = false, features = [
34-
"std",
34+
"std",
3535
], optional = true }
3636
ctrlc = { version = "3", optional = true }
3737
lazy_static = { version = "1", optional = true }
3838
once_cell = { version = "1.19.0", optional = true }
3939

4040
# windows dependencies(will be added when windows support finished)
41-
[target.'cfg(windows)'.dependencies.windows-sys]
42-
features = ["Win32_Foundation", "Win32_Networking_WinSock"]
43-
version = "0.48.0"
41+
[target.'cfg(windows)'.dependencies]
42+
windows-sys = { version = "0.48.0", features = [
43+
"Win32_Foundation",
44+
"Win32_Networking_WinSock",
45+
"Win32_System_IO",
46+
"Win32_Storage_FileSystem",
47+
"Win32_Security"
48+
] }
4449

4550
# unix dependencies
4651
[target.'cfg(unix)'.dependencies]

monoio/src/buf/io_vec_buf.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ pub unsafe trait IoVecBuf: Unpin + 'static {
2424
#[cfg(unix)]
2525
fn read_iovec_ptr(&self) -> *const libc::iovec;
2626

27-
#[cfg(unix)]
2827
/// Returns the count of iovec struct behind the pointer.
2928
///
3029
/// # Safety
3130
/// There must be really that number of iovec here.
31+
#[cfg(unix)]
3232
fn read_iovec_len(&self) -> usize;
3333

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

38+
/// Returns the count of WSABUF struct behind the pointer.
3739
#[cfg(windows)]
3840
fn read_wsabuf_len(&self) -> usize;
3941
}
@@ -110,7 +112,7 @@ impl From<Vec<Vec<u8>>> for VecBuf {
110112
.iter()
111113
.map(|v| WSABUF {
112114
buf: v.as_ptr() as _,
113-
len: v.len(),
115+
len: v.len() as _,
114116
})
115117
.collect();
116118
Self { wsabufs, raw: vs }
@@ -187,7 +189,6 @@ impl From<VecBuf> for Vec<Vec<u8>> {
187189
/// See the safety note of the methods.
188190
#[allow(clippy::unnecessary_safety_doc)]
189191
pub unsafe trait IoVecBufMut: Unpin + 'static {
190-
#[cfg(unix)]
191192
/// Returns a raw mutable pointer to iovec struct.
192193
/// struct iovec {
193194
/// void *iov_base; /* Starting address */
@@ -200,15 +201,18 @@ pub unsafe trait IoVecBufMut: Unpin + 'static {
200201
/// The implementation must ensure that, while the runtime owns the value,
201202
/// the pointer returned by `write_iovec_ptr` **does not** change.
202203
/// Also, the value pointed must be a valid iovec struct.
204+
#[cfg(unix)]
203205
fn write_iovec_ptr(&mut self) -> *mut libc::iovec;
204206

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

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

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

@@ -252,19 +256,19 @@ unsafe impl IoVecBufMut for VecBuf {
252256
#[cfg(windows)]
253257
unsafe impl IoVecBufMut for VecBuf {
254258
fn write_wsabuf_ptr(&mut self) -> *mut WSABUF {
255-
self.write_wsabuf_ptr() as *mut _
259+
self.read_wsabuf_ptr() as *mut _
256260
}
257261

258262
fn write_wsabuf_len(&mut self) -> usize {
259-
self.write_wsabuf_len()
263+
self.read_wsabuf_len()
260264
}
261265

262266
unsafe fn set_init(&mut self, mut len: usize) {
263267
for (idx, wsabuf) in self.wsabufs.iter_mut().enumerate() {
264-
if wsabuf.len <= len {
268+
if wsabuf.len as usize <= len {
265269
// set_init all
266-
self.raw[idx].set_len(wsabuf.len);
267-
len -= wsabuf.len;
270+
self.raw[idx].set_len(wsabuf.len as _);
271+
len -= wsabuf.len as usize;
268272
} else {
269273
if len > 0 {
270274
self.raw[idx].set_len(len);

monoio/src/buf/raw_buf.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,21 @@ impl RawBuf {
6969
/// make sure the pointer and length is valid when RawBuf is used.
7070
#[inline]
7171
pub unsafe fn new_from_iovec_mut<T: IoVecBufMut>(data: &mut T) -> Option<Self> {
72-
if data.write_iovec_len() == 0 {
73-
return None;
74-
}
7572
#[cfg(unix)]
7673
{
74+
if data.write_iovec_len() == 0 {
75+
return None;
76+
}
7777
let iovec = *data.write_iovec_ptr();
7878
Some(Self::new(iovec.iov_base as *const u8, iovec.iov_len))
7979
}
8080
#[cfg(windows)]
8181
{
82+
if data.write_wsabuf_len() == 0 {
83+
return None;
84+
}
8285
let wsabuf = *data.write_wsabuf_ptr();
83-
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len))
86+
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len as _))
8487
}
8588
}
8689

@@ -103,7 +106,7 @@ impl RawBuf {
103106
return None;
104107
}
105108
let wsabuf = *data.read_wsabuf_ptr();
106-
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len))
109+
Some(Self::new(wsabuf.buf as *const u8, wsabuf.len as _))
107110
}
108111
}
109112
}
@@ -129,6 +132,10 @@ impl RawBufVectored {
129132
pub const unsafe fn new(ptr: *const libc::iovec, len: usize) -> Self {
130133
Self { ptr, len }
131134
}
135+
136+
/// Create a new RawBuf with given pointer and length.
137+
/// # Safety
138+
/// make sure the pointer and length is valid when RawBuf is used.
132139
#[cfg(windows)]
133140
#[inline]
134141
pub const unsafe fn new(ptr: *const WSABUF, len: usize) -> Self {
@@ -175,13 +182,13 @@ unsafe impl IoVecBufMut for RawBufVectored {
175182

176183
#[cfg(windows)]
177184
#[inline]
178-
fn write_wsabuf_ptr(&self) -> *mut WSABUF {
185+
fn write_wsabuf_ptr(&mut self) -> *mut WSABUF {
179186
self.ptr as *mut WSABUF
180187
}
181188

182189
#[cfg(windows)]
183190
#[inline]
184-
fn write_wsabuf_len(&self) -> usize {
191+
fn write_wsabuf_len(&mut self) -> usize {
185192
self.len
186193
}
187194

monoio/src/buf/slice.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ unsafe impl<T: IoVecBuf> IoBuf for IoVecWrapper<T> {
310310
#[cfg(windows)]
311311
{
312312
let wsabuf = unsafe { *self.raw.read_wsabuf_ptr() };
313-
wsabuf.len
313+
wsabuf.len as _
314314
}
315315
}
316316
}
@@ -325,9 +325,14 @@ impl<T: IoVecBufMut> IoVecWrapperMut<T> {
325325
/// Create a new IoVecWrapperMut with something that impl IoVecBufMut.
326326
#[inline]
327327
pub fn new(mut iovec_buf: T) -> Result<Self, T> {
328+
#[cfg(unix)]
328329
if iovec_buf.write_iovec_len() == 0 {
329330
return Err(iovec_buf);
330331
}
332+
#[cfg(windows)]
333+
if iovec_buf.write_wsabuf_len() == 0 {
334+
return Err(iovec_buf);
335+
}
331336
Ok(Self { raw: iovec_buf })
332337
}
333338

@@ -348,7 +353,7 @@ unsafe impl<T: IoVecBufMut> IoBufMut for IoVecWrapperMut<T> {
348353
#[cfg(windows)]
349354
{
350355
let wsabuf = unsafe { *self.raw.write_wsabuf_ptr() };
351-
wsabuf.buf as *mut u8
356+
wsabuf.buf
352357
}
353358
}
354359

@@ -361,7 +366,7 @@ unsafe impl<T: IoVecBufMut> IoBufMut for IoVecWrapperMut<T> {
361366
#[cfg(windows)]
362367
{
363368
let wsabuf = unsafe { *self.raw.write_wsabuf_ptr() };
364-
wsabuf.len
369+
wsabuf.len as _
365370
}
366371
}
367372

0 commit comments

Comments
 (0)