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 }} 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" 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(()) + } +}