From fa26b5a06d0075e2e9e9aae09c95946c535d582a Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sat, 6 Aug 2022 13:21:18 +0800 Subject: [PATCH 1/2] linux/super: add unversioned GCC lib directory to RPATH This adds GCC's runtime lib directory to the RPATH of every build on Linux (unconditionally!). This is useful for three things: 1. It fixes versioned GCC linkage for formulae that users build from source instead of pouring from a bottle. We currently only handle bottle installs. See #13633. 2. It helps minimise the GCC dependency explosion. When a formula has a Linux-only GCC dependency, then all its dependents that link with some GCC runtime library (typically `libstdc++`) must, before this change, also adopt a GCC dependency. This is a consequence of our injecting GCC's runtime library directory into RPATH only when a formula is built with GCC (this is done through the specs file). We can avoid the need to do this by always injecting this path instead. 3. This enables us to automatically install Homebrew GCC whenever the user's GCC is too old and the formula may need it. Without this change, auto-installing GCC is not that useful because formulae that need it may not know to look for our GCC, unless the formula already happened to be built with our GCC. With this change, these formulae will always be able to find our GCC when it is installed. This is particularly useful for when we start building with a version of GCC that is much closer to the latest than we currently do. This approach comes with at least two drawbacks: 1. We will see spurious linkage warnings in CI about an undeclared dependency with linkage as soon as Homebrew GCC is installed, because formulae will link with our GCC instead of the host's. Users will also see a similar complaint if they do `brew linkage`. 2. This leans _very_ heavily on GCC delivering backward compatibility of their runtime libraries. If they do not, we could see different behaviour across different CI runs for the same formula depending on whether Homebrew GCC is installed. It's worth noting that item 3 in the "useful" list above may rely on features not yet implement in `brew`. --- Library/Homebrew/extend/os/linux/extend/ENV/super.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 8dd6f95c8d..eb2460a5ba 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -51,6 +51,7 @@ module Superenv 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", ) From 478e42d536679ecc8673fbbb991347779e4d8112 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 10 Aug 2022 19:00:59 +0800 Subject: [PATCH 2/2] linux/linkage_checker: remove `gcc` from `undeclared_deps` --- Library/Homebrew/extend/os/linux/linkage_checker.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/linux/linkage_checker.rb b/Library/Homebrew/extend/os/linux/linkage_checker.rb index 4e2bbf557b..e94995e966 100644 --- a/Library/Homebrew/extend/os/linux/linkage_checker.rb +++ b/Library/Homebrew/extend/os/linux/linkage_checker.rb @@ -72,6 +72,9 @@ class LinkageChecker @unwanted_system_dylibs = @system_dylibs.reject do |s| SYSTEM_LIBRARY_ALLOWLIST.include? File.basename(s) end - @undeclared_deps -= [CompilerSelector.preferred_gcc, "glibc"] + # FIXME: Remove this when these dependencies are injected correctly (e.g. through `DependencyCollector`) + # See discussion at + # https://github.com/Homebrew/brew/pull/13577 + @undeclared_deps -= [CompilerSelector.preferred_gcc, "glibc", "gcc"] end end