From: Otto Moerbeek Date: Tue, 30 Jun 2026 13:57:54 +0000 (+0200) Subject: rec: Set Rust LTO mode automatically, and allow setting RUSTFLAGS, rec edition X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5bda62d1aeb3a0b659ee507404dcc53ce8bfcf3e;p=thirdparty%2Fpdns.git rec: Set Rust LTO mode automatically, and allow setting RUSTFLAGS, rec edition Copied from #17639 Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/meson_options.txt b/pdns/recursordist/meson_options.txt index d68545c091..0d249277a5 100644 --- a/pdns/recursordist/meson_options.txt +++ b/pdns/recursordist/meson_options.txt @@ -26,3 +26,5 @@ option('libcap', type: 'feature', value: 'auto', description: 'Enable libcap for option('clang-coverage-format', type: 'boolean', value: false, description: 'Whether to generate coverage data in clang format') option('tls-gnutls', type: 'feature', value: 'auto', description: 'GnuTLS-based TLS') option('man-pages', type: 'boolean', value: true, description: 'Generate man pages') +option('rust-args', type: 'string', description: 'Rust compile arguments to use') +option('rust-lto', type: 'boolean', value: true, description: 'Enable LTO for Rust according to b_lto, b_lto_mode settings') diff --git a/pdns/recursordist/rec-rust-lib/rust/build_recrust b/pdns/recursordist/rec-rust-lib/rust/build_recrust index 5e9bc5db52..ab42265616 100755 --- a/pdns/recursordist/rec-rust-lib/rust/build_recrust +++ b/pdns/recursordist/rec-rust-lib/rust/build_recrust @@ -11,15 +11,26 @@ export CARGO="${CARGO:-$_defaultCARGO}" mytarget=${CARGO_TARGET_DIR-target} #echo "mytarget=${mytarget}" -CARGO_PROFILE="--release" +CARGO_PROFILE="release" if [ -n "${CARGO_USE_DEV}" ]; then - CARGO_PROFILE="" + CARGO_PROFILE="dev" if [ -n "${CARGO_USE_CLIPPY}" ]; then $CARGO clippy --manifest-path $srcdir/Cargo.toml fi fi -$CARGO build ${CARGO_PROFILE} $RUST_TARGET --target-dir=$builddir/target --manifest-path $srcdir/Cargo.toml $features +case "${CARGO_LTO_MODE:-unspecified}" in + "fat" | "thin") + CARGO_CONFIG="--config profile.${CARGO_PROFILE}.lto=\"${CARGO_LTO_MODE}\"" + ;; +esac + +# echo "RUSTFLAGS = ${RUSTFLAGS}" +# echo "CARGO_PROFILE = ${CARGO_PROFILE}" +# echo "CARGO_LTO_MODE = ${CARGO_LTO_MODE}" +# echo "CARGO_CONFIG = ${CARGO_CONFIG}" + +$CARGO build --profile ${CARGO_PROFILE} ${CARGO_CONFIG} $RUST_TARGET --target-dir=$builddir/target --manifest-path $srcdir/Cargo.toml --locked $features if [ -n "${CARGO_USE_DEV}" ]; then cp -p target/$RUSTC_TARGET_ARCH/debug/librecrust.a $builddir/rec-rust-lib/rust/librecrust.a diff --git a/pdns/recursordist/rec-rust-lib/rust/meson.build b/pdns/recursordist/rec-rust-lib/rust/meson.build index 57f386218e..e4884f21a8 100644 --- a/pdns/recursordist/rec-rust-lib/rust/meson.build +++ b/pdns/recursordist/rec-rust-lib/rust/meson.build @@ -20,6 +20,23 @@ if cargo.version().version_compare('>=1.88') env.set('features', '--features pkcs12') endif +opt_rust_args = get_option('rust-args') +if opt_rust_args != '' + env.set('RUSTFLAGS', opt_rust_args) +endif + +if get_option('rust-lto') and get_option('b_lto') and get_option('b_lto_mode') == 'default' + env.set('CARGO_LTO_MODE', 'fat') + summary('LTO', true, bool_yn: true, section: 'Rust') + summary('LTO mode', 'fat', section: 'Rust') +elif get_option('rust-lto') and get_option('b_lto') and get_option('b_lto_mode') == 'thin' + env.set('CARGO_LTO_MODE', 'thin') + summary('LTO', true, bool_yn: true, section: 'Rust') + summary('LTO mode', 'thin', section: 'Rust') +else + summary('LTO', false, bool_yn: true, section: 'Rust') +endif + lib_recrust = custom_target('librecrust.a', output: [outfile, 'cxx.h', 'lib.rs.h', 'misc.rs.h', 'web.rs.h'], input: infile,