Skip to content

Commit 25c72b0

Browse files
jackorpXrXr
andcommitted
Support customizable rustc_flags for rustc builds.
Add `rustc_flags` option for configure that appends to RUSTC_FLAGS flags used when compiling with rustc for customizable build flags. It appends to existing defaults in RUSTC_FLAGS. Co-authored-by: Alan Wu <[email protected]>
1 parent 1abb609 commit 25c72b0

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

common.mk

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,15 @@ MAKE_LINK = $(MINIRUBY) -rfileutils -e "include FileUtils::Verbose" \
269269
# For release builds
270270
YJIT_RUSTC_ARGS = --crate-name=yjit \
271271
$(JIT_RUST_FLAGS) \
272+
$(RUSTC_FLAGS) \
272273
--edition=2021 \
273-
-g \
274-
-C lto=thin \
275-
-C opt-level=3 \
276-
-C overflow-checks=on \
277274
'--out-dir=$(CARGO_TARGET_DIR)/release/' \
278275
'$(top_srcdir)/yjit/src/lib.rs'
279276

280277
ZJIT_RUSTC_ARGS = --crate-name=zjit \
281278
$(JIT_RUST_FLAGS) \
279+
$(RUSTC_FLAGS) \
282280
--edition=2024 \
283-
-g \
284-
-C lto=thin \
285-
-C opt-level=3 \
286-
-C overflow-checks=on \
287281
'--out-dir=$(CARGO_TARGET_DIR)/release/' \
288282
'$(top_srcdir)/zjit/src/lib.rs'
289283

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ dnl 93(bright yellow) is copied from .github/workflows/mingw.yml
6969
AC_ARG_VAR([cflags], [additional CFLAGS (ignored when CFLAGS is given)])dnl
7070
AC_ARG_VAR([cppflags], [additional CPPFLAGS (ignored when CPPFLAGS is given)])dnl
7171
AC_ARG_VAR([cxxflags], [additional CXXFLAGS (ignored when CXXFLAGS is given)])dnl
72+
AC_ARG_VAR([rustc_flags], [additional RUSTC_FLAGS])dnl
7273

7374
[begin]_group "environment section" && {
7475
HAVE_BASERUBY=yes
@@ -4049,6 +4050,11 @@ AS_CASE(["${ZJIT_SUPPORT}"],
40494050
AC_DEFINE(USE_ZJIT, 0)
40504051
])
40514052

4053+
RUSTC_FLAGS='-g -C lto=thin -C opt-level=3 -C overflow-checks=on'
4054+
AS_IF([test -n "${rustc_flags}"], [
4055+
RUSTC_FLAGS="${RUSTC_FLAGS} ${rustc_flags}"
4056+
])
4057+
40524058
JIT_RUST_FLAGS='--crate-type=staticlib --cfg feature=\"stats_allocator\"'
40534059
RLIB_DIR=
40544060
AS_CASE(["$JIT_CARGO_SUPPORT:$YJIT_SUPPORT:$ZJIT_SUPPORT"],
@@ -4106,6 +4112,7 @@ AS_IF([test -n "$RUST_LIB"], [
41064112
dnl These variables end up in ::RbConfig::CONFIG
41074113
AC_SUBST(RUSTC)dnl Rust compiler command
41084114
AC_SUBST(JIT_RUST_FLAGS)dnl the common rustc flags for JIT crates such as zjit
4115+
AC_SUBST(RUSTC_FLAGS)dnl user-configurable rustc compiler flags
41094116
AC_SUBST(CARGO)dnl Cargo command for Rust builds
41104117
AC_SUBST(CARGO_BUILD_ARGS)dnl for selecting Rust build profiles
41114118
AC_SUBST(YJIT_SUPPORT)dnl what flavor of YJIT the Ruby build includes
@@ -4838,6 +4845,7 @@ config_summary "strip command" "$STRIP"
48384845
config_summary "install doc" "$DOCTARGETS"
48394846
config_summary "YJIT support" "$YJIT_SUPPORT"
48404847
config_summary "ZJIT support" "$ZJIT_SUPPORT"
4848+
config_summary "RUSTC_FLAGS" "$RUSTC_FLAGS"
48414849
config_summary "man page type" "$MANTYPE"
48424850
config_summary "search path" "$search_path"
48434851
config_summary "static-linked-ext" ${EXTSTATIC:+"yes"}

defs/jit.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ else ifneq ($(strip $(RLIB_DIR)),) # combo build
4040
$(RUST_LIB): $(srcdir)/ruby.rs
4141
$(ECHO) 'building $(@F)'
4242
$(gnumake_recursive)$(Q) $(RUSTC) --edition=2024 \
43+
$(RUSTC_FLAGS) \
4344
'-L$(@D)' \
4445
--extern=yjit \
4546
--extern=zjit \
@@ -58,6 +59,7 @@ $(JIT_RLIB):
5859
$(gnumake_recursive)$(Q) $(RUSTC) --crate-name=jit \
5960
--edition=2024 \
6061
$(JIT_RUST_FLAGS) \
62+
$(RUSTC_FLAGS) \
6163
'--out-dir=$(@D)' \
6264
'$(top_srcdir)/jit/src/lib.rs'
6365
endif # ifneq ($(JIT_CARGO_SUPPORT),no)

template/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ CARGO_TARGET_DIR=@abs_top_builddir@/target
115115
CARGO_BUILD_ARGS=@CARGO_BUILD_ARGS@
116116
ZJIT_TEST_FEATURES=@ZJIT_TEST_FEATURES@
117117
JIT_RUST_FLAGS=@JIT_RUST_FLAGS@
118+
RUSTC_FLAGS=@RUSTC_FLAGS@
118119
RLIB_DIR=@RLIB_DIR@
119120
RUST_LIB=@RUST_LIB@
120121
RUST_LIBOBJ = $(RUST_LIB:.a=.@OBJEXT@)

0 commit comments

Comments
 (0)