Complies C code natively and links it to NGINX Unit's libunit.a
so you can register your native C app.
Inspired by the article NGINX Unit Adds Assembly Language Support.
- Add required Unit header files to your C code. i.e.
#include "nxt_clang.h"
#include "nxt_unit.h"
#include "nxt_unit_request.h"
#include "nxt_unit_typedefs.h"
Unit source files will be included in the docker image, so you don't need local copies.
- Put your app source files in the
src/
directory. - Rename your maic C file to
main.c
; or change the expected file name in theDockerfile
. - Build the docker image:
docker build -t nunit:latest .
- Run the docker container:
docker run --rm -p 8081:8081 nunit:latest
- See your app running at
localhost:8081
!
Compiling libunit.a
requires the Unit source code, see https://unit.nginx.org/installation/
- Run
UNIT_SRC=/path/to/unit make prepare
to create libunit.a
and copy over the necessary header to include/
-
Run
make
-
Run your app
./app
- Run
UNIT_SRC=/path/to/unit make sample
- Run
./sample
or build the docker image:
docker build -t nunit:sample -f Dockerfile.sample .