Skip to content

Commit

Permalink
vendor aarch64 sys.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
quininer committed Sep 21, 2024
1 parent 5e332f3 commit c214d42
Show file tree
Hide file tree
Showing 9 changed files with 6,045 additions and 3,014 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Bench
run: cargo bench --package io-uring-bench

check-x86_64:
check-vendor:
runs-on: ubuntu-latest

strategy:
Expand All @@ -44,6 +44,7 @@ jobs:
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-gnu

steps:
- uses: actions/checkout@v4
Expand All @@ -68,7 +69,6 @@ jobs:
- "1.63"
target:
- i686-unknown-linux-gnu
- aarch64-unknown-linux-gnu

steps:
- uses: actions/checkout@v4
Expand All @@ -83,6 +83,32 @@ jobs:
RUSTFLAGS: --cfg=io_uring_skip_arch_check
run: cargo clippy --target ${{ matrix.target }}

check-own:
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
toolchain:
- stable
target:
- x86_64-unknown-linux-gnu

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.target }}
components: clippy
override: true
- name: Lint
env:
RUSTFLAGS: --cfg=io_uring_use_own_sys
IO_URING_OWN_SYS_BINDING: src/sys/sys_aarch64.rs
run: cargo check --target ${{ matrix.target }}

fmt:
name: fmt
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ io_safety = []

[dependencies]
bitflags = "2"
cfg-if = "1"

libc = { version = "0.2.98", default-features = false }
sc = { version = "0.2", optional = true }
Expand Down
7 changes: 6 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {
build();

println!("cargo::rustc-check-cfg=cfg(io_uring_skip_arch_check)");
println!("cargo::rustc-check-cfg=cfg(io_uring_use_own_sys)");
}

#[cfg(feature = "bindgen")]
Expand All @@ -26,6 +27,8 @@ fn build() {
#[cfg(feature = "overwrite")]
let outdir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src/sys");

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

let mut builder = bindgen::Builder::default();

if let Some(path) = env::var("BUILD_IO_URING_INCLUDE_FILE")
Expand All @@ -37,6 +40,8 @@ fn build() {
builder = builder.header_contents("include-file.h", INCLUDE);
}

let target_file = outdir.join(format!("sys_{}.rs", target_arch));

builder
.ctypes_prefix("libc")
.prepend_enum_name(false)
Expand All @@ -47,6 +52,6 @@ fn build() {
.allowlist_var("__NR_io_uring.*|IOSQE_.*|IORING_.*|IO_URING_.*|SPLICE_F_FD_IN_FIXED")
.generate()
.unwrap()
.write_to_file(outdir.join("sys.rs"))
.write_to_file(target_file)
.unwrap();
}
2 changes: 2 additions & 0 deletions io-uring-test/src/tests/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ pub fn test_file_direct_write_read<S: squeue::EntryMarker, C: cqueue::EntryMarke

assert_eq!(cqes.len(), 1);
assert_eq!(cqes[0].user_data(), 0x03);

// when fs does not support Direct IO, it may fallback to buffered IO.
assert_eq_warn!(cqes[0].result(), -libc::EINVAL);

Ok(())
Expand Down
55 changes: 28 additions & 27 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,9 @@ use std::io;

use libc::*;

#[cfg(feature = "direct-syscall")]
fn to_result(ret: c_int) -> io::Result<c_int> {
if ret >= 0 {
Ok(ret)
} else {
Err(io::Error::from_raw_os_error(-ret))
}
}

#[cfg(not(feature = "direct-syscall"))]
fn to_result(ret: c_int) -> io::Result<c_int> {
if ret >= 0 {
Ok(ret)
} else {
Err(io::Error::last_os_error())
}
}

#[cfg(all(
not(feature = "bindgen"),
not(target_arch = "x86_64"),
not(any(target_arch = "x86_64", target_arch = "aarch64")),
not(io_uring_skip_arch_check)
))]
compile_error!(
Expand All @@ -44,14 +26,15 @@ please use bindgen feature to generate new `sys.rs` of your arch
or use `--cfg=io_uring_skip_arch_check` to skip the check."
);

#[cfg(all(feature = "bindgen", not(feature = "overwrite")))]
include!(concat!(env!("OUT_DIR"), "/sys.rs"));

#[cfg(any(
not(feature = "bindgen"),
all(feature = "bindgen", feature = "overwrite")
))]
include!("sys.rs");
cfg_if::cfg_if!{
if #[cfg(io_uring_use_own_sys)] {
include!(env!("IO_URING_OWN_SYS_BINDING"));
} else if #[cfg(all(feature = "bindgen", not(feature = "overwrite")))] {
include!(concat!(env!("OUT_DIR"), "/sys.rs"));
} else {
include!("sys.rs");
}
}

#[cfg(feature = "bindgen")]
const SYSCALL_REGISTER: c_long = __NR_io_uring_register as _;
Expand All @@ -71,6 +54,24 @@ const SYSCALL_ENTER: c_long = __NR_io_uring_enter as _;
#[cfg(not(feature = "bindgen"))]
const SYSCALL_ENTER: c_long = libc::SYS_io_uring_enter;

#[cfg(feature = "direct-syscall")]
fn to_result(ret: c_int) -> io::Result<c_int> {
if ret >= 0 {
Ok(ret)
} else {
Err(io::Error::from_raw_os_error(-ret))
}
}

#[cfg(not(feature = "direct-syscall"))]
fn to_result(ret: c_int) -> io::Result<c_int> {
if ret >= 0 {
Ok(ret)
} else {
Err(io::Error::last_os_error())
}
}

#[cfg(not(feature = "direct-syscall"))]
pub unsafe fn io_uring_register(
fd: c_int,
Expand Down
Loading

0 comments on commit c214d42

Please sign in to comment.