Skip to content

Commit

Permalink
Merge pull request #16 from h-vetinari/cross
Browse files Browse the repository at this point in the history
Add patches for cross-compilation
  • Loading branch information
rgommers authored Aug 6, 2024
2 parents 31161ee + b92996d commit 6f88e48
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ def get_executable_serialisation(
else:
extra_paths = []

if self.environment.need_exe_wrapper(exe_for_machine):
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine)
if is_cross_built and self.environment.need_exe_wrapper():
if not self.environment.has_exe_wrapper():
msg = 'An exe_wrapper is needed but was not found. Please define one ' \
'in cross file and check the command and/or add it to PATH.'
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def sanity_check(self, work_dir: str, env: 'Environment') -> None:
flags += self.get_ccbin_args(env.coredata.options)

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

# Run sanity check (if possible)
if env.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not env.has_exe_wrapper():
return
else:
Expand Down
16 changes: 13 additions & 3 deletions mesonbuild/compilers/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,19 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
output_name = os.path.join(work_dir, 'dtest')
with open(source_name, 'w', encoding='utf-8') as ofile:
ofile.write('''void main() { }''')
pc = subprocess.Popen(self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name], cwd=work_dir)

compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name]

# If cross-compiling, we can't run the sanity check, only compile it.
if self.is_cross and not environment.has_exe_wrapper():
compile_cmdlist += self.get_compile_only_args()

pc = subprocess.Popen(compile_cmdlist, cwd=work_dir)
pc.wait()
if pc.returncode != 0:
raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
if environment.need_exe_wrapper(self.for_machine):

if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down Expand Up @@ -545,7 +553,9 @@ def _get_target_arch_args(self) -> T.List[str]:
# LDC2 on Windows targets to current OS architecture, but
# it should follow the target specified by the MSVC toolchain.
if self.info.is_windows():
if self.arch == 'x86_64':
if self.is_cross:
return [f'-mtriple={self.arch}-windows-msvc']
elif self.arch == 'x86_64':
return ['-m64']
return ['-m32']
return []
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,8 @@ def detect_d_compiler(env: 'Environment', for_machine: MachineChoice) -> Compile

return cls(
exelist, version, for_machine, info, arch,
full_version=full_version, linker=linker, version_output=out)
full_version=full_version, linker=linker,
is_cross=is_cross, version_output=out)
elif 'gdc' in out:
cls = d.GnuDCompiler
linker = guess_nix_linker(env, exelist, cls, version, for_machine)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
mode = CompileCheckMode.LINK
if self.is_cross:
binname += '_cross'
if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
if not environment.has_exe_wrapper():
# Linking cross built C/C++ apps is painful. You can't really
# tell if you should use -nostdlib or not and for example
# on OSX the compiler binary is the same but you need
Expand Down Expand Up @@ -308,7 +308,7 @@ def _sanity_check_impl(self, work_dir: str, environment: 'Environment',
if pc.returncode != 0:
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
# Run sanity check
if environment.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
self._native_static_libs(work_dir, source_name)
if environment.need_exe_wrapper(self.for_machine):
if self.is_cross:
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def machine_info_can_run(machine_info: MachineInfo):
if machine_info.system != detect_system():
return False
true_build_cpu_family = detect_cpu_family({})
assert machine_info.cpu_family is not None, 'called on incomplete machine_info'
return \
(machine_info.cpu_family == true_build_cpu_family) or \
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \
Expand Down

0 comments on commit 6f88e48

Please sign in to comment.