Skip to content

Commit ef1186a

Browse files
committed
get working prototype
1 parent 4736890 commit ef1186a

3 files changed

Lines changed: 61 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315
- name: Install liburing-rs build dependencies
316316
shell: alpine.sh --root {0}
317317
run: |
318-
apk add --no-cache curl clang;
318+
apk add --no-cache curl clang rust-bindgen;
319319
320320
- name: Install Rust
321321
shell: alpine.sh {0}

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readme = "liburing-rs/README.md"
1010
keywords = ["io_uring", "liburing", "linux"]
1111
categories = ["asynchronous", "network-programming", "filesystem"]
1212
documentation = "https://man.archlinux.org/listing/extra/liburing/"
13+
1314
include = [
1415
"/src/arch",
1516
"/src/*.c",
@@ -42,6 +43,7 @@ path = "liburing-rs/tests/main.rs"
4243

4344
[features]
4445
sanitizers = []
46+
bindgen-cli = []
4547

4648
[target.'cfg(unix)'.build-dependencies]
4749
bindgen = "0.71.1"

liburing-rs/build.rs

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,64 @@ fn main()
6868

6969
println!("completed `make library` call");
7070

71-
let bindings = bindgen::Builder::default().clang_arg(format!("-I{}/src/include",
72-
out_path.to_str().unwrap()))
73-
.clang_arg("-std=gnu11")
74-
.header("liburing-rs/include/liburing_wrapper.h")
75-
.anon_fields_prefix("__liburing_anon_")
76-
.prepend_enum_name(false)
77-
.derive_default(true)
78-
.generate()
79-
.expect("Unable to generate bindings");
80-
81-
// Write the bindings to the $OUT_DIR/bindings.rs file.
82-
83-
bindings.write_to_file(out_path.join("liburing_bindings.rs"))
84-
.expect("Couldn't write bindings!");
71+
if cfg!(feature = "bindgen-cli") {
72+
let bindgen_cmd = match env::var("BINDGEN_PATH") {
73+
Ok(s) => s,
74+
Err(_) => String::from("bindgen"),
75+
};
76+
77+
// I hate this hack for getting the rustc version to pass to bindgen, and maybe there's a better way.
78+
let output = std::process::Command::new("rustc").arg("--version")
79+
.output()
80+
.expect("Failed to run rustc");
81+
82+
// ❯ rustc --version
83+
// rustc 1.90.0 (1159e78c4 2025-09-14)
84+
// ❯ rustc +nightly --version
85+
// rustc 1.92.0-nightly (4da69dfff 2025-10-01)
86+
let rustc_version = String::from_utf8(output.stdout).unwrap();
87+
let parts: Vec<&str> = rustc_version.split_whitespace().collect();
88+
let rustc_version = parts[1];
89+
90+
let rustc_version = rustc_version.split("-").next().unwrap();
91+
92+
let r = std::process::Command::new(&bindgen_cmd).args(["liburing-rs/include/liburing_wrapper.h",
93+
"--anon-fields-prefix",
94+
"__liburing_anon_",
95+
"--no-prepend-enum-name",
96+
"--with-derive-default",
97+
"--rust-edition", "2024",
98+
"--rust-target", rustc_version,
99+
"--output",
100+
out_path.join("liburing_bindings.rs")
101+
.to_str()
102+
.unwrap(),
103+
"--",
104+
"-std=gnu11",
105+
&format!("-I{}/src/include",
106+
out_path.to_str().unwrap()),
107+
])
108+
.output()
109+
.unwrap();
110+
111+
std::io::stderr().write_all(&r.stderr).unwrap();
112+
assert!(r.status.success());
113+
} else {
114+
let bindings = bindgen::Builder::default().clang_arg(format!("-I{}/src/include",
115+
out_path.to_str().unwrap()))
116+
.clang_arg("-std=gnu11")
117+
.header("liburing-rs/include/liburing_wrapper.h")
118+
.anon_fields_prefix("__liburing_anon_")
119+
.prepend_enum_name(false)
120+
.derive_default(true)
121+
.generate()
122+
.expect("Unable to generate bindings");
123+
124+
// Write the bindings to the $OUT_DIR/bindings.rs file.
125+
126+
bindings.write_to_file(out_path.join("liburing_bindings.rs"))
127+
.expect("Couldn't write bindings!");
128+
}
85129

86130
println!("generated bindings");
87131

0 commit comments

Comments
 (0)