Module: Superenv Private

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Why superenv?

  1. Only specify the environment we need (NO LDFLAGS for cmake)
  2. Only apply compiler-specific options when we are calling that compiler
  3. Force all incpaths and libpaths into the cc instantiation (fewer bugs)
  4. Cater toolchain usage to specific Xcode versions
  5. Remove flags that we don't want or that will break builds
  6. Simpler code
  7. Simpler formulae that just work
  8. Build-system agnostic configuration of the toolchain

Constant Summary

Constants included from CompilerConstants

CompilerConstants::COMPILERS, CompilerConstants::COMPILER_SYMBOL_MAP, CompilerConstants::GNU_GCC_REGEXP, CompilerConstants::GNU_GCC_VERSIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from SharedEnvExtension

#append, #append_path, #append_to_cccfg, #append_to_cflags, #append_to_rustflags, #bottle_arch, #build_bottle?, #cc, #cflags, #compiler, #cppflags, #cxx, #cxxflags, #debug_symbols?, #effective_arch, #fc, #fcflags, #fflags, #fortran, #ldflags, #prepend, #prepend_create_path, #prepend_path, #remove, #remove_cc_etc, #remove_from_cflags

Methods included from OS::Linux::SharedEnvExtension

#effective_arch

Methods included from OS::Linux::Superenv

#determine_dynamic_linker_path, #determine_rpath_paths

Methods included from OS::Mac::Superenv

#no_fixup_chains, #no_weak_imports

Class Method Details

.bin ⇒ Pathname?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



65
# File 'extend/ENV/super.rb', line 65

def self.bin; end

.enabled_for?(env) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


68
69
70
71
72
# File 'extend/ENV/super.rb', line 68

def self.enabled_for?(env)
  return false if env == "std"

  !bin.nil?
end

.extended(base) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



47
48
49
50
51
52
53
54
# File 'extend/ENV/super.rb', line 47

def self.extended(base)
  # Runtime signatures on the dependency setters resolve Formula on first call.
  require "formula"

  base.keg_only_deps = []
  base.deps = []
  base.run_time_deps = []
end

.shims_path ⇒ Pathname

The location of Homebrew's shims.

Returns:



60
61
62
# File 'extend/ENV/super.rb', line 60

def self.shims_path
  HOMEBREW_SHIMS_PATH/"super"
end

Instance Method Details

#cxx11 ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



398
399
400
401
# File 'extend/ENV/super.rb', line 398

def cxx11
  append_to_cccfg "x"
  append_to_cccfg "g" if homebrew_cc == "clang"
end

#deparallelize(&block) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Removes the MAKEFLAGS environment variable, causing make to use a single job. This is useful for makefiles with race conditions. When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion.

Parameters:

  • block (T.proc.returns(T.untyped), nil)

Returns:

  • (T.untyped)


365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'extend/ENV/super.rb', line 365

def deparallelize(&block)
  old_makeflags = delete("MAKEFLAGS")
  old_make_jobs = delete("HOMEBREW_MAKE_JOBS")
  self["HOMEBREW_MAKE_JOBS"] = "1"
  if block
    begin
      yield
    ensure
      self["MAKEFLAGS"] = old_makeflags
      self["HOMEBREW_MAKE_JOBS"] = old_make_jobs
    end
  end

  old_makeflags
end

#deps ⇒ Array<Formula>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



31
# File 'extend/ENV/super.rb', line 31

def deps = build_environment_state.deps

#deps=(deps) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



34
35
36
# File 'extend/ENV/super.rb', line 34

def deps=(deps)
  build_environment_state(writable: true).deps = deps
end

#keg_only_deps ⇒ Array<Formula>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



23
# File 'extend/ENV/super.rb', line 23

def keg_only_deps = build_environment_state.keg_only_deps

#keg_only_deps=(deps) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



26
27
28
# File 'extend/ENV/super.rb', line 26

def keg_only_deps=(deps)
  build_environment_state(writable: true).keg_only_deps = deps
end

#libcxx ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



404
405
406
# File 'extend/ENV/super.rb', line 404

def libcxx
  append_to_cccfg "g" if compiler == :clang
end

#llvm_clang ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



169
170
171
172
173
# File 'extend/ENV/super.rb', line 169

def llvm_clang
  super
  self["CC"] = self["OBJC"] = "clang"
  self["CXX"] = self["OBJCXX"] = "clang++"
end

#make_jobs ⇒ Integer

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



382
383
384
385
# File 'extend/ENV/super.rb', line 382

def make_jobs
  self["MAKEFLAGS"] =~ /-\w*j(\d+)/
  [Regexp.last_match(1).to_i, 1].max
end

#O0(&block) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



421
422
423
424
425
426
427
# File 'extend/ENV/super.rb', line 421

def O0(&block)
  if block
    with_env(HOMEBREW_OPTIMIZATION_LEVEL: "O0", &block)
  else
    self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O0"
  end
end

#O1(&block) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • block (T.proc.void, nil)


430
431
432
433
434
435
436
# File 'extend/ENV/super.rb', line 430

def O1(&block)
  if block
    with_env(HOMEBREW_OPTIMIZATION_LEVEL: "O1", &block)
  else
    self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O1"
  end
end

#O3(&block) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • block (T.proc.void, nil)


439
440
441
442
443
444
445
# File 'extend/ENV/super.rb', line 439

def O3(&block)
  if block
    with_env(HOMEBREW_OPTIMIZATION_LEVEL: "O3", &block)
  else
    self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O3"
  end
end

#permit_arch_flags ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



388
389
390
# File 'extend/ENV/super.rb', line 388

