diff --git a/CHANGELOG.md b/CHANGELOG.md index dd03b001a..dbc07f939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.2.9](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.8...cc-v1.2.9) - 2025-01-12 + +### Other + +- Don't pass inherited PGO flags to GNU compilers (#1363) +- Adjusted zig cc judgment and avoided zigbuild errors([#1360](https://github.com/rust-lang/cc-rs/pull/1360)) ([#1361](https://github.com/rust-lang/cc-rs/pull/1361)) +- Fix compilation on macOS using clang and fix compilation using zig-cc ([#1364](https://github.com/rust-lang/cc-rs/pull/1364)) + ## [1.2.8](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.7...cc-v1.2.8) - 2025-01-11 ### Other diff --git a/Cargo.toml b/Cargo.toml index 3b932ba19..289fa9066 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cc" -version = "1.2.8" +version = "1.2.9" authors = ["Alex Crichton "] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/cc-rs" diff --git a/src/flags.rs b/src/flags.rs index 8b0d7563f..6bd8d72d7 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -174,26 +174,109 @@ impl<'this> RustcCodegenFlags<'this> { } }; - match family { - ToolFamily::Clang { .. } | ToolFamily::Gnu => { - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mbranch-protection - if let Some(value) = self.branch_protection { - push_if_supported( - format!("-mbranch-protection={}", value.replace(",", "+")).into(), - ); - } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mcmodel - if let Some(value) = self.code_model { - push_if_supported(format!("-mcmodel={value}").into()); + let clang_or_gnu = + matches!(family, ToolFamily::Clang { .. }) || matches!(family, ToolFamily::Gnu { .. }); + + // Flags shared between clang and gnu + if clang_or_gnu { + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mbranch-protection + if let Some(value) = self.branch_protection { + push_if_supported( + format!("-mbranch-protection={}", value.replace(",", "+")).into(), + ); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mcmodel + if let Some(value) = self.code_model { + push_if_supported(format!("-mcmodel={value}").into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-vectorize + if self.no_vectorize_loops { + push_if_supported("-fno-vectorize".into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-slp-vectorize + if self.no_vectorize_slp { + push_if_supported("-fno-slp-vectorize".into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mguard + if let Some(value) = self.control_flow_guard { + let cc_val = match value { + "y" | "yes" | "on" | "true" | "checks" => Some("cf"), + "nochecks" => Some("cf-nochecks"), + "n" | "no" | "off" | "false" => Some("none"), + _ => None, + }; + if let Some(cc_val) = cc_val { + push_if_supported(format!("-mguard={cc_val}").into()); } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fno-vectorize - if self.no_vectorize_loops { - push_if_supported("-fno-vectorize".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-fno-slp-vectorize - if self.no_vectorize_slp { - push_if_supported("-fno-slp-vectorize".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 + if let Some(value) = self.relocation_model { + let cc_flag = match value { + "pic" => Some("-fPIC"), + "pie" => Some("-fPIE"), + "dynamic-no-pic" => Some("-mdynamic-no-pic"), + _ => None, + }; + if let Some(cc_flag) = cc_flag { + 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 { + let cc_flag = if value { + "-fno-omit-frame-pointer" + } else { + "-fomit-frame-pointer" + }; + push_if_supported(cc_flag.into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-dead_strip + if let Some(false) = self.link_dead_code { + push_if_supported("-dead_strip".into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-red-zone + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mred-zone + if let Some(value) = self.no_redzone { + let cc_flag = if value { "-mno-red-zone" } else { "-mred-zone" }; + push_if_supported(cc_flag.into()); + } + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-msoft-float + // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-soft-float + if let Some(value) = self.soft_float { + let cc_flag = if value { + "-msoft-float" + } else { + "-mno-soft-float" + }; + push_if_supported(cc_flag.into()); + } + } + + // Compiler-exclusive flags + match family { + ToolFamily::Clang { .. } => { + // GNU and Clang compilers both support the same PGO flags, but they use different libraries and + // different formats for the profile files which are not compatible. + // clang and rustc both internally use llvm, so we want to inherit the PGO flags only for clang. // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fprofile-generate if let Some(value) = self.profile_generate { push_if_supported(format!("-fprofile-generate={value}").into()); @@ -202,79 +285,8 @@ 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-mguard - if let Some(value) = self.control_flow_guard { - let cc_val = match value { - "y" | "yes" | "on" | "true" | "checks" => Some("cf"), - "nochecks" => Some("cf-nochecks"), - "n" | "no" | "off" | "false" => Some("none"), - _ => None, - }; - if let Some(cc_val) = cc_val { - 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 - if let Some(value) = self.relocation_model { - let cc_flag = match value { - "pic" => Some("-fPIC"), - "pie" => Some("-fPIE"), - "dynamic-no-pic" => Some("-mdynamic-no-pic"), - _ => None, - }; - if let Some(cc_flag) = cc_flag { - 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 { - let cc_flag = if value { - "-fno-omit-frame-pointer" - } else { - "-fomit-frame-pointer" - }; - push_if_supported(cc_flag.into()); - } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-dead_strip - if let Some(false) = self.link_dead_code { - push_if_supported("-dead_strip".into()); - } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-red-zone - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mred-zone - if let Some(value) = self.no_redzone { - let cc_flag = if value { "-mno-red-zone" } else { "-mred-zone" }; - push_if_supported(cc_flag.into()); - } - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-msoft-float - // https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mno-soft-float - if let Some(value) = self.soft_float { - let cc_flag = if value { - "-msoft-float" - } else { - "-mno-soft-float" - }; - push_if_supported(cc_flag.into()); - } } + ToolFamily::Gnu { .. } => {} ToolFamily::Msvc { .. } => { // https://learn.microsoft.com/en-us/cpp/build/reference/guard-enable-control-flow-guard if let Some(value) = self.control_flow_guard { diff --git a/src/tool.rs b/src/tool.rs index af43a918e..4233d5915 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -103,6 +103,12 @@ impl Tool { ) .map(|o| String::from_utf8_lossy(&o).contains("ziglang")) .unwrap_or_default() + || { + match path.file_name().map(OsStr::to_string_lossy) { + Some(fname) => fname.contains("zig"), + _ => false, + } + } } fn guess_family_from_stdout( @@ -428,10 +434,8 @@ impl Tool { /// Supports using `--` delimiter to separate arguments and path to source files. pub(crate) fn supports_path_delimiter(&self) -> bool { - matches!( - self.family, - ToolFamily::Clang { .. } | ToolFamily::Msvc { clang_cl: true } - ) && !self.cuda + // homebrew clang and zig-cc does not support this while stock version does + matches!(self.family, ToolFamily::Msvc { clang_cl: true }) && !self.cuda } } diff --git a/tests/test.rs b/tests/test.rs index 84d3e005f..b88a81904 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -405,8 +405,6 @@ fn gnu_static() { } #[test] -// on macOS, cc/gcc is link to apple clang -#[cfg_attr(target_os = "macos", ignore)] fn gnu_no_dash_dash() { let test = Test::gnu(); test.gcc().file("foo.c").compile("foo");