forked from nginx/ngx-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
72 lines (67 loc) · 2.79 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Bindings to NGINX
//! This project provides Rust SDK interfaces to the [NGINX](https://nginx.com) proxy allowing the creation of NGINX
//! dynamic modules completely in Rust.
//!
//! ## Build
//!
//! NGINX modules can be built against a particular version of NGINX. The following environment variables can be used
//! to specify a particular version of NGINX or an NGINX dependency:
//!
//! * `ZLIB_VERSION` (default 1.2.13) -
//! * `PCRE2_VERSION` (default 10.42)
//! * `OPENSSL_VERSION` (default 3.0.7)
//! * `NGX_VERSION` (default 1.23.3) - NGINX OSS version
//! * `NGX_DEBUG` (default to false)- if set to true, then will compile NGINX `--with-debug` option
//!
//! For example, this is how you would compile the [examples](https://github.com/nginxinc/ngx-rust/tree/master/examples) using a specific version of NGINX and enabling
//! debugging: `NGX_DEBUG=true NGX_VERSION=1.23.0 cargo build --package=examples --examples --release`
//!
//! To build Linux-only modules, use the "linux" feature: `cargo build --package=examples --examples --features=linux --release`
//!
//! After compilation, the modules can be found in the path `target/release/examples/` ( with the `.so` file extension for
//! Linux or `.dylib` for MacOS).
//!
//! Additionally, the folder `.cache/nginx/{NGX_VERSION}/{OS}/` will contain the compiled version of NGINX used to build
//! the SDK. You can start NGINX directly from this directory if you want to test the module or add it to `$PATH`
//! ```not_rust
//! $ export NGX_VERSION=1.23.3
//! $ cargo build --package=examples --examples --features=linux --release
//! $ export PATH=$PATH:`pwd`/.cache/nginx/$NGX_VERSION/macos-x86_64/sbin
//! $ nginx -V
//! $ ls -la ./target/release/examples/
//! # now you can use dynamic modules with the NGINX
//! ```
#![warn(missing_docs)]
pub mod core;
pub mod ffi;
pub mod http;
pub mod log;
/// Define modules exported by this library.
///
/// These are normally generated by the Nginx module system, but need to be
/// defined when building modules outside of it.
#[macro_export]
macro_rules! ngx_modules {
($( $mod:ident ),+) => {
#[no_mangle]
pub static mut ngx_modules: [*const ngx_module_t; $crate::count!($( $mod, )+) + 1] = [
$( unsafe { &$mod } as *const ngx_module_t, )+
std::ptr::null()
];
#[no_mangle]
pub static mut ngx_module_names: [*const c_char; $crate::count!($( $mod, )+) + 1] = [
$( concat!(stringify!($mod), "\0").as_ptr() as *const i8, )+
std::ptr::null()
];
#[no_mangle]
pub static mut ngx_module_order: [*const c_char; 1] = [
std::ptr::null()
];
};
}
/// Count number of arguments
#[macro_export]
macro_rules! count {
() => { 0usize };
($x:tt, $( $xs:tt ),*) => { 1usize + $crate::count!($( $xs, )*) };
}