From a1cb07215010375df7ccf3abaea473e0027f7ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:13:54 +0800 Subject: [PATCH 1/2] flags: constrain LTO flag inheritance to be `clang`-only --- src/flags.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/flags.rs b/src/flags.rs index 96049a42..efbb09f6 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -209,17 +209,6 @@ impl<'this> RustcCodegenFlags<'this> { push_if_supported(format!("-mguard={cc_val}").into()); } } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-flto - if let Some(value) = self.lto { - let cc_val = match value { - "y" | "yes" | "on" | "true" | "fat" => Some("full"), - "thin" => Some("thin"), - _ => None, - }; - if let Some(cc_val) = cc_val { - push_if_supported(format!("-flto={cc_val}").into()); - } - } // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIC // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fPIE // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mdynamic-no-pic @@ -285,6 +274,18 @@ impl<'this> RustcCodegenFlags<'this> { if let Some(value) = self.profile_use { push_if_supported(format!("-fprofile-use={value}").into()); } + + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-flto + if let Some(value) = self.lto { + let cc_val = match value { + "y" | "yes" | "on" | "true" | "fat" => Some("full"), + "thin" => Some("thin"), + _ => None, + }; + if let Some(cc_val) = cc_val { + push_if_supported(format!("-flto={cc_val}").into()); + } + } } ToolFamily::Gnu { .. } => {} ToolFamily::Msvc { .. } => { From 1342d8f6c25365c0c7c142a1351d449d95c0cb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:23:30 +0800 Subject: [PATCH 2/2] flags: constrain `embed-bitcode` flag inheritance to be `clang`-only --- src/flags.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/flags.rs b/src/flags.rs index efbb09f6..93391633 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -223,11 +223,6 @@ impl<'this> RustcCodegenFlags<'this> { push_if_supported(cc_flag.into()); } } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fembed-bitcode - if let Some(value) = self.embed_bitcode { - let cc_val = if value { "all" } else { "off" }; - push_if_supported(format!("-fembed-bitcode={cc_val}").into()); - } // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-omit-frame-pointer // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fomit-frame-pointer if let Some(value) = self.force_frame_pointers { @@ -275,6 +270,12 @@ impl<'this> RustcCodegenFlags<'this> { push_if_supported(format!("-fprofile-use={value}").into()); } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fembed-bitcode + if let Some(value) = self.embed_bitcode { + let cc_val = if value { "all" } else { "off" }; + push_if_supported(format!("-fembed-bitcode={cc_val}").into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-flto if let Some(value) = self.lto { let cc_val = match value {