diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 22f5cb4056f96..b0c312c24a86c 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -68,6 +68,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a gcc_formula = gcc_version_formula(cc) append_path "PATH", gcc_formula.opt_bin.to_s end + alias generic_setup_build_environment setup_build_environment sig { returns(T.nilable(PATH)) } def determine_pkg_config_libdir diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 812ae68bfddb6..89f7ecfa5e654 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -119,6 +119,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a # These flags will also be present: # a - apply fix for apr-1-config path end + alias generic_setup_build_environment setup_build_environment private diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb index 8a249311b83f6..ba2fa12309d4a 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb @@ -1,45 +1,36 @@ # typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true -module OS - module Linux - module Stdenv - extend T::Helpers - - requires_ancestor { ::Stdenv } - - sig { - params( - formula: T.nilable(Formula), - cc: T.nilable(String), - build_bottle: T.nilable(T::Boolean), - bottle_arch: T.nilable(String), - testing_formula: T::Boolean, - debug_symbols: T.nilable(T::Boolean), - ).void - } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, - testing_formula: false, debug_symbols: false) - super - - prepend_path "CPATH", HOMEBREW_PREFIX/"include" - prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" - prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib" - - return unless @formula - - prepend_path "CPATH", @formula.include - prepend_path "LIBRARY_PATH", @formula.lib - prepend_path "LD_RUN_PATH", @formula.lib - end +module Stdenv + sig { + params( + formula: T.nilable(Formula), + cc: T.nilable(String), + build_bottle: T.nilable(T::Boolean), + bottle_arch: T.nilable(String), + testing_formula: T::Boolean, + debug_symbols: T.nilable(T::Boolean), + ).void + } + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, + debug_symbols: false) + generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, + testing_formula:, debug_symbols:) + + prepend_path "CPATH", HOMEBREW_PREFIX/"include" + prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" + prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib" + + return unless @formula + + prepend_path "CPATH", @formula.include + prepend_path "LIBRARY_PATH", @formula.lib + prepend_path "LD_RUN_PATH", @formula.lib + end - def libxml2 - append "CPPFLAGS", "-I#{::Formula["libxml2"].include/"libxml2"}" - rescue FormulaUnavailableError - nil - end - end + def libxml2 + append "CPPFLAGS", "-I#{Formula["libxml2"].include/"libxml2"}" + rescue FormulaUnavailableError + nil end end - -Stdenv.prepend(OS::Linux::Stdenv) diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 6bc4da2d051bb..f0aa87920edad 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -1,82 +1,73 @@ # typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true -module OS - module Linux - module Superenv - extend T::Helpers - - requires_ancestor { ::Superenv } - - sig { returns(Pathname) } - def self.shims_path - HOMEBREW_SHIMS_PATH/"linux/super" - end +module Superenv + sig { returns(Pathname) } + def self.shims_path + HOMEBREW_SHIMS_PATH/"linux/super" + end - sig { returns(T.nilable(Pathname)) } - def self.bin - shims_path.realpath - end + sig { returns(T.nilable(Pathname)) } + def self.bin + shims_path.realpath + end - sig { - params( - formula: T.nilable(Formula), - cc: T.nilable(String), - build_bottle: T.nilable(T::Boolean), - bottle_arch: T.nilable(String), - testing_formula: T::Boolean, - debug_symbols: T.nilable(T::Boolean), - ).void - } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, - testing_formula: false, debug_symbols: false) - super - self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" - self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path - self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) - self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" || d.name == "bison" } - end + sig { + params( + formula: T.nilable(Formula), + cc: T.nilable(String), + build_bottle: T.nilable(T::Boolean), + bottle_arch: T.nilable(String), + testing_formula: T::Boolean, + debug_symbols: T.nilable(T::Boolean), + ).void + } + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, + debug_symbols: false) + generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, + testing_formula:, debug_symbols:) + self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" + self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path + self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) + self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" || d.name == "bison" } + end - def homebrew_extra_paths - paths = generic_homebrew_extra_paths - paths += %w[binutils make].filter_map do |f| - bin = Formulary.factory(f).opt_bin - bin if bin.directory? - rescue FormulaUnavailableError - nil - end - paths - end + def homebrew_extra_paths + paths = generic_homebrew_extra_paths + paths += %w[binutils make].filter_map do |f| + bin = Formulary.factory(f).opt_bin + bin if bin.directory? + rescue FormulaUnavailableError + nil + end + paths + end - def homebrew_extra_isystem_paths - paths = [] - # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. - if deps.any? { |d| d.name == "glibc@2.13" } - gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp - gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp - paths << gcc_include_dir << gcc_include_fixed_dir - end - paths - end + def homebrew_extra_isystem_paths + paths = [] + # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. + if deps.any? { |d| d.name == "glibc@2.13" } + gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp + gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp + paths << gcc_include_dir << gcc_include_fixed_dir + end + paths + end - def determine_rpath_paths(formula) - PATH.new( - *formula&.lib, - "#{HOMEBREW_PREFIX}/opt/gcc/lib/gcc/current", - PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing, - "#{HOMEBREW_PREFIX}/lib", - ) - end + def determine_rpath_paths(formula) + PATH.new( + *formula&.lib, + "#{HOMEBREW_PREFIX}/opt/gcc/lib/gcc/current", + PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing, + "#{HOMEBREW_PREFIX}/lib", + ) + end - sig { returns(T.nilable(String)) } - def determine_dynamic_linker_path - path = "#{HOMEBREW_PREFIX}/lib/ld.so" - return unless File.readable? path + sig { returns(T.nilable(String)) } + def determine_dynamic_linker_path + path = "#{HOMEBREW_PREFIX}/lib/ld.so" + return unless File.readable? path - path - end - end + path end end - -Superenv.prepend(OS::Linux::Superenv) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index 90f3dedacc725..c312eb1125234 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -1,124 +1,117 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -module OS - module Mac - module Stdenv - extend T::Helpers - - requires_ancestor { ::Stdenv } - - sig { returns(T::Array[Pathname]) } - def homebrew_extra_pkg_config_paths - [Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")] - end - private :homebrew_extra_pkg_config_paths - - sig { - params( - formula: T.nilable(::Formula), - cc: T.nilable(String), - build_bottle: T.nilable(T::Boolean), - bottle_arch: T.nilable(String), - testing_formula: T::Boolean, - debug_symbols: T.nilable(T::Boolean), - ).void - } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, - testing_formula: false, debug_symbols: false) - super - - append "LDFLAGS", "-Wl,-headerpad_max_install_names" - - # `sed` is strict and errors out when it encounters files with mixed character sets. - delete("LC_ALL") - self["LC_CTYPE"] = "C" - - # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags: - macosxsdk(formula: @formula, testing_formula:) - - return unless MacOS::Xcode.without_clt? - - append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin" - append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin" - end - - def remove_macosxsdk(version = nil) - # Clear all `lib` and `include` dirs from `CFLAGS`, `CPPFLAGS`, `LDFLAGS` that were - # previously added by `macosxsdk`. - remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/) - delete("CPATH") - remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" - - sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed(version) - return unless sdk - - delete("SDKROOT") - remove_from_cflags "-isysroot#{sdk}" - remove "CPPFLAGS", "-isysroot#{sdk}" - remove "LDFLAGS", "-isysroot#{sdk}" - if HOMEBREW_PREFIX.to_s == "/usr/local" - delete("CMAKE_PREFIX_PATH") - else - # It was set in `setup_build_environment`, so we have to restore it here. - self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s - end - remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" - end - - def macosxsdk(version = nil, formula: nil, testing_formula: false) - # Sets all needed `lib` and `include` dirs to `CFLAGS`, `CPPFLAGS`, `LDFLAGS`. - remove_macosxsdk - min_version = version || MacOS.version - append_to_cflags("-mmacosx-version-min=#{min_version}") - self["CPATH"] = "#{HOMEBREW_PREFIX}/include" - prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" - - sdk = if formula - MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula) - else - MacOS.sdk(version) - end - return if !MacOS.sdk_root_needed? && sdk&.source != :xcode - - Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) - sdk = sdk.path - - # Extra setup to support Xcode 4.3+ without CLT. - self["SDKROOT"] = sdk - # Tell clang/gcc where system include's are: - append_path "CPATH", "#{sdk}/usr/include" - # The -isysroot is needed, too, because of the Frameworks - append_to_cflags "-isysroot#{sdk}" - append "CPPFLAGS", "-isysroot#{sdk}" - # And the linker needs to find sdk/usr/lib - append "LDFLAGS", "-isysroot#{sdk}" - # Needed to build cmake itself and perhaps some cmake projects: - append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr" - append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" - end - - # Some configure scripts won't find libxml2 without help. - # This is a no-op with macOS SDK 10.15.4 and later. - def libxml2 - sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed - if !sdk - append "CPPFLAGS", "-I/usr/include/libxml2" - elsif !Pathname("#{sdk}/usr/include/libxml").directory? - # Use the includes form the sdk - append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2" - end - end - - def no_weak_imports - append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support? - end - - def no_fixup_chains - append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support? - end +module Stdenv + undef homebrew_extra_pkg_config_paths + + sig { returns(T::Array[Pathname]) } + def homebrew_extra_pkg_config_paths + [Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")] + end + private :homebrew_extra_pkg_config_paths + + sig { + params( + formula: T.nilable(Formula), + cc: T.nilable(String), + build_bottle: T.nilable(T::Boolean), + bottle_arch: T.nilable(String), + testing_formula: T::Boolean, + debug_symbols: T.nilable(T::Boolean), + ).void + } + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, + debug_symbols: false) + generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, + testing_formula:, debug_symbols:) + + append "LDFLAGS", "-Wl,-headerpad_max_install_names" + + # `sed` is strict and errors out when it encounters files with mixed character sets. + delete("LC_ALL") + self["LC_CTYPE"] = "C" + + # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags: + macosxsdk(formula: @formula, testing_formula:) + + return unless MacOS::Xcode.without_clt? + + append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin" + append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin" + end + + def remove_macosxsdk(version = nil) + # Clear all `lib` and `include` dirs from `CFLAGS`, `CPPFLAGS`, `LDFLAGS` that were + # previously added by `macosxsdk`. + remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/) + delete("CPATH") + remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" + + sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed(version) + return unless sdk + + delete("SDKROOT") + remove_from_cflags "-isysroot#{sdk}" + remove "CPPFLAGS", "-isysroot#{sdk}" + remove "LDFLAGS", "-isysroot#{sdk}" + if HOMEBREW_PREFIX.to_s == "/usr/local" + delete("CMAKE_PREFIX_PATH") + else + # It was set in `setup_build_environment`, so we have to restore it here. + self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s end + remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" + end + + def macosxsdk(version = nil, formula: nil, testing_formula: false) + # Sets all needed `lib` and `include` dirs to `CFLAGS`, `CPPFLAGS`, `LDFLAGS`. + remove_macosxsdk + min_version = version || MacOS.version + append_to_cflags("-mmacosx-version-min=#{min_version}") + self["CPATH"] = "#{HOMEBREW_PREFIX}/include" + prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" + + sdk = if formula + MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula) + else + MacOS.sdk(version) + end + return if !MacOS.sdk_root_needed? && sdk&.source != :xcode + + Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) + sdk = sdk.path + + # Extra setup to support Xcode 4.3+ without CLT. + self["SDKROOT"] = sdk + # Tell clang/gcc where system include's are: + append_path "CPATH", "#{sdk}/usr/include" + # The -isysroot is needed, too, because of the Frameworks + append_to_cflags "-isysroot#{sdk}" + append "CPPFLAGS", "-isysroot#{sdk}" + # And the linker needs to find sdk/usr/lib + append "LDFLAGS", "-isysroot#{sdk}" + # Needed to build cmake itself and perhaps some cmake projects: + append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr" + append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" end -end -Stdenv.prepend(OS::Mac::Stdenv) + # Some configure scripts won't find libxml2 without help. + # This is a no-op with macOS SDK 10.15.4 and later. + def libxml2 + sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed + if !sdk + append "CPPFLAGS", "-I/usr/include/libxml2" + elsif !Pathname("#{sdk}/usr/include/libxml").directory? + # Use the includes form the sdk + append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2" + end + end + + def no_weak_imports + append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support? + end + + def no_fixup_chains + append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support? + end +end diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 921e13707c6a5..940bb6e744646 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -1,174 +1,171 @@ # typed: true # rubocop:disable Sorbet/StrictSigil # frozen_string_literal: true -module OS - module Mac - module Superenv - extend T::Helpers +module Superenv + class << self + # The location of Homebrew's shims on macOS. + def shims_path + HOMEBREW_SHIMS_PATH/"mac/super" + end - requires_ancestor { ::Superenv } + undef bin - module ClassMethods - # The location of Homebrew's shims on macOS. - def shims_path - HOMEBREW_SHIMS_PATH/"mac/super" - end + def bin + return unless DevelopmentTools.installed? - def bin - return unless ::DevelopmentTools.installed? + shims_path.realpath + end + end - shims_path.realpath - end - end + undef homebrew_extra_pkg_config_paths, + homebrew_extra_isystem_paths, homebrew_extra_library_paths, + homebrew_extra_cmake_include_paths, + homebrew_extra_cmake_library_paths, + homebrew_extra_cmake_frameworks_paths, + determine_cccfg - sig { returns(T::Array[Pathname]) } - def homebrew_extra_pkg_config_paths - [Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")] - end - private :homebrew_extra_pkg_config_paths + sig { returns(T::Array[Pathname]) } + def homebrew_extra_pkg_config_paths + [Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")] + end + private :homebrew_extra_pkg_config_paths - sig { returns(T::Boolean) } - def libxml2_include_needed? - return false if deps.any? { |d| d.name == "libxml2" } - return false if Pathname("#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml").directory? + sig { returns(T::Boolean) } + def libxml2_include_needed? + return false if deps.any? { |d| d.name == "libxml2" } + return false if Pathname("#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml").directory? - true - end - private :libxml2_include_needed? - - def homebrew_extra_isystem_paths - paths = [] - paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? - paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? - paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" - paths - end + true + end + private :libxml2_include_needed? + + def homebrew_extra_isystem_paths + paths = [] + paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? + paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? + paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" + paths + end - def homebrew_extra_library_paths - paths = [] - if compiler == :llvm_clang - paths << "#{self["HOMEBREW_SDKROOT"]}/usr/lib" - paths << ::Formula["llvm"].opt_lib.to_s - end - paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries" - paths - end + def homebrew_extra_library_paths + paths = [] + if compiler == :llvm_clang + paths << "#{self["HOMEBREW_SDKROOT"]}/usr/lib" + paths << Formula["llvm"].opt_lib.to_s + end + paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries" + paths + end - def homebrew_extra_cmake_include_paths - paths = [] - paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? - paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? - paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" - paths - end + def homebrew_extra_cmake_include_paths + paths = [] + paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/libxml2" if libxml2_include_needed? + paths << "#{self["HOMEBREW_SDKROOT"]}/usr/include/apache2" if MacOS::Xcode.without_clt? + paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" + paths + end - def homebrew_extra_cmake_library_paths - [Pathname( - "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries", - )] - end + def homebrew_extra_cmake_library_paths + [Pathname("#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")] + end - def homebrew_extra_cmake_frameworks_paths - paths = [] - paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks" if MacOS::Xcode.without_clt? - paths - end + def homebrew_extra_cmake_frameworks_paths + paths = [] + paths << "#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks" if MacOS::Xcode.without_clt? + paths + end - def determine_cccfg - s = +"" - # Fix issue with >= Mountain Lion apr-1-config having broken paths - s << "a" - s.freeze - end + def determine_cccfg + s = +"" + # Fix issue with >= Mountain Lion apr-1-config having broken paths + s << "a" + s.freeze + end - # @private - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, - testing_formula: false, debug_symbols: false) - sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk - is_xcode_sdk = sdk&.source == :xcode - - if is_xcode_sdk || MacOS.sdk_root_needed? - Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) - self["HOMEBREW_SDKROOT"] = sdk.path if sdk - end - - self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk - MacOS::Xcode.prefix.to_s - else - MacOS::CLT::PKG_PATH - end - - # This is a workaround for the missing `m4` in Xcode CLT 15.3, which was - # reported in FB13679972. Apple has fixed this in Xcode CLT 16.0. - # See https://github.com/Homebrew/homebrew-core/issues/165388 - if deps.none? { |d| d.name == "m4" } && - MacOS.active_developer_dir == MacOS::CLT::PKG_PATH && - !File.exist?("#{MacOS::CLT::PKG_PATH}/usr/bin/m4") && - (gm4 = ::DevelopmentTools.locate("gm4").to_s).present? - self["M4"] = gm4 - end - - super - - # Filter out symbols known not to be defined since GNU Autotools can't - # reliably figure this out with Xcode 8 and above. - if MacOS.version == "10.12" && MacOS::Xcode.version >= "9.0" - %w[fmemopen futimens open_memstream utimensat].each do |s| - ENV["ac_cv_func_#{s}"] = "no" - end - elsif MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" - %w[basename_r clock_getres clock_gettime clock_settime dirname_r - getentropy mkostemp mkostemps timingsafe_bcmp].each do |s| - ENV["ac_cv_func_#{s}"] = "no" - end - - ENV["ac_cv_search_clock_gettime"] = "no" - - # works around libev.m4 unsetting ac_cv_func_clock_gettime - ENV["ac_have_clock_syscall"] = "no" - end - - # On macOS Sonoma (at least release candidate), iconv() is generally - # present and working, but has a minor regression that defeats the - # test implemented in gettext's configure script (and used by many - # gettext dependents). - ENV["am_cv_func_iconv_works"] = "yes" if MacOS.version == "14" - - # The tools in /usr/bin proxy to the active developer directory. - # This means we can use them for any combination of CLT and Xcode. - self["HOMEBREW_PREFER_CLT_PROXIES"] = "1" - - # Deterministic timestamping. - # This can work on older Xcode versions, but they contain some bugs. - # Notably, Xcode 10.2 fixes issues where ZERO_AR_DATE affected file mtimes. - # Xcode 11.0 contains fixes for lldb reading things built with ZERO_AR_DATE. - self["ZERO_AR_DATE"] = "1" if MacOS::Xcode.version >= "11.0" || MacOS::CLT.version >= "11.0" - - # Pass `-no_fixup_chains` whenever the linker is invoked with `-undefined dynamic_lookup`. - # See: https://github.com/python/cpython/issues/97524 - # https://github.com/pybind/pybind11/pull/4301 - no_fixup_chains - - # Strip build prefixes from linker where supported, for deterministic builds. - append_to_cccfg "o" if OS::Mac::DevelopmentTools.ld64_version >= 512 - - # Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs` - # on `ld` versions that don't properly handle that option. - if OS::Mac::DevelopmentTools.ld64_version >= "1015.7" && OS::Mac::DevelopmentTools.ld64_version <= "1022.1" - append_to_cccfg "c" - end - end + # @private + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, + debug_symbols: false) + sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk + is_xcode_sdk = sdk&.source == :xcode - def no_weak_imports - append_to_cccfg "w" if no_weak_imports_support? - end + if is_xcode_sdk || MacOS.sdk_root_needed? + Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks) + self["HOMEBREW_SDKROOT"] = sdk.path if sdk + end + + self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk + MacOS::Xcode.prefix.to_s + else + MacOS::CLT::PKG_PATH + end + + # This is a workaround for the missing `m4` in Xcode CLT 15.3, which was + # reported in FB13679972. Apple has fixed this in Xcode CLT 16.0. + # See https://github.com/Homebrew/homebrew-core/issues/165388 + if deps.none? { |d| d.name == "m4" } && + MacOS.active_developer_dir == MacOS::CLT::PKG_PATH && + !File.exist?("#{MacOS::CLT::PKG_PATH}/usr/bin/m4") && + (gm4 = DevelopmentTools.locate("gm4").to_s).present? + self["M4"] = gm4 + end - def no_fixup_chains - append_to_cccfg "f" if no_fixup_chains_support? + generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, + testing_formula:, debug_symbols:) + + # Filter out symbols known not to be defined since GNU Autotools can't + # reliably figure this out with Xcode 8 and above. + if MacOS.version == "10.12" && MacOS::Xcode.version >= "9.0" + %w[fmemopen futimens open_memstream utimensat].each do |s| + ENV["ac_cv_func_#{s}"] = "no" + end + elsif MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" + %w[basename_r clock_getres clock_gettime clock_settime dirname_r + getentropy mkostemp mkostemps timingsafe_bcmp].each do |s| + ENV["ac_cv_func_#{s}"] = "no" end + + ENV["ac_cv_search_clock_gettime"] = "no" + + # works around libev.m4 unsetting ac_cv_func_clock_gettime + ENV["ac_have_clock_syscall"] = "no" + end + + # On macOS Sonoma (at least release candidate), iconv() is generally + # present and working, but has a minor regression that defeats the + # test implemented in gettext's configure script (and used by many + # gettext dependents). + ENV["am_cv_func_iconv_works"] = "yes" if MacOS.version == "14" + + # The tools in /usr/bin proxy to the active developer directory. + # This means we can use them for any combination of CLT and Xcode. + self["HOMEBREW_PREFER_CLT_PROXIES"] = "1" + + # Deterministic timestamping. + # This can work on older Xcode versions, but they contain some bugs. + # Notably, Xcode 10.2 fixes issues where ZERO_AR_DATE affected file mtimes. + # Xcode 11.0 contains fixes for lldb reading things built with ZERO_AR_DATE. + self["ZERO_AR_DATE"] = "1" if MacOS::Xcode.version >= "11.0" || MacOS::CLT.version >= "11.0" + + # Pass `-no_fixup_chains` whenever the linker is invoked with `-undefined dynamic_lookup`. + # See: https://github.com/python/cpython/issues/97524 + # https://github.com/pybind/pybind11/pull/4301 + no_fixup_chains + + # Strip build prefixes from linker where supported, for deterministic builds. + append_to_cccfg "o" if OS::Mac::DevelopmentTools.ld64_version >= 512 + + # Pass `-ld_classic` whenever the linker is invoked with `-dead_strip_dylibs` + # on `ld` versions that don't properly handle that option. + if OS::Mac::DevelopmentTools.ld64_version >= "1015.7" && OS::Mac::DevelopmentTools.ld64_version <= "1022.1" + append_to_cccfg "c" end end -end -Superenv.singleton_class.prepend(OS::Mac::Superenv::ClassMethods) -Superenv.prepend(OS::Mac::Superenv) + def no_weak_imports + append_to_cccfg "w" if no_weak_imports_support? + end + + def no_fixup_chains + append_to_cccfg "f" if no_fixup_chains_support? + end +end