67
67
#
68
68
# ngx_rust_make_modules
69
69
# ```
70
+ #
71
+ # The following environment variables can affect the generated Makefile:
72
+ #
73
+ # - NGX_CARGO sets the "cargo" binary to use, e.g. NGX_CARGO=cargo-1.82
74
+ # - NGX_RUST_TARGET passes the --target to the Rust compiler if set
75
+ # - NGX_RUSTC_OPT passes additional options to "cargo rustc"
70
76
71
77
# Prevent duplicate invocation unless it is a newer library version
72
78
if [ " ${NGX_RUST_AUTO_VER:- 0} " -ge 1 ]; then
@@ -136,7 +142,7 @@ case "$NGX_PLATFORM" in
136
142
RUST_LIBS=" $RUST_LIBS userenv.lib" # std::env::home_dir
137
143
RUST_LIBS=" $RUST_LIBS dbghelp.lib" # backtrace symbolization
138
144
139
- RUST_TARGET= $ RUST_TARGET_ARCH -pc-windows-msvc
145
+ NGX_RUST_TARGET= ${NGX_RUST_TARGET :- $ RUST_TARGET_ARCH -pc-windows-msvc}
140
146
;;
141
147
142
148
gcc | clang)
@@ -145,7 +151,7 @@ case "$NGX_PLATFORM" in
145
151
RUST_LIBS=" $RUST_LIBS -luserenv"
146
152
RUST_LIBS=" $RUST_LIBS -ldbghelp"
147
153
# gnullvm on arm64?
148
- RUST_TARGET= $ RUST_TARGET_ARCH -pc-windows-gnu
154
+ NGX_RUST_TARGET= ${NGX_RUST_TARGET :- $ RUST_TARGET_ARCH -pc-windows-gnu}
149
155
;;
150
156
151
157
esac
@@ -220,7 +226,7 @@ ngx_rust_target_path () {
220
226
ngx_rust_obj=examples/$ngx_rust_obj
221
227
fi
222
228
223
- echo " ${RUST_TARGET : +$RUST_TARGET / } $ngx_cargo_profile /$ngx_rust_obj "
229
+ echo " ${NGX_RUST_TARGET : +$NGX_RUST_TARGET / } $ngx_cargo_profile /$ngx_rust_obj "
224
230
}
225
231
226
232
@@ -244,21 +250,30 @@ ngx_rust_module () {
244
250
ngx_module_libs_saved=$ngx_module_libs
245
251
ngx_module_libs=" $ngx_rust_obj $ngx_module_libs $RUST_LIBS "
246
252
247
- # Module deps are usually added to the object file targets, but we don't have any
248
- LINK_DEPS=" $LINK_DEPS $ngx_rust_obj "
249
-
250
- eval ${ngx_addon_id} _RUST_TARGETS=\"\$ ${ngx_addon_id} _RUST_TARGETS \
251
- $ngx_rust_target_type :$ngx_rust_target_name \"
252
-
253
253
if [ -n " $ngx_rust_target_features " ]; then
254
254
eval ${ngx_addon_id} _RUST_FEATURES=\"\$ ${ngx_addon_id} _RUST_FEATURES \
255
255
$ngx_rust_target_features \"
256
256
fi
257
257
258
- . auto/module
258
+ . auto/module
259
+
260
+ ngx_rust_target=$ngx_rust_target_type :$ngx_rust_target_name
261
+
262
+ # module deps are usually added to the object file targets, but we don't have any
263
+
264
+ if [ " $ngx_module_link " = DYNAMIC ]; then
265
+ # remember the dynamic module name and generate dependency later
266
+ ngx_rust_target=$ngx_rust_target :$ngx_module
267
+ else
268
+ # add dependency to the binary target
269
+ LINK_DEPS=" $LINK_DEPS $ngx_rust_obj "
270
+ fi
271
+
272
+ eval ${ngx_addon_id} _RUST_TARGETS=\"\$ ${ngx_addon_id} _RUST_TARGETS \
273
+ $ngx_rust_target \"
259
274
260
- ngx_module_deps=$ngx_module_deps_saved
261
- ngx_module_libs=$ngx_module_libs_saved
275
+ ngx_module_deps=$ngx_module_deps_saved
276
+ ngx_module_libs=$ngx_module_libs_saved
262
277
}
263
278
264
279
@@ -272,8 +287,9 @@ ngx_rust_make_modules () {
272
287
eval ngx_rust_targets=" \$ ${ngx_addon_id} _RUST_TARGETS"
273
288
274
289
for target in $ngx_rust_targets ; do
275
- ngx_rust_target_type=${target%%:* }
276
- ngx_rust_target_name=${target#*: }
290
+ IFS=' :' read -r ngx_rust_target_type ngx_rust_target_name ngx_rust_module_name << END
291
+ $target
292
+ END
277
293
278
294
ngx_rust_make_module
279
295
done
@@ -304,10 +320,20 @@ $ngx_rust_obj:
304
320
--manifest-path "$ngx_cargo_manifest " \\
305
321
--no-default-features \\
306
322
--profile $ngx_cargo_profile \\
307
- ${RUST_TARGET : +--target $RUST_TARGET } \\
323
+ ${NGX_RUST_TARGET : +--target $NGX_RUST_TARGET } \\
308
324
--target-dir $NGX_OBJS /$ngx_addon_id \\
309
325
--features "$ngx_rust_features " \\
310
326
$ngx_rustc_module_opt $NGX_RUSTC_OPT
311
327
312
328
END
329
+
330
+ # Ensure that the "auto"-generated dynamic module target depends on the
331
+ # static library. Normally this is achieved by attaching ADDON_DEPS to
332
+ # the module object files, but we don't have any suitable C sources.
333
+
334
+ if [ -n " $ngx_rust_module_name " ]; then
335
+ cat << END >> $NGX_MAKEFILE
336
+ $NGX_OBJS$ngx_dirsep$ngx_rust_module_name$ngx_modext : $ngx_rust_obj
337
+ END
338
+ fi
313
339
}
0 commit comments