Skip to content

Commit 5b1b99a

Browse files
committed
Make: refactor dynamic module builds.
Define all the shared module targets in the main Makefile and allow build/*.mk files to add the correct dependencies.
1 parent 3b5459d commit 5b1b99a

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
MODULE = nginx_acme
2-
# build/build-%.mk: debug, debug-static, release, release-static, sanitize
1+
# NGINX module name (should match the exported symbol name).
2+
MODULE_NAME = ngx_http_acme_module
3+
# Target name used by cargo build.
4+
TARGET_NAME = nginx_acme
5+
6+
# build/build-%.mk: debug, debug-static, release, release-static, sanitize, ...
37
BUILD ?= debug
48
TESTS ?= t/
59
NGX_CARGO ?= cargo
@@ -20,6 +24,12 @@ NGINX_BUILD_DIR ?= $(CURDIR)/objs-$(BUILD)
2024
TEST_NGINX_BINARY = $(NGINX_BUILD_DIR)/nginx
2125
TEST_NGINX_GLOBALS += env RUST_BACKTRACE;
2226

27+
# Shared library generated with --add-dynamic-module=.
28+
NGINX_BUILT_MODULE = $(NGINX_BUILD_DIR)/$(MODULE_NAME).so
29+
# Shared libraries generated by cargo build.
30+
CARGO_DEBUG_MODULE = target/debug/lib$(TARGET_NAME)$(SHLIB_EXT)
31+
CARGO_RELEASE_MODULE = target/release/lib$(TARGET_NAME)$(SHLIB_EXT)
32+
2333
# "build" always calls cargo and causes relinking.
2434
# Clearing this var allows to skip the build step: "make test TEST_PREREQ="
2535
TEST_PREREQ = build
@@ -64,8 +74,7 @@ help:
6474
@echo "Pass NGINX_SOURCE_DIR to specify path to your NGINX source checkout."
6575

6676
# Always rebuild targets managed by external build tool
67-
.PHONY: target/debug/lib$(MODULE)$(NGX_MODEXT) \
68-
target/release/lib$(MODULE)$(NGX_MODEXT) \
77+
.PHONY: $(CARGO_DEBUG_MODULE) $(CARGO_RELEASE_MODULE) $(NGINX_BUILT_MODULE) \
6978
$(TEST_NGINX_BINARY)
7079

7180
$(NGINX_BUILD_DIR)/Makefile: config config.make auto/rust
@@ -81,12 +90,16 @@ $(NGINX_BUILD_DIR)/Makefile: $(NGINX_SOURCE_DIR)/src/core/nginx.h
8190

8291
$(TEST_NGINX_BINARY): $(NGINX_BUILD_DIR)/Makefile
8392
cd $(NGINX_SOURCE_DIR) \
84-
&& $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile
93+
&& $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile binary
94+
95+
$(NGINX_BUILT_MODULE): $(NGINX_BUILD_DIR)/Makefile
96+
cd $(NGINX_SOURCE_DIR) \
97+
&& $(BUILD_ENV) $(MAKE) -f $(NGINX_BUILD_DIR)/Makefile modules
8598

86-
target/debug/lib$(MODULE)$(NGX_MODEXT): $(NGINX_BUILD_DIR)/Makefile
99+
$(CARGO_DEBUG_MODULE): $(NGINX_BUILD_DIR)/Makefile
87100
$(BUILD_ENV) $(NGX_CARGO) build
88101

89-
target/release/lib$(MODULE)$(NGX_MODEXT): $(NGINX_BUILD_DIR)/Makefile
102+
$(CARGO_RELEASE_MODULE): $(NGINX_BUILD_DIR)/Makefile
90103
$(BUILD_ENV) $(NGX_CARGO) build --release
91104

92105
build: $(TEST_NGINX_BINARY) ## Build the module

build/build-aws-lc.mk

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# * we use libssl objects created by nginx, and thus have to link to the same
77
# library
8-
#
8+
#
99
# * linking static libssl.a to the nginx binary alone results in missing
1010
# symbols during module load
1111
#
@@ -24,6 +24,7 @@ BUILD_ENV += OPENSSL_LIB_DIR="$(LIBSSL_DESTDIR)/lib"
2424
BUILD_ENV += OPENSSL_STATIC=0
2525

2626
TEST_ENV += LD_LIBRARY_PATH="$(LIBSSL_DESTDIR)/lib"
27+
TEST_NGINX_GLOBALS += load_module $(NGINX_BUILT_MODULE);
2728

2829
NGINX_CONFIGURE = \
2930
$(NGINX_CONFIGURE_BASE) \
@@ -33,13 +34,7 @@ NGINX_CONFIGURE = \
3334
--add-dynamic-module="$(CURDIR)"
3435

3536

36-
NGX_MODULE = $(NGINX_BUILD_DIR)/ngx_http_acme_module.so
37-
TEST_NGINX_GLOBALS += load_module $(NGX_MODULE);
38-
39-
.PHONY: $(NGX_MODULE)
40-
41-
build: $(NGX_MODULE)
42-
37+
build: $(NGINX_BUILT_MODULE)
4338

4439
$(LIBSSL_BUILDDIR)/CMakeCache.txt: $(LIBSSL_SRCDIR)/CMakeLists.txt
4540
cmake -S $(LIBSSL_SRCDIR) \
@@ -50,8 +45,8 @@ $(LIBSSL_BUILDDIR)/CMakeCache.txt: $(LIBSSL_SRCDIR)/CMakeLists.txt
5045
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
5146
-DCMAKE_INSTALL_PREFIX:STRING=$(LIBSSL_DESTDIR)
5247

53-
$(LIBSSL_DESTDIR)/lib/libssl.so: $(LIBSSL_BUILDDIR)/CMakeCache.txt
48+
$(LIBSSL_DESTDIR)/lib/libssl$(SHLIB_EXT): $(LIBSSL_BUILDDIR)/CMakeCache.txt
5449
cmake --build $(LIBSSL_BUILDDIR)
5550
cmake --install $(LIBSSL_BUILDDIR)
5651

57-
$(NGINX_BUILD_DIR)/Makefile: $(LIBSSL_DESTDIR)/lib/libssl.so
52+
$(NGINX_BUILD_DIR)/Makefile: $(LIBSSL_DESTDIR)/lib/libssl$(SHLIB_EXT)

build/build-debug.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
NGX_MODULE = target/debug/lib$(MODULE)$(NGX_MODEXT)
2-
TEST_NGINX_GLOBALS += load_module $(CURDIR)/$(NGX_MODULE);
1+
TEST_NGINX_GLOBALS += load_module $(CURDIR)/$(CARGO_DEBUG_MODULE);
32

43
NGINX_CONFIGURE = \
54
$(NGINX_CONFIGURE_BASE) \
65
--with-debug \
76
--add-dynamic-module="$(CURDIR)"
87

9-
# always rebuild targets managed by external build tool
10-
.PHONY: $(NGX_MODULE)
11-
12-
build: $(NGX_MODULE)
8+
build: $(CARGO_DEBUG_MODULE) $(NGINX_BUILT_MODULE)

build/build-release.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
NGX_MODULE = target/release/lib$(MODULE)$(NGX_MODEXT)
2-
TEST_NGINX_GLOBALS += load_module $(CURDIR)/$(NGX_MODULE);
1+
TEST_NGINX_GLOBALS += load_module $(CURDIR)/$(CARGO_RELEASE_MODULE);
32

43
NGINX_CONFIGURE = \
54
$(NGINX_CONFIGURE_BASE) \
65
--add-dynamic-module="$(CURDIR)"
76

8-
# always rebuild targets managed by external build tool
9-
.PHONY: $(NGX_MODULE)
10-
11-
build: $(NGX_MODULE)
7+
build: $(CARGO_RELEASE_MODULE) $(NGINX_BUILT_MODULE)

build/compat-gnu.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ TEST_JOBS := $(shell nproc 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null |
33

44
# extension for Rust cdylib targets
55
ifeq ($(shell uname), Darwin)
6-
NGX_MODEXT = .dylib
6+
SHLIB_EXT = .dylib
77
else
8-
NGX_MODEXT = .so
8+
SHLIB_EXT = .so
99
endif
1010

1111
# resolve paths

build/compat-posix.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TEST_JOBS != nproc 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1
44
# bsd make compatibility
55
CURDIR ?= $(.CURDIR)
66
# extension for Rust cdylib targets
7-
NGX_MODEXT != if [ `uname` = Darwin ]; then echo ".dylib"; else echo ".so"; fi
7+
SHLIB_EXT != if [ `uname` = Darwin ]; then echo ".dylib"; else echo ".so"; fi
88

99
# resolve paths
1010

0 commit comments

Comments
 (0)