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

Instance Attribute Summary collapse

Attributes included from SharedEnvExtension

#bottle_arch

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_outside_github_actions, #opoo_without_github_actions_annotation, #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, #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

#libxml2_include_needed?, #no_fixup_chains, #no_weak_imports

Instance Attribute Details

#depsArray<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:



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

def deps
  @deps
end

#keg_only_depsArray<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
24
25
# File 'extend/ENV/super.rb', line 23

def keg_only_deps
  @keg_only_deps
end

#run_time_depsArray<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:



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

def run_time_deps
  @run_time_deps
end

Class Method Details

.binPathname?

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:



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

def self.bin; 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:



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

def self.extended(base)
  base.keg_only_deps = []
  base.deps = []
  base.run_time_deps = []
end

.shims_pathPathname

The location of Homebrew's shims.

Returns:



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

def self.shims_path
  HOMEBREW_SHIMS_PATH/"super"
end

Instance Method Details

#cxx11void

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.



373
374
375
376
# File 'extend/ENV/super.rb', line 373

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)


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'extend/ENV/super.rb', line 340

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

#initializevoid

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.



50
51
52
53
54
55
56
# File 'extend/ENV/super.rb', line 50

def initialize
  @keg_only_deps = T.let([], T::Array[Formula])
  @deps = T.let([], T::Array[Formula])
  @run_time_deps = T.let([], T::Array[Formula])

  @formula = T.let(nil, T.nilable(Formula))
end

#libcxxvoid

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.



379
380
381
# File 'extend/ENV/super.rb', line 379

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

#llvm_clangvoid

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.



146
147
148
149
150
# File 'extend/ENV/super.rb', line 146

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

#make_jobsInteger

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:



357
358
359
360
# File 'extend/ENV/super.rb', line 357

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.



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

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)


405
406
407
408
409
410
411
# File 'extend/ENV/super.rb', line 405

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)


414
415
416
417
418
419
420
# File 'extend/ENV/super.rb', line 414

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

#permit_arch_flagsvoid

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.



363
364
365
# File 'extend/ENV/super.rb', line 363

def permit_arch_flags
  append_to_cccfg "K"
end

#refurbish_argsvoid

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.



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

def refurbish_args
  append_to_cccfg "O"
end

#resetvoid

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.



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

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

#runtime_cpu_detectionvoid

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.



368
369
370
# File 'extend/ENV/super.rb', line 368

def runtime_cpu_detection
  append_to_cccfg "d"
end

#set_debug_symbolsvoid

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.



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

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)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
# File 'extend/ENV/super.rb', line 76

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 unless @formula.nil?
  # 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_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