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: conditional compilation support #97

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

bavshin-f5
Copy link
Collaborator

Nginx has various configuration options that may affect the availability of functions, constants and structure fields. This is not something that can be detected at runtime, as an attempt to use a symbol unavailable in the bindings would result in compilation error.

This PR introduces translation of a limited subset of NGX_... macros to the Rust cfg flags, allowing conditional checks like #[cfg(ngx_feature = "debug")].

There's no publicly available code that uses these flags yet, but I already need the functionality for some WIP stuff.

`cargo fmt` already passes this option, but some editors prefer to call
rustfmt directly.
nginx-sys cannot be used as rlib or as a static library.
@bavshin-f5 bavshin-f5 force-pushed the ngx-feature-checks branch 2 times, most recently from bf4e8f4 to daf6dba Compare November 15, 2024 03:55
The example build script converts `DEP_NGINX_FEATURES`, `DEP_NGINX_OS`
and `DEP_NGINX_VERSION_NUMBER` received from `nginx-sys` to the `cfg`
values for conditional compilation.

See tests for usage examples.
The flags set in cargo config will be ignored if the `RUSTFLAGS` is set.
Document cargo metadata variables set by the build script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant