Giter Site home page Giter Site logo

ngx-rust's Introduction

Rust crates.io Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept. Community Support

Project status

This project is still a work in progress and not production ready.

Description

This project provides Rust SDK interfaces to the NGINX proxy allowing the creation of NGINX dynamic modules completely in Rust.

In short, this SDK allows writing NGINX modules using the Rust language.

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.3.1) - zlib version
  • PCRE2_VERSION (default 10.42 for NGINX 1.22.0 and later, or 8.45 for earlier) - PCRE1 or PCRE2 version
  • OPENSSL_VERSION (default 3.2.1 for NGINX 1.22.0 and later, or 1.1.1w for earlier) - OpenSSL version
  • NGX_VERSION (default 1.26.1) - 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 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}/{TARGET} ({TARGET} means rustc's target triple string) 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.

The following environment variables can be used to change locations of cache directory and NGINX directory:

  • CACHE_DIR (default [nginx-sys's root directory]/.cache) - the directory containing cache files, means PGP keys, tarballs, PGP signatures, and unpacked source codes. It also contains compiled NGINX in default configuration.
  • NGINX_INSTALL_ROOT_DIR (default {CACHE_DIR}/nginx) - the directory containing the series of compiled NGINX in its subdirectories
  • NGINX_INSTALL_DIR (default {NGINX_INSTALL_BASE_DIR}/{NGX_VERSION}/{TARGET}) - the directory containing the NGINX compiled in the build

Mac OS dependencies

In order to use the optional GNU make build process on MacOS, you will need to install additional tools. This can be done via homebrew with the following command:

brew install make openssl grep

Additionally, you may need to set up LLVM and clang. Typically, this is done as follows:

# make sure xcode tools are installed
xcode-select --install
# instal llvm
brew install --with-toolchain llvm

Linux dependencies

See the Dockerfile for dependencies as an example of required packages on Debian Linux.

Build example

Example modules are available in examples folder. You can use cargo build --package=examples --examples to build these examples. After building, you can find the .so or .dylib in the target/debug folder. Add --features=linux to build linux specific modules. NOTE: adding the "linux" feature on MacOS will cause a build failure.

For example (all examples plus linux specific): cargo build --package=examples --examples --features=linux

Build with external NGINX source tree

If you require a customized NGINX configuration, you can build a module against an existing pre-configured source tree. To do that, you need to set the NGX_OBJS variable to an absolute path of the NGINX build directory (--builddir, defaults to the objs in the source directory). Only the ./configure step of the NGINX build is mandatory because bindings don't depend on any of the artifacts generated by make.

NGX_OBJS=$PWD/../nginx/objs cargo build --package=examples --examples

Furthermore, this approach can be leveraged to build a module as a part of the NGINX build process by adding the --add-module/--add-dynamic-module options to the configure script. See the following example integration scripts: examples/config and examples/config.make.

Docker

We provide a multistage Dockerfile:

# build all dynamic modules examples and specify NGINX version to use
docker buildx build --build-arg NGX_VERSION=1.23.3 -t ngx-rust .

# start NGINX using [curl](examples/curl.conf) module example:
docker run --rm -d  -p 8000:8000 ngx-rust nginx -c examples/curl.conf

# test it - you should see 403 Forbidden
curl http://127.0.0.1:8000 -v -H "user-agent: curl"


# test it - you should see 404 Not Found
curl http://127.0.0.1:8000 -v -H "user-agent: foo"

Usage

A complete module example using the SDK can be found here. You can build it with cargo build --package=examples --example=curl then set up NGINX to use it:

For example:

daemon off;
master_process off;

# unix:
# load_module modules/libcurl.so;

# error_log logs/error.log debug;
error_log /dev/stdout debug;

working_directory /tmp/cores/;
worker_rlimit_core 500M;

events {
}

http {
    access_log /dev/stdout;
    server {
        listen 8000;
        server_name localhost;
        location / {
            alias /srv/http;
            # ... Other config stuff ...

            curl on;
        }
    }
}

Support

This SDK is currently unstable. Right now, our primary goal is collect feedback and stabilize it be before offering support. Feel free contributing by creating issues, PRs, or github discussions.

Currently, the only supported platforms are:

  • Darwin (Mac OSX)
  • Linux platform

Roadmap

If you have ideas for releases in the future, please suggest them in the github discussions.

Contributing

We welcome pull requests and issues!

Please refer to the Contributing Guidelines when doing a PR.

Authors and acknowledgment

This project uses some great work from dcoles/nginx-rs, arvancloud/nginx-rs.

Projects using the SDK

ngx-strict-sni - Strict SNI validator for Nginx

License

All code in this repository is licensed under the Apache License v2 license.

ngx-rust's People

Contributors

alexzorin avatar allan2 avatar baerwang avatar bavshin-f5 avatar dekobon avatar f5yacobucci avatar ivanitskiy avatar jyjyjcr avatar messense avatar mtb0x1 avatar sahandevs avatar ytlm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-rust's Issues

compile modules via nginx's configure tool

Is your feature request related to a problem? Please describe.
It would be beneficial to allow building/compiling dynamic modules using a standard way that is used to build C-based modules like
./configure --add-dynamic-module=/opt/source/ngx_rust_my_module/

Further reading:

By doing so ngx-rust-based modules would be easer to build at the same time when nginx is building itself.

build: zlib 1.2.13 not available anymore

Describe the bug
zlib 1.3 ws released on August 18, 2023 and zlib.net is not serving 1.2.13 version anymore which is causing compile time.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure you have no .cache folder and target is cleaned up, run make clean

  2. Build a module ZLIB_VERSION=1.2.13 cargo build -p examples --examples

   Compiling nginx-sys v0.1.0 (/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/nginx-sys)
error: failed to run custom build command for `nginx-sys v0.1.0 (/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/nginx-sys)`

Caused by:
  process didn't exit successfully: `/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/target/debug/build/nginx-sys-3b08605f44a50128/build-script-build` (exit status: 1)
  --- stdout
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: keybox '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg/pubring.kbx' created
  gpg: /Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg/trustdb.gpg: trustdb created
  gpg: key 783FCD8E58BCAFBA: public key "Mark Adler <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: 783FCD8E58BCAFBA
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key 9766E084FB0F43D8: 1 duplicate signature removed
  gpg: key 9766E084FB0F43D8: public key "Philip Hazel <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: 9766E084FB0F43D8
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key B8EF1A6BA9DA2D5C: public key "TomΓ‘Ε‘ MrΓ‘z <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: A21FAB74B0088AA361152586B8EF1A6BA9DA2D5C
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key D9C4D26D0E604491: public key "Matt Caswell <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: 8657ABB260F056B1E5190839D9C4D26D0E604491
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key 231C84CDDCC69C45: public key "Paul Dale <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: B7C1C14360F353A36862E4D5231C84CDDCC69C45
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key 3D30A3A9FF1360DC: public key "Hugo Landau (2013 Principal) <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: 95A9908DDFA16830BE9FB9003D30A3A9FF1360DC
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key D5E9E43F7DF9EE8C: public key "Richard Levitte <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: 7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C
  gpg: WARNING: unsafe permissions on homedir '/Users/ivanitskiy/go/src/github.com/nginxinc/ngx-rust/.cache/.gnupg'
  gpg: key A0EA981B66B0D967: public key "Konstantin Pavlov <[email protected]>" imported
  gpg: Total number processed: 1
  gpg:               imported: 1
  Imported GPG key: A0EA981B66B0D967

  --- stderr
  Error: Status(404, Response[status: 404, status_text: Not Found, url: https://www.zlib.net/zlib-1.2.13.tar.gz.asc])

Expected behavior
Able to compile with 1.2.13 zlib (by default).

Your environment

Additional context
Add any other context about the problem here. Any log files you want to share.

Build error: "_FORTIFY_SOURCE" redefined [-Werror]

Describe the bug
Can't build on Ubuntu 24.04 at 85/88: nginx-sys(build)

To Reproduce

git clone https://github.com/nginxinc/ngx-rust
cargo b

I see:

Blocking waiting for file lock on build directory
   Compiling nginx-sys v0.5.0 (/home/i/ngx-rust/nginx-sys)
error: failed to run custom build command for `nginx-sys v0.5.0 (/home/i/ngx-rust/nginx-sys)`

Caused by:
  process didn't exit successfully: `/home/i/ngx-rust/target/debug/build/nginx-sys-6d4e38600c2f20d0/build-script-main` (exit status: 1)
  --- stdout
...
...
 install ./include/openssl/x509err.h -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include/openssl/x509err.h
  install ./include/openssl/x509v3.h -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include/openssl/x509v3.h
  install ./include/openssl/x509v3err.h -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include/openssl/x509v3err.h
  install libcrypto.a -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/lib/libcrypto.a
  install libssl.a -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/lib/libssl.a
  install libcrypto.pc -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/lib/pkgconfig/libcrypto.pc
  install libssl.pc -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/lib/pkgconfig/libssl.pc
  install openssl.pc -> /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/lib/pkgconfig/openssl.pc
  gmake[2]: Leaving directory '/home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1'
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/nginx.o \
  	src/core/nginx.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_log.o \
  	src/core/ngx_log.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_palloc.o \
  	src/core/ngx_palloc.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_array.o \
  	src/core/ngx_array.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_list.o \
  	src/core/ngx_list.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_hash.o \
  	src/core/ngx_hash.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_buf.o \
  	src/core/ngx_buf.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_queue.o \
  	src/core/ngx_queue.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_output_chain.o \
  	src/core/ngx_output_chain.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_string.o \
  	src/core/ngx_string.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_parse.o \
  	src/core/ngx_parse.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_parse_time.o \
  	src/core/ngx_parse_time.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_inet.o \
  	src/core/ngx_inet.c
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_file.o \
  	src/core/ngx_file.c
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_crc32.o \
  	src/core/ngx_crc32.c
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: note: this is the location of the previous definition
  cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/pcre2-10.42/src/ -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/openssl-3.2.1/.openssl/include -I /home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/zlib-1.3.1 -I objs \
  	-o objs/src/core/ngx_murmurhash.o \
  	src/core/ngx_murmurhash.c
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  <command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
  <command-line>: note: this is the location of the previous definition
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:595: objs/src/core/ngx_crc32.o] Error 1
  gmake[1]: *** Waiting for unfinished jobs....
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:518: objs/src/core/ngx_array.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:602: objs/src/core/ngx_murmurhash.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:567: objs/src/core/ngx_parse.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:511: objs/src/core/ngx_palloc.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:553: objs/src/core/ngx_output_chain.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:497: objs/src/core/nginx.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:539: objs/src/core/ngx_buf.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:574: objs/src/core/ngx_parse_time.o] Error 1
  cc1: all warnings being treated as errors
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:546: objs/src/core/ngx_queue.o] Error 1
  gmake[1]: *** [objs/Makefile:560: objs/src/core/ngx_string.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:525: objs/src/core/ngx_list.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:504: objs/src/core/ngx_log.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:581: objs/src/core/ngx_inet.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:532: objs/src/core/ngx_hash.o] Error 1
  cc1: all warnings being treated as errors
  gmake[1]: *** [objs/Makefile:588: objs/src/core/ngx_file.o] Error 1
  gmake[1]: Leaving directory '/home/i/ngx-rust/.cache/src/x86_64-unknown-linux-gnu/nginx-1.24.0'
  gmake: *** [Makefile:13: install] Error 2

  --- stderr
  Error: Custom { kind: Other, error: "command [\"/usr/bin/gmake\", \"-j\", \"16\", \"install\"] exited with code 2" }

Possibly fix
I remove this: -Wp,-D_FORTIFY_SOURCE=2 from

const NGX_LINUX_ADDITIONAL_OPTS: [&str; 3] = [
    "--with-file-aio",
    "--with-cc-opt=-g -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC",
    "--with-ld-opt=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie",
];

to

const NGX_LINUX_ADDITIONAL_OPTS: [&str; 3] = [
    "--with-file-aio",
    "--with-cc-opt=-g -fstack-protector-strong -Wformat -Werror=format-security -fPIC",
    "--with-ld-opt=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie",
];

and compilation was success

My environment

  • Version of the repo - a specific commit or tag: commit 8875fb8 (HEAD -> master, origin/master, origin/HEAD)
  • Version of ngx-rust: 0.5
  • Version of Rust: info: The currently active rustc version is rustc 1.78.0 (9b00956e5 2024-04-29)
  • OS and distribution: Ubuntu 24.04 LTS

Additional context
Add any other context about the problem here. Any log files you want to share.

Can't build ngx = "0.4.1" because wrong zlib url substitution

Describe the bug
can't build project with ngx = "0.4.1":

   Compiling nginx-sys v0.2.1
   Compiling app v0.1.0 (ssh://[email protected]/datsteam/wafng/wafng.git?branch=feature/multitenant#f0d78440)
error: failed to run custom build command for `nginx-sys v0.2.1`

Caused by:
  process didn't exit successfully: `/home/i/nginx-wafng-filter/target/debug/build/nginx-sys-8749b18e0178e362/build-script-build` (exit status: 1)
  --- stderr
  Error: Status(404, Response[status: 404, status_text: Not Found, url: https://www.zlib.net/zlib-1.3.tar.gz.asc])
warning: build failed, waiting for other jobs to finish...

B7C1C14360F353A36862E4D5231C84CDDCC69C45

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. See my project that depends on this project
  2. View logs on '....'
  3. Run this test I created
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Your environment

  • Version of the repo - a specific commit or tag
  • Version of ngx-rust
  • Version of Rust
  • Version of NGINX (and all dependencies if modified)
  • OS and distribution
  • Details about containerization, virtualization, or physical environment

Additional context
Add any other context about the problem here. Any log files you want to share.

Add Event timers

Is your feature request related to a problem? Please describe.
While working on a retry module it became clear there was no facility to schedule actions for the future. NGINX supports timers via the event API. Exposing event timers can be useful to a variety of use cases: repetitive actions outside of I/O events, timeouts for I/O events, or one shot condition checks.

Describe the solution you'd like
Expose an idiomatic Rust API for NGINX ngx_event_t types. The first set of APIs required is to expose timers. A proposal for this work is here and is generally complete, but needs to be broken apart from other features (subrequest updates).

This issue should start with the existing branch and only pull over the necessary Event timer API.

macro stubbing

Macro to generate stubbing for

  • directive
  • context
  • definition

Dockerfile fails with newer openssl version

The current openssl versions does not include 3.0.7 that ngx-sys was compiled against so I have added in the Dockerfile the latest version: ENV OPENSSL_VERSION 3.2.0

However, the dockerfile fails with an error that seems to be related to pgp validation in the build actions in ngx-sys:

=> ERROR [build 6/6] RUN --mount=type=cache,id=target,target=target     --mount=type=cache,id=cache,target=.cache     --mount=type=ca  1.8s 
------                                                                                                                                       
 > [build 6/6] RUN --mount=type=cache,id=target,target=target     --mount=type=cache,id=cache,target=.cache     --mount=type=cache,id=cargo,target=/usr/local/cargo/registry     mkdir -p /out &&     cargo build --release --package examples --examples &&     mv /project/target/release/examples/*.so /out:
0.603    Compiling nginx-sys v0.2.1 (/project/nginx-sys)
1.673 error: failed to run custom build command for `nginx-sys v0.2.1 (/project/nginx-sys)`
1.673 
1.673 Caused by:
1.674   process didn't exit successfully: `/project/target/release/build/nginx-sys-33f897259fe1683d/build-script-build` (exit status: 1)
1.674   --- stdout
1.674   Archive [zlib-1.3] already extracted to directory: /project/.cache/src/linux-x86_64/zlib-1.3
1.674   Archive [pcre2-10.42] already extracted to directory: /project/.cache/src/linux-x86_64/pcre2-10.42
1.674 
1.674   --- stderr
1.674   Error: Custom { kind: Other, error: "command [\"/usr/bin/gpg\", \"--homedir\", \"/project/.cache/.gnupg\", \"--verify\", \"/project/.cache/openssl-3.2.0.tar.gz.asc\", \"/project/.cache/openssl-3.2.0.tar.gz\"] exited with code 2" }
------
Dockerfile:32
--------------------
  31 |     
  32 | >>> RUN --mount=type=cache,id=target,target=target \
  33 | >>>     --mount=type=cache,id=cache,target=.cache \
  34 | >>>     --mount=type=cache,id=cargo,target=/usr/local/cargo/registry \
  35 | >>>     mkdir -p /out && \
  36 | >>>     cargo build --release --package examples --examples && \
  37 | >>>     mv /project/target/release/examples/*.so /out
  38 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c mkdir -p /out &&     cargo build --release --package examples --examples &&     mv /project/target/release/examples/*.so /out" did not complete successfully: exit code: 101

Curl example doesn't compile : method not found in `Option<&NgxStr>`

Describe the bug
I can't compile curl example, error message :

error[E0599]: no method named `as_bytes` found for enum `Option` in the current scope
   --> examples/curl.rs:114:37
    |
114 |             if request.user_agent().as_bytes().starts_with(b"curl") {
    |                                     ^^^^^^^^ method not found in `Option<&NgxStr>`
    |
note: the method `as_bytes` exists on the type `&NgxStr`
   --> /home/user/apps/rust/ngx-rust/src/core/string.rs:55:5
    |
55  |     pub fn as_bytes(&self) -> &[u8] {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using `Option::expect` to unwrap the `&NgxStr` value, panicking if the value is an `Option::None`
    |
114 |             if request.user_agent().expect("REASON").as_bytes().starts_with(b"curl") {
    |                                    +++++++++++++++++

For more information about this error, try `rustc --explain E0599`.
error: could not compile `examples` (example "curl") due to previous error

To Reproduce
Steps to reproduce the behavior:

  1. Run cargo build --release --package=examples --example=curl
  2. See error

Expected behavior
Curl example compiles without errors

Your environment

  • Repo version : Last version up to date (9ce7895)
  • Version of Rust : stable, rustc 1.73.0 (cc66ad468 2023-10-03)
  • OS and distribution : Debian bookworm

Additional context
N/A

crate documentation at docs.rs fails to build

Neither of the crates has a documentation available. This happens because docs.rs builds are performed in an isolated environment without network access and with limited filesystem access, therefore nginx-sys fails to fetch and build the dependencies.

Logs:

https://docs.rs/crate/ngx/0.4.1/builds/1026822

[INFO] running `Command { std: "docker" "create" "-v" "/home/cratesfyi/workspace-builder/builds/ngx-0.4.1/target:/opt/rustwide/target:rw,Z" "-v" "/home/cratesfyi/workspace-builder/builds/ngx-0.4.1/source:/opt/rustwide/workdir:ro,Z" "-v" "/home/cratesfyi/workspace-builder/cargo-home:/opt/rustwide/cargo-home:ro,Z" "-v" "/home/cratesfyi/workspace-builder/rustup-home:/opt/rustwide/rustup-home:ro,Z" "-e" "SOURCE_DIR=/opt/rustwide/workdir" "-e" "CARGO_TARGET_DIR=/opt/rustwide/target" "-e" "DOCS_RS=1" "-e" "CARGO_HOME=/opt/rustwide/cargo-home" "-e" "RUSTUP_HOME=/opt/rustwide/rustup-home" "-w" "/opt/rustwide/workdir" "-m" "6442450944" "--cpus" "6" "--user" "1001:1001" "--network" "none" "ghcr.io/rust-lang/crates-build-env/linux@sha256:2788e3201cd34a07e3172128adcd8b3090168a8e3bcc40d7c032b9dda1df7d1c" "/opt/rustwide/cargo-home/bin/cargo" "+nightly" "rustdoc" "--lib" "-Zrustdoc-map" "-Z" "unstable-options" "--config" "build.rustdocflags=[\"-Z\", \"unstable-options\", \"--emit=invocation-specific\", \"--resource-suffix\", \"-20231130-1.76.0-nightly-87e1447aa\", \"--static-root-path\", \"/-/rustdoc.static/\", \"--cap-lints\", \"warn\", \"--extern-html-root-takes-precedence\"]" "--offline" "-Zunstable-options" "--config=doc.extern-map.registries.crates-io=\"https://docs.rs/{pkg_name}/{version}/x86_64-unknown-linux-gnu\"" "-Zrustdoc-scrape-examples" "-j6" "--target" "x86_64-unknown-linux-gnu", kill_on_drop: false }`
[INFO] [stderr] WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
[INFO] [stdout] 4ff50542616c16f9e6936f68b5420444e406f0fc316bab0bf9567271ca7c6653
[INFO] running `Command { std: "docker" "start" "-a" "4ff50542616c16f9e6936f68b5420444e406f0fc316bab0bf9567271ca7c6653", kill_on_drop: false }`
[INFO] [stderr] warning: Target filter specified, but no targets matched. This is a no-op
[INFO] [stderr]    Compiling nginx-sys v0.2.1
[INFO] [stderr] error: failed to run custom build command for `nginx-sys v0.2.1`
[INFO] [stderr] 
[INFO] [stderr] Caused by:
[INFO] [stderr]   process didn't exit successfully: `/opt/rustwide/target/debug/build/nginx-sys-72198d03140dc169/build-script-build` (exit status: 1)
[INFO] [stderr]   --- stderr
[INFO] [stderr]   Error: Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" }
[INFO] running `Command { std: "docker" "inspect" "4ff50542616c16f9e6936f68b5420444e406f0fc316bab0bf9567271ca7c6653", kill_on_drop: false }`
[INFO] running `Command { std: "docker" "rm" "-f" "4ff50542616c16f9e6936f68b5420444e406f0fc316bab0bf9567271ca7c6653", kill_on_drop: false }`
[INFO] [stdout] 4ff50542616c16f9e6936f68b5420444e406f0fc316bab0bf9567271ca7c6653

The build environment already has most of the things we need, we'll only have to deliver the NGINX itself and make it build against the system libs.
A possible approach can be copied from the openssl crate: a new nginx-src crate that embeds a git submodule with the latest stable NGINX source.

publish as rust crate

This is blocker for release. This need to be done in order for other crates to use this.

Subrequest API requires data support and API updates.

Is your feature request related to a problem? Please describe.
During the development of a retry module gaps in the current subrequest API support were identified.

  • need getters for request status and subrequest depth
  • need to increment cycle count
  • the flags argument is not supported
  • the args argument is not supported
  • need to pass custom data to subrequest
  • do not automatically destroy subrequest body (allow caller to handle body lifetime)
  • suggested: provide a basic subrequest example module

Describe the solution you'd like
Add additional API support. This work has mostly been complete here but needs to be separated from the Event timer API work and linting updates. See the src/http/flags.rs and src/http/request.rs files for salient changes.

Additional context
Since this work is mostly completed by @avahahn and @f5yacobucci please see them for unclear details. This issue is a placeholder tracking issue to break apart an existing PR into its component features.

Examples on upstream/loadbalancer modules

Hey folks, thanks for this crate.

I'm looking into testing ngx-rust with ingress-nginx, to replace parts of the code that deals with upstream/balancer (today it uses openresty).

First of all, bare in mind I'm almost null in Rust.

While trying to follow the examples and some module development blogs (in C), I couldn't move forward to implement a LB module for it.

I'm a bit lost on where are the limits of C/bindings and Rust code, and was wondering if it is possible to get an example on a loadbalancer module to check where am I doing the mistakes.

Thank you!

Make lint fails with errors

Running make lint on the main branch generates errors.

Steps to reproduce the behavior:

  1. git clone [ngx-rust project]
  2. make lint

Expected behavior
Ideally, make lint should complete clean without warnings (-D warnings) or errors. But make lint (cargo clippy) must complete without errors.

Your environment

  • Version of the repo - 4aa2e35
  • Version of ngx-rust - 0.3.0-beta
  • Version of Rust - 1.71.0-nightly
  • Version of NGINX (and all dependencies if modified) - N/A
  • OS and distribution - Ubuntu 22.04.2 LTS
  • Details about containerization, virtualization, or physical environment - N/A

Additional context
Suggested tasks:

  • Propose lint (clippy.toml) configuration for consistency
  • Add git action to run lint appropriately (build / review)
  • Run strict checks (-D warnings)
  • Make main branch clean and free of error

Provide more logging macros

ngx-rust doesn't provide a full set of convenience macros for logging.

We support specific debug logging, but for other logging the user still needs to call the C FFI functions themselves. Needing to provide unnecessary arguments, e.g., in the upstream.rs module example:

ngx_conf_log_error(
            NGX_LOG_EMERG as usize,
            cf,
            0,
            "CUSTOM UPSTREAM no upstream srv_conf".as_bytes().as_ptr() as *const i8,
       );

This can be simplified with a corresponding macro like we do for ngx_log_debug!.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.