Skip to content

Commit 8c0de5a

Browse files
Axel Ricardh-vetinari
authored andcommitted
fix sanity check for d cross-compilation
Cherry-picked from mesonbuild@8d7ffe6
1 parent 31161ee commit 8c0de5a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

mesonbuild/compilers/d.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,18 @@ 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 environment.need_exe_wrapper(self.for_machine) 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())
457+
450458
if environment.need_exe_wrapper(self.for_machine):
451459
if not environment.has_exe_wrapper():
452460
# Can't check if the binaries run so we have to assume they do
@@ -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)

0 commit comments

Comments
 (0)