def permit_arch_flags
  append_to_cccfg "K"
end

#refurbish_args ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



414
415
416
# File 'extend/ENV/super.rb', line 414

def refurbish_args
  append_to_cccfg "O"
end

#reset ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



75
76
77
78
79
80
# File 'extend/ENV/super.rb', line 75

def reset
  super
  # Configure scripts generated by autoconf 2.61 or later export as_nl, which
  # we use as a heuristic for running under configure
  delete("as_nl")
end

#run_time_deps ⇒ Array<Formula>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



39
# File 'extend/ENV/super.rb', line 39

def run_time_deps = build_environment_state.run_time_deps

#run_time_deps=(deps) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



42
43
44
# File 'extend/ENV/super.rb', line 42

def run_time_deps=(deps)
  build_environment_state(writable: true).run_time_deps = deps
end

#runtime_cpu_detection ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



393
394
395
# File 'extend/ENV/super.rb', line 393

def runtime_cpu_detection
  append_to_cccfg "d"
end

#set_debug_symbols ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



409
410
411
# File 'extend/ENV/super.rb', line 409

def set_debug_symbols
  append_to_cccfg "D"
end

#setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • formula (Formula, nil) (defaults to: nil)
  • cc (String, nil) (defaults to: nil)
  • build_bottle (Boolean, nil) (defaults to: false)
  • bottle_arch (String, nil) (defaults to: nil)
  • testing_formula (Boolean) (defaults to: false)
  • debug_symbols (Boolean, nil) (defaults to: false)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'extend/ENV/super.rb', line 92

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
                            debug_symbols: false)
  super
  send(compiler)

  self["HOMEBREW_ENV"] = "super"
  self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}"
  self["RUSTC_WRAPPER"] = "#{HOMEBREW_SHIMS_PATH}/shared/rustc_wrapper"
  self["HOMEBREW_RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
  self["PATH"] = determine_path&.to_s
  self["PKG_CONFIG_PATH"] = determine_pkg_config_path&.to_s
  self["PKG_CONFIG_LIBDIR"] = (determine_pkg_config_libdir || "").to_s
  self["HOMEBREW_CCCFG"] = determine_cccfg
  self["HOMEBREW_OPTIMIZATION_LEVEL"] = compiler.match?(GNU_GCC_REGEXP) ? "O2" : "Os"
  self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s
  self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
  self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
  self["HOMEBREW_OPT"] = "#{HOMEBREW_PREFIX}/opt"
  self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
  self["HOMEBREW_OPTFLAGS"] = determine_optflags
  self["HOMEBREW_MAKE_JOBS"] = determine_make_jobs.to_s
  self["CMAKE_PREFIX_PATH"] = determine_cmake_prefix_path&.to_s
  self["CMAKE_FRAMEWORK_PATH"] = determine_cmake_frameworks_path&.to_s
  self["CMAKE_INCLUDE_PATH"] = determine_cmake_include_path&.to_s
  self["CMAKE_LIBRARY_PATH"] = determine_cmake_library_path&.to_s
  self["ACLOCAL_PATH"] = determine_aclocal_path&.to_s
  self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" }
  self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths&.to_s
  self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths&.to_s
  self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths&.to_s
  self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
  self["HOMEBREW_FORMULA_PREFIX"] = formula.prefix.to_s if formula
  # Prevent the OpenSSL rust crate from building a vendored OpenSSL.
  # https://github.com/sfackler/rust-openssl/blob/994e5ff8c63557ab2aa85c85cc6956b0b0216ca7/openssl/src/lib.rs#L65
  self["OPENSSL_NO_VENDOR"] = "1"
  # Prevent Go from automatically downloading a newer toolchain than the one that we have.
  # https://tip.golang.org/doc/toolchain
  self["GOTOOLCHAIN"] = "local"
  # Prevent maturin from automatically downloading its own rust
  self["MATURIN_NO_INSTALL_RUST"] = "1"
  # Prevent Python packages from using bundled libraries by default.
  # Currently for hidapi, pyzmq and pynacl
  self["HIDAPI_SYSTEM_HIDAPI"] = "1"
  self["PYZMQ_NO_BUNDLE"] = "1"
  self["SODIUM_INSTALL"] = "system"
  # Set defaults for Bundler installs
  self["BUNDLE_FORCE_RUBY_PLATFORM"] = "true"
  self["BUNDLE_VERSION"] = "system"
  self["BUNDLE_WITHOUT"] = "development:test"
  # Set defaults for opam
  self["OPAMNODEPEXTS"] = "1"
  self["OPAMYES"] = "1"

  set_debug_symbols if debug_symbols

  # The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control
  # compiler flag stripping. It consists of a string of characters which act
  # as flags. Some of these flags are mutually exclusive.
  #
  # O - Enables argument refurbishing. Only active under the
  #     make/bsdmake wrappers currently.
  # x - Enable C++11 mode.
  # g - Enable "-stdlib=libc++" for clang.
  # h - Enable "-stdlib=libstdc++" for clang.
  # K - Don't strip -arch <arch>, -m32, or -m64
  # d - Don't strip -march=<target>. Use only in formulae that
  #     have runtime detection of CPU features.
  # D - Generate debugging information
  # w - Pass `-no_weak_imports` to the linker
  # f - Pass `-no_fixup_chains` to `ld` whenever it
  #     is invoked with `-undefined dynamic_lookup`
  # c - Pass `-ld_classic` to `ld` whenever it is invoked
  #     with `-dead_strip_dylibs`
  # b - Pass `-mbranch-protection=standard` to the compiler
end