Skip to content

Commit 37627c4

Browse files
committed
feat(sys): import types from libc
The change introduces an optional feature nginx-sys/libc that replaces some generated types with corresponding imports from "libc".
1 parent bc1054f commit 37627c4

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ lock_api = "0.4.13"
3737
nginx-sys = { path = "nginx-sys", default-features=false, version = "0.5.0"}
3838
pin-project-lite = { version = "0.2.16", optional = true }
3939

40+
[workspace.dependencies]
41+
libc = { version = "0.2.174", default-features = false }
42+
4043
[features]
4144
default = ["std"]
4245
async = [

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ chrono = "0.4.23"
2222
http = "1.1.0"
2323
# use unicode-rs idna backend for lower MSRV and faster builds
2424
idna_adapter = "=1.1.0"
25-
libc = "0.2.140"
25+
libc.workspace = true
2626
tokio = { version = "1.33.0", features = ["full"] }
2727

2828
[[example]]

nginx-sys/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ default-target = "x86_64-unknown-linux-gnu"
2020
targets = []
2121

2222
[dependencies]
23+
libc = { optional = true, workspace = true }
2324
openssl-sys = { version = "0.9.109", optional = true }
2425

2526
[target.'cfg(not(windows))'.dependencies]
@@ -34,6 +35,8 @@ regex = "1.11.1"
3435
nginx-src = { version = "~1.28.0", optional = true, path = "../nginx-src" }
3536

3637
[features]
38+
# Reexport types from "libc" instead of generating our own bindings.
39+
libc = ["dep:libc"]
3740
# Reexport types from "openssl-sys" instead of generating our own bindings.
3841
# Note that openssl-sys depends on "std".
3942
openssl-sys = ["dep:openssl-sys"]

nginx-sys/build/main.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,57 @@ fn generate_binding(nginx: &NginxSource) {
250250
.rust_target(rust_target)
251251
.use_core();
252252

253-
if cfg!(feature = "openssl-sys") {
253+
if cfg!(any(feature = "libc", feature = "openssl-sys")) {
254254
use bindgen_callbacks::TypeFlags as TF;
255255

256256
let mut callbacks = bindgen_callbacks::NgxBindgenCallbacks::new();
257-
callbacks.add_external_types(
258-
"openssl_sys",
259-
[
260-
("SSL", TF::empty()),
261-
("SSL_CTX", TF::empty()),
262-
("SSL_SESSION", TF::empty()),
263-
],
264-
);
257+
if cfg!(feature = "libc") {
258+
callbacks.add_external_types(
259+
"libc",
260+
[
261+
("glob_t", TF::COPY),
262+
("in6_addr", TF::COPY),
263+
("iocb", TF::COPY),
264+
("sem_t", TF::COPY),
265+
("sockaddr_in", TF::COPY),
266+
("sockaddr_in6", TF::COPY),
267+
("stat", TF::COPY),
268+
("DIR", TF::COPY | TF::DEBUG),
269+
("cmsghdr", TF::COPY | TF::DEBUG),
270+
("cpu_set_t", TF::COPY | TF::DEBUG),
271+
("dirent", TF::COPY | TF::DEBUG),
272+
("gid_t", TF::COPY | TF::DEBUG),
273+
("in6_pktinfo", TF::COPY | TF::DEBUG),
274+
("in_addr_t", TF::COPY | TF::DEBUG),
275+
("in_pktinfo", TF::COPY | TF::DEBUG),
276+
("in_port_t", TF::COPY | TF::DEBUG),
277+
("ino_t", TF::COPY | TF::DEBUG),
278+
("iovec", TF::COPY | TF::DEBUG),
279+
("msghdr", TF::COPY | TF::DEBUG),
280+
("off_t", TF::COPY | TF::DEBUG),
281+
("pid_t", TF::COPY | TF::DEBUG),
282+
("pthread_cond_t", TF::COPY | TF::DEBUG),
283+
("pthread_mutex_t", TF::COPY | TF::DEBUG),
284+
("sockaddr", TF::COPY | TF::DEBUG),
285+
("sockaddr_un", TF::COPY | TF::DEBUG),
286+
("socklen_t", TF::COPY | TF::DEBUG),
287+
("time_t", TF::COPY | TF::DEBUG),
288+
("tm", TF::COPY | TF::DEBUG),
289+
("uid_t", TF::COPY | TF::DEBUG),
290+
],
291+
);
292+
}
293+
294+
if cfg!(feature = "openssl-sys") {
295+
callbacks.add_external_types(
296+
"openssl_sys",
297+
[
298+
("SSL", TF::empty()),
299+
("SSL_CTX", TF::empty()),
300+
("SSL_SESSION", TF::empty()),
301+
],
302+
)
303+
}
265304

266305
bindings = callbacks.add_to_builder(bindings);
267306
}

0 commit comments

Comments
 (0)