Module: Hardware Private

Defined in:
extend/os/mac/hardware.rb,
extend/os/mac/hardware/cpu.rb,
extend/os/linux/hardware/cpu.rb,
hardware.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.

Helper module for querying hardware information.

Defined Under Namespace

Classes: CPU

Class Method Summary collapse

Class Method Details

.cores_as_wordsString

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:



207
208
209
210
211
212
213
214
215
216
217
218
# File 'hardware.rb', line 207

def cores_as_words
  case Hardware::CPU.cores
  when 1 then "single"
  when 2 then "dual"
  when 4 then "quad"
  when 6 then "hexa"
  when 8 then "octa"
  when 12 then "dodeca"
  else
    Hardware::CPU.cores.to_s
  end
end

.oldest_cpu(_version = nil) ⇒ Symbol Also known as: generic_oldest_cpu

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:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'extend/os/mac/hardware.rb', line 6

def self.oldest_cpu(version = nil)
  version = if version
    MacOSVersion.new(version.to_s)
  else
    MacOS.version
  end
  if CPU.arch == :arm64
    :arm_vortex_tempest
  # This cannot use a newer CPU e.g. haswell because Rosetta 2 does not
  # support AVX instructions in bottles:
  #   https://github.com/Homebrew/homebrew-core/issues/67713
  elsif version >= :ventura
    :westmere
  elsif version >= :mojave
    :nehalem
  else
    generic_oldest_cpu
  end
end

.rustflags_target_cpu(arch) ⇒ String?

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 a Rust flag to set the target CPU if necessary. Defaults to nil.

Parameters:

Returns:



248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'hardware.rb', line 248

def rustflags_target_cpu(arch)
  # Rust already defaults to the oldest supported cpu for each target-triplet
  # so it's safe to ignore generic archs such as :armv6 here.
  # Rust defaults to apple-m1 since Rust 1.71 for aarch64-apple-darwin.
  @target_cpu ||= T.let(case arch
  when :core
    :prescott
  when :native, :ivybridge, :sandybridge, :westmere, :nehalem, :core2
    arch
  end, T.nilable(Symbol))
  return if @target_cpu.blank?

  "--codegen target-cpu=#{@target_cpu}"
end