]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Set Rust LTO mode automatically, and allow setting RUSTFLAGS, rec edition 17659/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 30 Jun 2026 13:57:54 +0000 (15:57 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 30 Jun 2026 13:58:38 +0000 (15:58 +0200)
Copied from #17639

Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/meson_options.txt
pdns/recursordist/rec-rust-lib/rust/build_recrust
pdns/recursordist/rec-rust-lib/rust/meson.build

index d68545c0913d3eefb88bccd68145b542f50325e0..0d249277a5939be1a648debed47ff62805aaaef1 100644 (file)
@@ -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')
index 5e9bc5db5288004b30e4011b7fa575be4a492a29..ab42265616db63a5b4aa576c146a3fa8c8caf276 100755 (executable)
@@ -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
index 57f386218e725911914b67cbcfdd80ba4e55dee3..e4884f21a8739a4bf24b4b18acb1e146ccf6057e 100644 (file)
@@ -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,