Skip to content

Commit 6f88e48

Browse files
authored
Merge pull request #16 from h-vetinari/cross
Add patches for cross-compilation
2 parents 31161ee + b92996d commit 6f88e48

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

mesonbuild/backend/backends.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ def get_executable_serialisation(
568568
else:
569569
extra_paths = []
570570

571-
if self.environment.need_exe_wrapper(exe_for_machine):
571+
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine)
572+
if is_cross_built and self.environment.need_exe_wrapper():
572573
if not self.environment.has_exe_wrapper():
573574
msg = 'An exe_wrapper is needed but was not found. Please define one ' \
574575
'in cross file and check the command and/or add it to PATH.'

mesonbuild/compilers/cuda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
551551
flags += self.get_ccbin_args(env.coredata.options)
552552

553553
# If cross-compiling, we can't run the sanity check, only compile it.
554-
if env.need_exe_wrapper(self.for_machine) and not env.has_exe_wrapper():
554+
if self.is_cross and not env.has_exe_wrapper():
555555
# Linking cross built apps is painful. You can't really
556556
# tell if you should use -nostdlib or not and for example
557557
# on OSX the compiler binary is the same but you need
@@ -573,7 +573,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
573573
raise EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
574574

575575
# Run sanity check (if possible)
576-
if env.need_exe_wrapper(self.for_machine):
576+
if self.is_cross:
577577
if not env.has_exe_wrapper():
578578
return
579579
else:

mesonbuild/compilers/d.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,19 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
443443
output_name = os.path.join(work_dir, 'dtest')
444444
with open(source_name, 'w', encoding='utf-8') as ofile:
445445
ofile.write('''void main() { }''')
446-
pc = subprocess.Popen(self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name], cwd=work_dir)
446+
447+
compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name]
448+
449+
# If cross-compiling, we can't run the sanity check, only compile it.
450+
if self.is_cross and not environment.has_exe_wrapper():
451+
compile_cmdlist += self.get_compile_only_args()
452+
453+
pc = subprocess.Popen(compile_cmdlist, cwd=work_dir)
447454
pc.wait()
448455
if pc.returncode != 0:
449456
raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
450-
if environment.need_exe_wrapper(self.for_machine):
457+
458+
if self.is_cross:
451459
if not environment.has_exe_wrapper():
452460
# Can't check if the binaries run so we have to assume they do
453461
return
@@ -545,7 +553,9 @@ def _get_target_arch_args(self) -> T.List[str]:
545553
# LDC2 on Windows targets to current OS architecture, but
546554
# it should follow the target specified by the MSVC toolchain.
547555
if self.info.is_windows():
548-
if self.arch == 'x86_64':
556+
if self.is_cross:
557+
return [f'-mtriple={self.arch}-windows-msvc']
558+
elif self.arch == 'x86_64':
549559
return ['-m64']
550560
return ['-m32']
551561
return []

mesonbuild/compilers/detect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,8 @@ def detect_d_compiler(env: 'Environment', for_machine: MachineChoice) -> Compile
11611161

11621162
return cls(
11631163
exelist, version, for_machine, info, arch,
1164-
full_version=full_version, linker=linker, version_output=out)
1164+
full_version=full_version, linker=linker,
1165+
is_cross=is_cross, version_output=out)
11651166
elif 'gdc' in out:
11661167
cls = d.GnuDCompiler
11671168
linker = guess_nix_linker(env, exelist, cls, version, for_machine)

mesonbuild/compilers/mixins/clike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
278278
mode = CompileCheckMode.LINK
279279
if self.is_cross:
280280
binname += '_cross'
281-
if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
281+
if not environment.has_exe_wrapper():
282282
# Linking cross built C/C++ apps is painful. You can't really
283283
# tell if you should use -nostdlib or not and for example
284284
# on OSX the compiler binary is the same but you need
@@ -308,7 +308,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
308308
if pc.returncode != 0:
309309
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
310310
# Run sanity check
311-
if environment.need_exe_wrapper(self.for_machine):
311+
if self.is_cross:
312312
if not environment.has_exe_wrapper():
313313
# Can't check if the binaries run so we have to assume they do
314314
return

mesonbuild/compilers/rust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
8686
if pc.returncode != 0:
8787
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
8888
self._native_static_libs(work_dir, source_name)
89-
if environment.need_exe_wrapper(self.for_machine):
89+
if self.is_cross:
9090
if not environment.has_exe_wrapper():
9191
# Can't check if the binaries run so we have to assume they do
9292
return

mesonbuild/environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ def machine_info_can_run(machine_info: MachineInfo):
505505
if machine_info.system != detect_system():
506506
return False
507507
true_build_cpu_family = detect_cpu_family({})
508+
assert machine_info.cpu_family is not None, 'called on incomplete machine_info'
508509
return \
509510
(machine_info.cpu_family == true_build_cpu_family) or \
510511
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \

0 commit comments

Comments
 (0)