Skip to content

Commit e1cece4

Browse files
authored
Fix build with bindgen feature (#314)
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.
1 parent 7ad4f7f commit e1cece4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

build.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ fn build() {
2121
#include <linux/futex.h>
2222
"#;
2323

24-
#[cfg(not(feature = "overwrite"))]
25-
let outdir = PathBuf::from(env::var("OUT_DIR").unwrap());
26-
27-
#[cfg(feature = "overwrite")]
28-
let outdir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src/sys");
29-
30-
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
31-
3224
let mut builder = bindgen::Builder::default();
3325

3426
if let Some(path) = env::var("BUILD_IO_URING_INCLUDE_FILE")
@@ -40,7 +32,18 @@ fn build() {
4032
builder = builder.header_contents("include-file.h", INCLUDE);
4133
}
4234

43-
let target_file = outdir.join(format!("sys_{}.rs", target_arch));
35+
#[cfg(feature = "overwrite")]
36+
fn output_file() -> PathBuf {
37+
let outdir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src/sys");
38+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
39+
outdir.join(format!("sys_{}.rs", target_arch))
40+
}
41+
42+
#[cfg(not(feature = "overwrite"))]
43+
fn output_file() -> PathBuf {
44+
let outdir = PathBuf::from(env::var("OUT_DIR").unwrap());
45+
outdir.join("sys.rs")
46+
}
4447

4548
builder
4649
.ctypes_prefix("libc")
@@ -52,6 +55,6 @@ fn build() {
5255
.allowlist_var("__NR_io_uring.*|IOSQE_.*|IORING_.*|IO_URING_.*|SPLICE_F_FD_IN_FIXED")
5356
.generate()
5457
.unwrap()
55-
.write_to_file(target_file)
58+
.write_to_file(output_file())
5659
.unwrap();
5760
}

0 commit comments

Comments
 (0)