diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index e56d18d8d..d02f2ddbe 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -567,28 +567,41 @@ class Backend: args.append(d_arg) return args - def determine_windows_extra_paths(self, target, extra_bdeps): + def get_mingw_extra_paths(self): + paths = [] + # The cross bindir + root = self.environment.cross_info.get_root() + if root: + paths.append(os.path.join(root, 'bin')) + # The toolchain bindir + sys_root = self.environment.cross_info.get_sys_root() + if sys_root: + paths.append(os.path.join(sys_root, 'bin')) + return paths + + def determine_windows_extra_paths(self, target, extra_bdeps, is_cross=False): '''On Windows there is no such thing as an rpath. We must determine all locations of DLLs that this exe links to and return them so they can be used in unit tests.''' - result = [] - prospectives = [] + result = set() + prospectives = set() if isinstance(target, build.BuildTarget): - prospectives = target.get_transitive_link_deps() + prospectives.update(target.get_transitive_link_deps()) # External deps for deppath in self.rpaths_for_bundled_shared_libraries(target): - result.append(os.path.normpath(os.path.join(self.environment.get_build_dir(), deppath))) + result.add(os.path.normpath(os.path.join(self.environment.get_build_dir(), deppath))) for bdep in extra_bdeps: - prospectives += bdep.get_transitive_link_deps() + prospectives.update(bdep.get_transitive_link_deps()) # Internal deps for ld in prospectives: if ld == '' or ld == '.': continue dirseg = os.path.join(self.environment.get_build_dir(), self.get_target_dir(ld)) - if dirseg not in result: - result.append(dirseg) - return result + result.add(dirseg) + if is_cross: + result.update(self.get_mingw_extra_paths()) + return list(result) def write_benchmark_file(self, datafile): self.write_test_serialisation(self.build.get_benchmarks(), datafile) @@ -622,7 +635,7 @@ class Backend: extra_bdeps = [] if isinstance(exe, build.CustomTarget): extra_bdeps = exe.get_transitive_build_target_deps() - extra_paths = self.determine_windows_extra_paths(exe, extra_bdeps) + extra_paths = self.determine_windows_extra_paths(exe, extra_bdeps, is_cross) else: extra_paths = [] cmd_args = [] diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 6082c8502..423c2ff36 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -536,7 +536,8 @@ int dummy; if mesonlib.for_windows(is_cross, self.environment) or \ mesonlib.for_cygwin(is_cross, self.environment): extra_bdeps = target.get_transitive_build_target_deps() - extra_paths = self.determine_windows_extra_paths(target.command[0], extra_bdeps) + extra_paths = self.determine_windows_extra_paths(target.command[0], + extra_bdeps, is_cross) if extra_paths: serialize = True if serialize: diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 37bfe6037..6339570d8 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -1045,6 +1045,12 @@ class CrossBuildInfo: def get_properties(self): return self.config['properties'] + def get_root(self): + return self.get_properties().get('root', None) + + def get_sys_root(self): + return self.get_properties().get('sys_root', None) + # When compiling a cross compiler we use the native compiler for everything. # But not when cross compiling a cross compiler. def need_cross_compiler(self):