Skip to content

Commit

Permalink
Fix build with bindgen feature (#314)
Browse files Browse the repository at this point in the history
Since a2fed13, when the bindgen
feature is enabled, the build script writes the bindings to
OUT_DIR/sys_<arch>.rs (or src/sys/sys_<arch>.rs when the overwrite
feature is enabled). However, the src/sys/mod.rs file still imports the
file from OUT_DIR/sys.rs (without the architecture in the file name).

OUT_DIR already depends on the architecture, so there is no need to
include the architecture in the file name.

Modify the build script to write the file to OUT_DIR/sys.rs so that it
can be included by src/sys/mod.rs.
  • Loading branch information
beviu authored Feb 17, 2025
1 parent 7ad4f7f commit e1cece4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ fn build() {
#include <linux/futex.h>
"#;

#[cfg(not(feature = "overwrite"))]
let outdir = PathBuf::from(env::var("OUT_DIR").unwrap());

#[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 @@ -40,7 +32,18 @@ fn build() {
builder = builder.header_contents("include-file.h", INCLUDE);
}

let target_file = outdir.join(format!("sys_{}.rs", target_arch));
#[cfg(feature = "overwrite")]
fn output_file() -> PathBuf {
let outdir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src/sys");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
outdir.join(format!("sys_{}.rs", target_arch))
}

#[cfg(not(feature = "overwrite"))]
fn output_file() -> PathBuf {
let outdir = PathBuf::from(env::var("OUT_DIR").unwrap());
outdir.join("sys.rs")
}

builder
.ctypes_prefix("libc")
Expand All @@ -52,6 +55,6 @@ fn build() {
.allowlist_var("__NR_io_uring.*|IOSQE_.*|IORING_.*|IO_URING_.*|SPLICE_F_FD_IN_FIXED")
.generate()
.unwrap()
.write_to_file(target_file)
.write_to_file(output_file())
.unwrap();
}

0 comments on commit e1cece4

Please sign in to comment.