Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
search_version, is_windows, Popen_safe, Popen_safe_logged, version_compare, windows_proof_rm,
)
from ..programs import ExternalProgram
from ..envconfig import BinaryTable, detect_cpu_family, detect_machine_info
from ..envconfig import BinaryTable, detect_cpu_family
from .. import mlog

from ..linkers import guess_win_linker, guess_nix_linker
Expand Down Expand Up @@ -1329,6 +1329,8 @@ def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp

# We need a C compiler to properly detect the machine info and linker
cc = detect_c_compiler(env, for_machine)
if not (env.build_machines_are_exact or env.is_cross_build(for_machine)):
env.update_build_machine({'c': cc})

popen_exceptions: T.Dict[str, Exception] = {}
for comp in compilers:
Expand Down Expand Up @@ -1368,10 +1370,10 @@ def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
# We need a C compiler to properly detect the machine info and linker
cc = detect_c_compiler(env, for_machine)
if not env.is_cross_build(for_machine):
info = detect_machine_info({'c': cc})
else:
info = env.machines[for_machine]
if not (env.build_machines_are_exact or env.is_cross_build(for_machine)):
env.update_build_machine({'c': cc})

info = env.machines[for_machine]

from .asm import MasmCompiler, MasmARMCompiler
comp_class: T.Type[ASMCompiler]
Expand Down Expand Up @@ -1411,6 +1413,8 @@ def detect_linearasm_compiler(env: Environment, for_machine: MachineChoice) -> C
comp_class: T.Type[ASMCompiler] = TILinearAsmCompiler
arg = '-h'
cc = detect_c_compiler(env, for_machine)
if not (env.build_machines_are_exact or env.is_cross_build(for_machine)):
env.update_build_machine({'c': cc})

popen_exceptions: T.Dict[str, Exception] = {}
try:
Expand Down
19 changes: 19 additions & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def __init__(self, source_dir: str, build_dir: T.Optional[str], cmd_options: cmd
self.default_pkgconfig = ['pkg-config']
self.wrap_resolver: T.Optional['Resolver'] = None

self.build_machines_are_exact = False

def mfilestr2key(self, machine_file_string: str, section: T.Optional[str], section_subproject: T.Optional[str], machine: MachineChoice) -> OptionKey:
key = OptionKey.from_string(machine_file_string)
if key.subproject:
Expand Down Expand Up @@ -613,3 +615,20 @@ def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
# This is how autotools works, and the env vars feature is for
# autotools compatibility.
largs.extend_value(comp_options)

def update_build_machine(self, compilers: T.Optional[T.Dict[str, Compiler]] = None) -> None:
"""Redetect the build machine and update the machine definitions

:compilers: An optional dictionary of compilers to use instead of the coredata dict.
"""
if self.build_machines_are_exact:
return

compilers = compilers or self.coredata.compilers.build
if not compilers:
return

machines = self.machines.miss_defaulting()
machines.build = detect_machine_info(compilers)
self.machines = machines.default_missing()
self.build_machines_are_exact = True
7 changes: 1 addition & 6 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,7 @@ def _redetect_machines(self) -> None:
# Re-initialize machine descriptions. We can do a better job now because we
# have the compilers needed to gain more knowledge, so wipe out old
# inference and start over.
machines = self.build.environment.machines.miss_defaulting()
machines.build = envconfig.detect_machine_info(self.coredata.compilers.build)
self.build.environment.machines = machines.default_missing()
assert self.build.environment.machines.build.cpu is not None
assert self.build.environment.machines.host.cpu is not None
assert self.build.environment.machines.target.cpu is not None
self.build.environment.update_build_machine()

self.builtin['build_machine'] = \
OBJ.MachineHolder(self.build.environment.machines.build, self)
Expand Down
Loading