Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bindigns expansion #2

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[FEAT]: additional functions exposed
* formatted
* some function chagned to usnafe
  • Loading branch information
Mateusz Matejuk committed Feb 6, 2024
commit 11180c413bdf875c116500a52159ef19d61a323b
67 changes: 67 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[workspace]
resolver = "2"
resolver = "2"

members = [
"examples/simple"
]
members = [ "examples/simple" ]

[profile.release]
debug = true
debug = true
lto = false

[profile.dev]
opt-level = 1
lto = false
17 changes: 8 additions & 9 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[package]
name = "simple"
version = "0.1.0"
edition = "2021"
edition = "2021"
name = "simple"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["staticlib"]

crate-type = [ "staticlib" ]


[dependencies]
anyhow = "1.0.71"
nginx_derive = { path = "../../nginx_derive" }
nginx_module = { path = "../../nginx_module" }
anyhow = "1.0.71"
nginx_derive = { path = "../../nginx_derive" }
nginx_module = { path = "../../nginx_module" }
20 changes: 16 additions & 4 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/

use std::ffi::{c_char, c_void};

use nginx_derive::NginxConfig;
use nginx_module::{
add_http_handler, nginx_version, ngx_command_t, ngx_conf_t, ngx_http_module_t, ngx_module_t,
ngx_str_t, HttpHandler, HttpRequestAndContext, NgxConfig, NgxStr, NGX_DECLINED,
NGX_HTTP_FORBIDDEN, NGX_HTTP_MODULE, NGX_RS_MODULE_SIGNATURE,
add_http_handler,
nginx_version,
ngx_command_t,
ngx_conf_t,
ngx_http_module_t,
ngx_module_t,
ngx_str_t,
HttpHandler,
HttpRequestAndContext,
NgxConfig,
NgxStr,
NGX_DECLINED,
NGX_HTTP_FORBIDDEN,
NGX_HTTP_MODULE,
NGX_RS_MODULE_SIGNATURE,
};

#[no_mangle]
32 changes: 18 additions & 14 deletions nginx_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
[package]
name = "nginx_derive"
version = "0.1.1"
edition = "2021"
authors = ["Gabriel Oprisan <gabriel.oprisan@gcore.com>"]
description = "Helper crate for nginx-rust"
homepage = "https://github.com/g-Core/nginx-rust"
repository = "https://github.com/g-Core/nginx-rust"
readme = "README.md"
license = "Apache-2.0"
authors = [ "Gabriel Oprisan <gabriel.oprisan@gcore.com>" ]
description = "Helper crate for nginx-rust"
edition = "2021"
homepage = "https://github.com/g-Core/nginx-rust"
license = "Apache-2.0"
name = "nginx_derive"
readme = "README.md"
repository = "https://github.com/g-Core/nginx-rust"
version = "0.1.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true
proc-macro = true

[dependencies]
syn = "2.0.18"
quote = "1.0.28"
proc-macro2 = "1.0.59"
proc-macro2 = { version = "1.0.59" }
quote = { version = "1.0.28" }
syn = { version = "2.0.18" }

[profile.release]
debug = true
lto = false
17 changes: 8 additions & 9 deletions nginx_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/

use proc_macro::TokenStream;
use proc_macro2::Literal;
use quote::{quote, quote_spanned, format_ident};
use quote::{format_ident, quote, quote_spanned};
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(NginxConfig)]
@@ -21,7 +21,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
syn::Data::Struct(s) => {
let struct_name = input.ident;
let commands_ident = format_ident!("{}_COMMANDS_AUTOGENERATED", struct_name);

let mut field_defs: Vec<_> = s.fields.iter().filter_map(|f| {
let name = f.ident.as_ref()?;
let name_nil_terminated = Literal::byte_string((name.to_string() + "\0").as_bytes());
@@ -39,7 +39,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
}
})
}).collect();
field_defs.push(quote!{
field_defs.push(quote! {
::nginx_module::NGX_RS_NULL_COMMAND
});
let field_count = field_defs.len();
@@ -64,10 +64,9 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
Err(e) => {
b"Invalid value\0".as_ptr() as *mut i8
}
}
}
}
})

});

let merge_fields = s.fields.iter().filter_map(|f| {
@@ -98,7 +97,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
Ok(c) => (c as *mut #struct_name).cast(),
}
}

pub unsafe extern "C" fn merge(
_cf: *mut ngx_conf_t,
parent: *mut c_void,
@@ -115,7 +114,7 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
}
}
}
},
}
syn::Data::Enum(e) => quote_spanned! {
e.enum_token.span =>
compile_error!("Config derive: expected a struct");
@@ -125,4 +124,4 @@ fn impl_derive_config(input: DeriveInput) -> proc_macro2::TokenStream {
compile_error!("Config derive: expected a struct");
},
}
}
}
31 changes: 16 additions & 15 deletions nginx_module/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
[package]
name = "nginx_module"
version = "0.1.4"
edition = "2021"
build = "build.rs"
authors = ["Gabriel Oprisan <gabriel.oprisan@gcore.com>"]
description = "Rust bindings for building Nginx modules"
homepage = "https://github.com/g-Core/nginx-rust"
repository = "https://github.com/g-Core/nginx-rust"
readme = "README.md"
license = "Apache-2.0"
authors = [ "Gabriel Oprisan <gabriel.oprisan@gcore.com>" ]
build = "build.rs"
description = "Rust bindings for building Nginx modules"
edition = "2021"
homepage = "https://github.com/g-Core/nginx-rust"
license = "Apache-2.0"
name = "nginx_module"
readme = "README.md"
repository = "https://github.com/g-Core/nginx-rust"
version = "0.1.4"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
bindgen = "0.66.1"
bindgen = { version = "0.66.1" }

[dependencies]
anyhow = "1.0.71"
bitflags = "2.3.1"
libc = "0.2.144"
anyhow = { version = "1.0.71" }
bitflags = { version = "2.3.1" }
libc = { version = "0.2.144" }
url = { version = "2.5" }
5 changes: 3 additions & 2 deletions nginx_module/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/

use bindgen::callbacks::{IntKind, ParseCallbacks};
use std::{
env,
path::{Path, PathBuf},
};

use bindgen::callbacks::{IntKind, ParseCallbacks};

const INCLUDE_SUBDIRS: &[&str] = &[
"objs/",
"src/core/",
12 changes: 9 additions & 3 deletions nginx_module/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/

#![allow(non_upper_case_globals, non_snake_case, dead_code, non_camel_case_types, clippy::all)]
#![allow(
non_upper_case_globals,
non_snake_case,
dead_code,
non_camel_case_types,
clippy::all
)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
13 changes: 8 additions & 5 deletions nginx_module/src/complex_value.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/

use std::{marker::PhantomData, mem::MaybeUninit};

use super::{HttpRequest, NgxConfig, NgxStr};
use crate::{
bindings::{
ngx_http_compile_complex_value, ngx_http_compile_complex_value_t, ngx_http_complex_value,
ngx_http_complex_value_t, ngx_palloc, NGX_OK,
ngx_http_compile_complex_value,
ngx_http_compile_complex_value_t,
ngx_http_complex_value,
ngx_http_complex_value_t,
ngx_palloc,
NGX_OK,
},
ConfigValue,
};

use super::{HttpRequest, NgxConfig, NgxStr};

#[derive(Copy, Clone)]
pub struct ComplexValue<'a> {
inner: *mut ngx_http_complex_value_t,
Loading