Merge pull request #40 from penberg/windows

Windows support
This commit is contained in:
Pekka Enberg
2024-03-03 11:53:29 +02:00
committed by GitHub
4 changed files with 55 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

View File

@@ -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"

View File

@@ -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;
}
}

46
core/io/windows.rs Normal file
View File

@@ -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<Self> {
Ok(Self {})
}
}
impl IO for WindowsIO {
fn open_file(&self, path: &str) -> Result<Box<dyn File>> {
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<std::fs::File>,
}
impl File for WindowsFile {
fn pread(&self, pos: usize, c: Arc<Completion>) -> 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(())
}
}