Skip to content

feat!: add nginx-src crate with vendored nginx sources #160

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
steps:
- name: checkout source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- name: set up cargo cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
continue-on-error: false
Expand Down Expand Up @@ -82,14 +84,16 @@ jobs:
- name: rustdoc
# always run if build succeeds
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: cargo doc --no-deps
run: cargo doc --all-features --no-deps

examples-linux:
name: Examples (Linux)
runs-on: ubuntu-latest
steps:
- name: checkout source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- name: set up cargo cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
continue-on-error: false
Expand Down Expand Up @@ -124,6 +128,8 @@ jobs:
- name: install command line dependencies
run: brew install make gnupg
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
with:
toolchain: stable
Expand Down Expand Up @@ -156,9 +162,9 @@ jobs:
- name: disable ipv6 for gpg
run: echo "disable-ipv6" > .cache/.gnupg/dirmngr.conf
- name: build
run: cargo build
run: cargo build --workspace --all-targets --features "async,vendored"
- name: run tests
run: cargo test --workspace
run: cargo test --workspace --features "async,vendored"

fmt:
name: Rustfmt
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "nginx-src/nginx"]
path = nginx-src/nginx
url = https://github.com/nginx/nginx.git
branch = stable-1.28
60 changes: 27 additions & 33 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"nginx-src",
"nginx-sys",
"examples",
]
Expand All @@ -24,6 +25,11 @@ homepage.workspace = true
repository.workspace = true
rust-version.workspace = true

[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-unknown-linux-gnu"
targets = []

[dependencies]
allocator-api2 = { version = "0.2.21", default-features = false }
async-task = { version = "4.7.1", optional = true }
Expand All @@ -32,7 +38,7 @@ nginx-sys = { path = "nginx-sys", default-features=false, version = "0.5.0"}
pin-project-lite = { version = "0.2.16", optional = true }

[features]
default = ["std", "vendored"]
default = ["std"]
async = [
"alloc",
"dep:async-task",
Expand All @@ -46,14 +52,11 @@ std = [
"alloc",
"allocator-api2/std"
]
# Build our own copy of the NGINX by default.
# This could be disabled with `--no-default-features` to minimize the dependency
# tree when building against an existing copy of the NGINX with the
# NGINX_SOURCE_DIR/NGINX_BUILD_DIR variables.
# Build our own copy of the NGINX from `nginx-src` crate.
vendored = ["nginx-sys/vendored"]

[badges]
maintenance = { status = "experimental" }

[dev-dependencies]
target-triple = "0.1.2"
tempfile = { version = "3.20.0", default-features = false }
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ fn main() {
}
}

// Pass build directory to the tests
println!("cargo::rerun-if-env-changed=DEP_NGINX_BUILD_DIR");
if let Ok(build_dir) = std::env::var("DEP_NGINX_BUILD_DIR") {
println!("cargo::rustc-env=DEP_NGINX_BUILD_DIR={build_dir}");
}

// Generate required compiler flags
if cfg!(target_os = "macos") {
// https://stackoverflow.com/questions/28124221/error-linking-with-cc-failed-exit-code-1
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ all-features = true

[licenses]
allow = [
"Apache-2.0 WITH LLVM-exception",
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"MIT",
Expand Down
19 changes: 19 additions & 0 deletions nginx-src/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "nginx-src"
# Version format: <NGINX major>.<NGINX minor>.<crate patch>+<NGINX version>
version = "1.28.0+1.28.0"
# Crate sources are licensed under Apache-2.0, with exception of the
# NGINX submodlue that is redistributed under BSD-2-Clause.
license = "Apache-2.0 AND BSD-2-Clause"
description = "Source of NGINX"
keywords = ["nginx", "module", "sys"]
edition.workspace = true
homepage.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
duct = "1"
flate2 = "1"
tar = "0.4"
ureq = "3.0.10"
1 change: 1 addition & 0 deletions nginx-src/LICENSE
74 changes: 74 additions & 0 deletions nginx-src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# nginx-src

This crate contains a vendored copy of the NGINX source and the logic to
build it. It is intended to be consumed by the [nginx-sys] crate for CI
builds, tests or rustdoc generation.

It is notably not intended for producing binaries suitable for production
use. For such scenaros we recommend building the ngx-rust based module
against prebuilt packages from <https://nginx.org/> or your preferred
distribution. See the [nginx-sys] documentation for building ngx-rust
modules against an existing pre-configured NGINX source tree.

[nginx-sys]: https://docs.rs/nginx-sys/

## Versioning

This crate follows the latest stable branch of NGINX.

* The major and minor fields are taken from the NGINX version.
* The patch version is incremented on changes to the build logic or crate
metadata.
* The version metadata contains full version of NGINX.

## Build Requirements

The crate can be built on common Unix-like operating systems and requires
all the usual NGINX build dependencies (including development headers
for the libraries) installed in system paths:

* C compiler and toolchain
* SSL library, OpenSSL or LibreSSL
* PCRE or PCRE2
* Zlib or zlib-ng witn Zlib compatibile API enabled

We don't intend to support Windows at the moment, as NGINX does not
support dynamic modules for this target.

## Environment variables

Following variables can be set to customize the build.

* `NGX_CONFIGURE_ARGS` — additional arguments to pass to the NGINX configure
script.

Example: `export NGX_CONFIGURE_ARGS='--with-debug'; cargo build`

* `NGX_CFLAGS`, `NGX_LDFLAGS` — additional C compiler and linker flags to pass
to the NGINX configure script. Internally, this is added to the
`--with-cc-opt=...` and `--with-ld-opt=...` arguments.

Example:
```sh
export NGX_CFLAGS='-I/opt/boringssl/include'
export NGX_LDFLAGS='-L/opt/boringssl/build -lstdc++'
cargo build
```

Setting any of the following variables would result in downloading source
archives from the network.

* `NGX_VERSION` — if specified, the version of NGINX to download and build
instead of the one bundled with the crate.
* `OPENSSL_VERSION` — if specified, the version of OpenSSL to download and
use instead of the system-provided library.
* `PCRE2_VERSION` — if specified, the version of PCRE2 to download and use
instead of the system-provided library.
* `ZLIB_VERSION` — if specified, the version of Zlib to download and use
instead of the system-provided library.

## License

The code in this crate is licensed under the [Apache License 2.0](../LICENSE).
The crate also contains the source code of NGINX, distributed under the
[BSD 2-Clause License](https://nginx.org/LICENSE).
1 change: 1 addition & 0 deletions nginx-src/nginx
Submodule nginx added at 481d28
Loading
Loading