Skip to content

Commit 8aae700

Browse files
committed
fix(examples): nginx build integration with non-default builddir
The include paths we read from the Makefile are relative to the nginx source directory. Thus, it is preferable to run the cargo build command from the same path. Fixes build with `./configure --builddir=/tmp/nginx --add-module=...`
1 parent 6f2d4eb commit 8aae700

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

examples/config

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
ngx_addon_name=ngx_rust_examples
2-
ngx_cargo_profile=ngx-module
2+
3+
if [ "$NGX_DEBUG" = YES ]; then
4+
ngx_cargo_profile=dev
5+
ngx_cargo_profile_dir=debug
6+
else
7+
ngx_cargo_profile=release
8+
ngx_cargo_profile_dir=$ngx_cargo_profile
9+
fi
310

411
if [ $HTTP = YES ]; then
512
ngx_module_type=HTTP
@@ -8,7 +15,7 @@ if [ $HTTP = YES ]; then
815
ngx_module_name=ngx_http_async_module
916
ngx_module_lib=async
1017

11-
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
18+
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_module_lib.a
1219
ngx_module_deps=$ngx_module_lib
1320
ngx_module_libs="$ngx_module_lib -lm"
1421

@@ -22,7 +29,7 @@ if [ $HTTP = YES ]; then
2229
ngx_module_name=ngx_http_awssigv4_module
2330
ngx_module_lib=awssig
2431

25-
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
32+
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_module_lib.a
2633
ngx_module_deps=$ngx_module_lib
2734
ngx_module_libs="$ngx_module_lib -lm"
2835

@@ -36,7 +43,7 @@ if [ $HTTP = YES ]; then
3643
ngx_module_name=ngx_http_curl_module
3744
ngx_module_lib=curl
3845

39-
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
46+
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_module_lib.a
4047
ngx_module_deps=$ngx_module_lib
4148
ngx_module_libs=$ngx_module_lib
4249

@@ -51,7 +58,7 @@ if [ $HTTP = YES ]; then
5158
ngx_module_name=ngx_http_orig_dst_module
5259
ngx_module_lib=httporigdst
5360

54-
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
61+
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_module_lib.a
5562
ngx_module_deps=$ngx_module_lib
5663
ngx_module_libs=$ngx_module_lib
5764

@@ -66,7 +73,7 @@ if [ $HTTP = YES ]; then
6673
ngx_module_name=ngx_http_upstream_custom_module
6774
ngx_module_lib=upstream
6875

69-
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
76+
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_module_lib.a
7077
ngx_module_deps=$ngx_module_lib
7178
ngx_module_libs=$ngx_module_lib
7279

@@ -76,19 +83,3 @@ if [ $HTTP = YES ]; then
7683
. auto/module
7784
fi
7885
fi
79-
80-
# Write a cargo config with the $ngx_cargo_profile definition (optional)
81-
82-
if [ "$NGX_DEBUG" = YES ]; then
83-
NGX_CARGO_PROFILE_BASE=dev
84-
else
85-
NGX_CARGO_PROFILE_BASE=release
86-
fi
87-
88-
mkdir -p "$NGX_OBJS/.cargo"
89-
cat > "$NGX_OBJS/.cargo/config.toml" << END
90-
91-
[profile.$ngx_cargo_profile]
92-
inherits = "$NGX_CARGO_PROFILE_BASE"
93-
94-
END

examples/config.make

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ngx_addon_name=ngx_rust_examples
2-
ngx_cargo_profile=ngx-module
32
ngx_cargo_manifest=$(realpath $ngx_addon_dir/Cargo.toml)
43
ngx_cargo_features=
54
ngx_rust_examples="async awssig curl upstream"
@@ -11,23 +10,30 @@ case "$NGX_PLATFORM" in
1110
;;
1211
esac
1312

13+
if [ "$NGX_DEBUG" = YES ]; then
14+
ngx_cargo_profile=dev
15+
ngx_cargo_profile_dir=debug
16+
else
17+
ngx_cargo_profile=release
18+
ngx_cargo_profile_dir=$ngx_cargo_profile
19+
fi
20+
1421
for ngx_rust_example in $ngx_rust_examples
1522
do
1623

1724
cat << END >> $NGX_MAKEFILE
1825

1926
# Always call cargo instead of tracking the source modifications
20-
.PHONY: $NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_rust_example.a
27+
.PHONY: $NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_rust_example.a
2128

22-
$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_rust_example.a:
23-
cd $NGX_OBJS && \\
24-
NGX_OBJS="\$\$PWD" cargo rustc \\
29+
$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile_dir/examples/lib$ngx_rust_example.a:
30+
NGX_OBJS="\$\$NGX_OBJS" cargo rustc \\
2531
--crate-type staticlib \\
2632
--example "$ngx_rust_example" \\
2733
--no-default-features \\
2834
--features "$ngx_cargo_features" \\
2935
--profile $ngx_cargo_profile \\
30-
--target-dir $ngx_addon_name \\
36+
--target-dir $NGX_OBJS/$ngx_addon_name \\
3137
--manifest-path $ngx_cargo_manifest
3238

3339
END

0 commit comments

Comments
 (0)