diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index 6661f22bc926851f42dd3ad3ad64e4581deffd81..6d98c8f758f3cf8888518d119330c0d992f99196 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -28,6 +28,23 @@ module Homebrew
       missing
     end
 
+    def self.checks(type, fatal: true)
+      @checks ||= Checks.new
+      failed = false
+      @checks.public_send(type).each do |check|
+        out = @checks.public_send(check)
+        next if out.nil?
+
+        if fatal
+          failed ||= true
+          ofail out
+        else
+          opoo out
+        end
+      end
+      exit 1 if failed && fatal
+    end
+
     # Diagnostic checks.
     class Checks
       def initialize(verbose: true)
@@ -74,6 +91,10 @@ module Homebrew
         ].freeze
       end
 
+      def fatal_setup_build_environment_checks
+        [].freeze
+      end
+
       def supported_configuration_checks
         [].freeze
       end
diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb
index 29f57569940a7fd3ec2b987d14bd2062e272f70e..9d0835167d501b84caff21bb128fd40cf07315a9 100644
--- a/Library/Homebrew/extend/ENV.rb
+++ b/Library/Homebrew/extend/ENV.rb
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 require "hardware"
+require "diagnostic"
 require "extend/ENV/shared"
 require "extend/ENV/std"
 require "extend/ENV/super"
diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb
index 9ebd2f88e3607108ee1f0218e9104a0a60769ada..de7222f907a3fa90ca55a7ab58f3efe3cfd825bc 100644
--- a/Library/Homebrew/extend/os/mac/diagnostic.rb
+++ b/Library/Homebrew/extend/os/mac/diagnostic.rb
@@ -41,8 +41,8 @@ module Homebrew
     end
 
     class Checks
-      undef fatal_build_from_source_checks, supported_configuration_checks,
-            build_from_source_checks
+      undef fatal_build_from_source_checks, fatal_setup_build_environment_checks,
+            supported_configuration_checks, build_from_source_checks
 
       def fatal_build_from_source_checks
         %w[
@@ -54,6 +54,12 @@ module Homebrew
         ].freeze
       end
 
+      def fatal_setup_build_environment_checks
+        %w[
+          check_if_supported_sdk_available
+        ].freeze
+      end
+
       def supported_configuration_checks
         %w[
           check_for_unsupported_macos
diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb
index a83d9f33021ef6a6c2d415370fc0feee9c4d8d16..680d391eefac623299611afc0d8b0c8f83bacdd9 100644
--- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb
+++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb
@@ -83,6 +83,7 @@ module Stdenv
     sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version)
     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.
diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb
index f704e7dd1350ff79b4b29d4905017dcdf0ff29fd..7c5fc789124bfae411b011253b5fec9f132a70a1 100644
--- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb
+++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb
@@ -110,7 +110,9 @@ module Superenv
     formula = options[:formula]
     sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
     if MacOS.sdk_root_needed? || sdk&.source == :xcode
+      Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
       self["HOMEBREW_SDKROOT"] = sdk.path
+
       self["HOMEBREW_DEVELOPER_DIR"] = if sdk.source == :xcode
         MacOS::Xcode.prefix
       else
diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb
index 10f8df4547f1a0de1f0dfaf0aa3d00b30125fdf4..17d406957b1c1af5329833ffb1032236c4655f81 100644
--- a/Library/Homebrew/install.rb
+++ b/Library/Homebrew/install.rb
@@ -16,15 +16,15 @@ module Homebrew
       check_cpu
       attempt_directory_creation
       check_cc_argv(cc)
-      diagnostic_checks(:supported_configuration_checks, fatal: all_fatal)
-      diagnostic_checks(:fatal_preinstall_checks)
+      Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal)
+      Diagnostic.checks(:fatal_preinstall_checks)
     end
     alias generic_perform_preinstall_checks perform_preinstall_checks
     module_function :generic_perform_preinstall_checks
 
     def perform_build_from_source_checks(all_fatal: false)
-      diagnostic_checks(:fatal_build_from_source_checks)
-      diagnostic_checks(:build_from_source_checks, fatal: all_fatal)
+      Diagnostic.checks(:fatal_build_from_source_checks)
+      Diagnostic.checks(:build_from_source_checks, fatal: all_fatal)
     end
 
     def check_cpu
@@ -69,24 +69,6 @@ module Homebrew
       EOS
     end
     private_class_method :check_cc_argv
-
-    def diagnostic_checks(type, fatal: true)
-      @checks ||= Diagnostic::Checks.new
-      failed = false
-      @checks.public_send(type).each do |check|
-        out = @checks.public_send(check)
-        next if out.nil?
-
-        if fatal
-          failed ||= true
-          ofail out
-        else
-          opoo out
-        end
-      end
-      exit 1 if failed && fatal
-    end
-    private_class_method :diagnostic_checks
   end
 end