Skip to content

Commit 26515b9

Browse files
committed
refactor(sys)!: remove foreign symbols from bindings
Leave only NGINX code and referenced types.
1 parent a129a2e commit 26515b9

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

examples/httporigdst.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
use std::ffi::{c_int, c_void};
22
use std::ptr::addr_of;
33

4+
use libc::sockaddr_storage;
45
use ngx::core;
56
use ngx::ffi::{
67
in_port_t, ngx_conf_t, ngx_connection_local_sockaddr, ngx_http_add_variable, ngx_http_module_t,
78
ngx_http_variable_t, ngx_inet_get_port, ngx_int_t, ngx_module_t, ngx_sock_ntop, ngx_str_t,
8-
ngx_variable_value_t, sockaddr, sockaddr_storage, INET_ADDRSTRLEN, NGX_HTTP_MODULE,
9+
ngx_variable_value_t, sockaddr, NGX_HTTP_MODULE,
910
};
1011
use ngx::http::{self, HttpModule};
1112
use ngx::{http_variable_get, ngx_log_debug_http, ngx_string};
1213

13-
const IPV4_STRLEN: usize = INET_ADDRSTRLEN as usize;
14+
const IPV4_STRLEN: usize = 16; // Not exported from `libc`
1415

1516
#[derive(Debug, Default)]
1617
struct NgxHttpOrigDstCtx {

nginx-sys/build/main.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,29 @@ fn generate_binding(nginx: &NginxSource) {
215215
.parse()
216216
.expect("rust-version is valid and supported by bindgen");
217217

218+
// Functions that we need for macro and inline fn reimplementations in the nginx-sys itself.
219+
#[cfg(windows)]
220+
let macro_dependencies = [
221+
"GetLastError",
222+
"SetLastError",
223+
"SwitchToThread",
224+
"WSAGetLastError",
225+
"WSASetLastError",
226+
"rand",
227+
];
228+
#[cfg(not(windows))]
229+
let macro_dependencies = ["random", "sched_yield", "usleep"];
230+
218231
let bindings = bindgen::Builder::default()
219-
// Bindings will not compile on Linux without block listing this item
220-
// It is worth investigating why this is
221-
.blocklist_item("IPPORT_RESERVED")
232+
// Allow all the NGINX symbols,
233+
.allowlist_function("ngx_.*")
234+
.allowlist_type("ngx_.*")
235+
.allowlist_var("(NGX|NGINX|ngx|nginx)_.*")
236+
// ...and a few symbols required for compilation,
237+
.allowlist_type("bpf_.*")
238+
.allowlist_type("sig_atomic_t|time_t|u_char|u_short")
239+
// ...and a couple of symbols we need in nginx-sys.
240+
.allowlist_function(macro_dependencies.join("|"))
222241
// will be restored later in build.rs
223242
.blocklist_item("NGX_ALIGNMENT")
224243
.generate_cstr(true)

0 commit comments

Comments
 (0)