Module: Superenv Private

Includes:
OS::Linux::Superenv, OS::Mac::Superenv, SharedEnvExtension
Defined in:
extend/ENV/super.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedEnvExtension

#[]=, #append, #append_path, #append_to_cccfg, #append_to_cflags, #cc, #cflags, #compiler, #cppflags, #cxx, #cxxflags, #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::Mac::SharedEnvExtension

#no_fixup_chains_support?, #no_weak_imports_support?

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

#depsObject

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.



20
21
22
# File 'extend/ENV/super.rb', line 20

def deps
  @deps
end

#keg_only_depsObject

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.



20
21
22
# File 'extend/ENV/super.rb', line 20

def keg_only_deps
  @keg_only_deps
end

#run_time_depsObject

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.



20
21
22
# File 'extend/ENV/super.rb', line 20

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:



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

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:



23
24
25
26
27
# File 'extend/ENV/super.rb', line 23

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

.shims_pathPathname

The location of Homebrew's shims.

Returns:



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

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.



353
354
355
356
# File 'extend/ENV/super.rb', line 353

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)


320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'extend/ENV/super.rb', line 320

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

#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.



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

def libcxx
  append_to_cccfg "g" if compiler == :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:

  • (Integer)


337
338
339
340
# File 'extend/ENV/super.rb', line 337

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.



376
377
378
379
380
381
382
# File 'extend/ENV/super.rb', line 376

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)


385
386
387
388
389
390
391
# File 'extend/ENV/super.rb', line 385

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)


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

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.



343
344
345
# File 'extend/ENV/super.rb', line 343

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.



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

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.



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

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.



348
349
350
# File 'extend/ENV/super.rb', line 348

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.



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

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)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
# File 'extend/ENV/super.rb', line 58

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["RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
  self["PATH"] = determine_path
  self["PKG_CONFIG_PATH"] = determine_pkg_config_path
  self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir || ""
  self["HOMEBREW_CCCFG"] = determine_cccfg
  self["HOMEBREW_OPTIMIZATION_LEVEL"] = "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_ARCHFLAGS"] = ""
  self["HOMEBREW_MAKE_JOBS"] = determine_make_jobs.to_s
  self["CMAKE_PREFIX_PATH"] = determine_cmake_prefix_path
  self["CMAKE_FRAMEWORK_PATH"] = determine_cmake_frameworks_path
  self["CMAKE_INCLUDE_PATH"] = determine_cmake_include_path
  self["CMAKE_LIBRARY_PATH"] = determine_cmake_library_path
  self["ACLOCAL_PATH"] = determine_aclocal_path
  self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" }
  self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
  self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
  self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
  self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
  self["HOMEBREW_FORMULA_PREFIX"] = @formula.prefix 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 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`
  # o - Pass `-oso_prefix` to `ld` whenever it is invoked
  # c - Pass `-ld_classic` to `ld` whenever it is invoked
  #     with `-dead_strip_dylibs`
  # b - Pass `-mbranch-protection=standard` to the compiler
  #
  # These flags will also be present:
  # a - apply fix for apr-1-config path
end