From 84a5115d77247d8e1b732e91c6bc18e81e3b66d7 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sun, 3 Mar 2024 11:29:23 +0200 Subject: [PATCH 1/3] core: Add Windows I/O module It's a copy of the synchronous I/O module that we use on Darwin. In the future, let's switch to Windows IOCP API. --- core/io/mod.rs | 5 +++++ core/io/windows.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 core/io/windows.rs diff --git a/core/io/mod.rs b/core/io/mod.rs index c55cf7cab..a2e4bb52d 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -102,4 +102,9 @@ cfg_block! { mod darwin; pub use darwin::DarwinIO as PlatformIO; } + + #[cfg(target_os = "windows")] { + mod windows; + pub use windows::WindowsIO as PlatformIO; + } } diff --git a/core/io/windows.rs b/core/io/windows.rs new file mode 100644 index 000000000..6178a7d38 --- /dev/null +++ b/core/io/windows.rs @@ -0,0 +1,46 @@ +use super::{Completion, File, IO}; +use anyhow::{Ok, Result}; +use std::sync::Arc; +use std::cell::RefCell; +use std::io::{Read, Seek}; +use log::trace; + +pub struct WindowsIO {} + +impl WindowsIO { + pub fn new() -> Result { + Ok(Self {}) + } +} + +impl IO for WindowsIO { + fn open_file(&self, path: &str) -> Result> { + trace!("open_file(path = {})", path); + let file = std::fs::File::open(path)?; + Ok(Box::new(WindowsFile { + file: RefCell::new(file), + })) + } + + fn run_once(&self) -> Result<()> { + Ok(()) + } +} + +pub struct WindowsFile { + file: RefCell, +} + +impl File for WindowsFile { + fn pread(&self, pos: usize, c: Arc) -> Result<()> { + let mut file = self.file.borrow_mut(); + file.seek(std::io::SeekFrom::Start(pos as u64))?; + { + let mut buf = c.buf_mut(); + let buf = buf.as_mut_slice(); + file.read_exact(buf)?; + } + c.complete(); + Ok(()) + } +} From 59822e2c6f2e6040a3083f0f330fd35c87f3f140 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sun, 3 Mar 2024 11:34:34 +0200 Subject: [PATCH 2/3] core: Don't depend on pprof on Windows --- core/Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index c334b7708..1bdebe8ed 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -31,9 +31,11 @@ fallible-iterator = "0.3.0" log = "0.4.20" sqlite3-parser = "0.11.0" +[target.'cfg(not(target_family = "windows"))'.dev-dependencies] +pprof = { version = "0.12.1", features = ["criterion", "flamegraph"] } + [dev-dependencies] criterion = { version = "0.5", features = ["html_reports", "async", "async_futures"] } -pprof = { version = "0.12.1", features = ["criterion", "flamegraph"] } rstest = "0.18.2" rusqlite = "0.29.0" From 69c6b67a26f006b505ee6fd41a5447d6b1a3a158 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sun, 3 Mar 2024 11:25:32 +0200 Subject: [PATCH 3/3] github: Run CI build on Windows --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1c2344fb1..2e908a30b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,7 +13,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }}