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

Fix stub implementation and test in CI #21

Merged
merged 3 commits into from
Aug 5, 2021
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
27 changes: 24 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
check:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: cargo test

test-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
target:
Expand All @@ -84,8 +84,29 @@ jobs:
- name: Run tests
run: cargo test

check-stub:
runs-on: ubuntu-20.04
strategy:
matrix:
target:
- wasm32-unknown-unknown
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.target }}
override: true

- name: Run check
run: cargo check --all-targets --target ${{ matrix.target }}

test-msrv:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::unix::MmapInner;
#[cfg(not(any(unix, windows)))]
mod stub;
#[cfg(not(any(unix, windows)))]
use crate::stub::file_len;
#[cfg(not(any(unix, windows)))]
use crate::stub::MmapInner;

use std::fmt;
Expand All @@ -36,6 +38,9 @@ pub struct MmapRawDescriptor<'a>(&'a File);
#[cfg(unix)]
pub struct MmapRawDescriptor(std::os::unix::io::RawFd);

#[cfg(not(any(unix, windows)))]
pub struct MmapRawDescriptor<'a>(&'a File);

pub trait MmapAsRawDesc {
fn as_raw_desc(&self) -> MmapRawDescriptor;
}
Expand All @@ -61,6 +66,13 @@ impl MmapAsRawDesc for std::os::unix::io::RawFd {
}
}

#[cfg(not(any(unix, windows)))]
impl MmapAsRawDesc for &File {
fn as_raw_desc(&self) -> MmapRawDescriptor {
MmapRawDescriptor(self)
}
}

/// A memory map builder, providing advanced options and flags for specifying memory map behavior.
///
/// `MmapOptions` can be used to create an anonymous memory map using [`map_anon()`], or a
Expand Down
14 changes: 9 additions & 5 deletions src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ impl MmapInner {
))
}

pub fn map(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_exec(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_exec(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_mut(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_mut(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

pub fn map_copy_read_only(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
pub fn map_copy_read_only(_: usize, _: &File, _: u64, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}

Expand Down Expand Up @@ -74,3 +74,7 @@ impl MmapInner {
unreachable!("self unconstructable");
}
}

pub fn file_len(file: &File) -> io::Result<usize> {
Ok(file.metadata()?.len() as usize)
}