diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-09-16 14:40:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-16 14:40:55 +0300 |
commit | b9f229a4940999fd2976e64aa8a51358cce52fdb (patch) | |
tree | 4a60e54787f0920c772b9e7fc144847b559f2ac1 | |
parent | 0e89b03be63c8b0a4ffb530cc20dc29aa01844db (diff) | |
parent | 5b0ad0f8adfa9c64def004bc96e931f1df803bc2 (diff) | |
download | meson-b9f229a4940999fd2976e64aa8a51358cce52fdb.zip meson-b9f229a4940999fd2976e64aa8a51358cce52fdb.tar.gz meson-b9f229a4940999fd2976e64aa8a51358cce52fdb.tar.bz2 |
Merge pull request #4175 from GoaLitiuM/d-archfixes
D: Improve target architecture handling
-rw-r--r-- | mesonbuild/compilers/d.py | 27 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 65 | ||||
-rw-r--r-- | mesonbuild/environment.py | 20 |
3 files changed, 61 insertions, 51 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 3d46390..6108e93 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -68,12 +68,12 @@ class DCompiler(Compiler): 'mtd': ['-mscrtlib=libcmtd'], } - def __init__(self, exelist, version, is_cross, is_64, **kwargs): + def __init__(self, exelist, version, is_cross, arch, **kwargs): self.language = 'd' super().__init__(exelist, version, **kwargs) self.id = 'unknown' self.is_cross = is_cross - self.is_64 = is_64 + self.arch = arch def sanity_check(self, work_dir, environment): source_name = os.path.join(work_dir, 'sanity.d') @@ -274,7 +274,7 @@ class DCompiler(Compiler): # LDC2 on Windows targets to current OS architecture, but # it should follow the target specified by the MSVC toolchain. if is_windows(): - if self.is_64: + if self.arch == 'x86_64': return ['-m64'] return ['-m32'] return [] @@ -410,8 +410,8 @@ class DCompiler(Compiler): return [] class GnuDCompiler(DCompiler): - def __init__(self, exelist, version, is_cross, is_64, **kwargs): - DCompiler.__init__(self, exelist, version, is_cross, is_64, **kwargs) + def __init__(self, exelist, version, is_cross, arch, **kwargs): + DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs) self.id = 'gcc' default_warn_args = ['-Wall', '-Wdeprecated'] self.warn_args = {'1': default_warn_args, @@ -465,8 +465,8 @@ class GnuDCompiler(DCompiler): return gnu_optimization_args[optimization_level] class LLVMDCompiler(DCompiler): - def __init__(self, exelist, version, is_cross, is_64, **kwargs): - DCompiler.__init__(self, exelist, version, is_cross, is_64, **kwargs) + def __init__(self, exelist, version, is_cross, arch, **kwargs): + DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs) self.id = 'llvm' self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt'] @@ -501,11 +501,10 @@ class LLVMDCompiler(DCompiler): class DmdDCompiler(DCompiler): - def __init__(self, exelist, version, is_cross, is_64, **kwargs): - DCompiler.__init__(self, exelist, version, is_cross, is_64, **kwargs) + def __init__(self, exelist, version, is_cross, arch, **kwargs): + DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs) self.id = 'dmd' self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt'] - self.is_msvc = 'VCINSTALLDIR' in os.environ def get_colorout_args(self, colortype): if colortype == 'always': @@ -521,9 +520,9 @@ class DmdDCompiler(DCompiler): if is_windows(): # DMD links against D runtime only when main symbol is found, # so these needs to be inserted when linking static D libraries. - if self.is_64: + if self.arch == 'x86_64': return ['phobos64.lib'] - elif self.is_msvc: + elif self.arch == 'x86_mscoff': return ['phobos32mscoff.lib'] return ['phobos.lib'] return [] @@ -536,9 +535,9 @@ class DmdDCompiler(DCompiler): # Force the target to 64-bit in order to stay consistent # across the different platforms. if is_windows(): - if self.is_64: + if self.arch == 'x86_64': return ['-m64'] - elif self.is_msvc: + elif self.arch == 'x86_mscoff': return ['-m32mscoff'] return ['-m32'] return [] diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index a34ebf7..a80423f 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -870,11 +870,8 @@ class DubDependency(ExternalDependency): mlog.debug('Determining dependency {!r} with DUB executable ' '{!r}'.format(name, self.dubbin.get_path())) - # we need to know the correct architecture on Windows - if self.compiler.is_64: - arch = 'x86_64' - else: - arch = 'x86' + # we need to know the target architecture + arch = self.compiler.arch # Ask dub for the package ret, res = self._call_dubbin(['describe', name, '--arch=' + arch]) @@ -885,8 +882,8 @@ class DubDependency(ExternalDependency): comp = self.compiler.get_id().replace('llvm', 'ldc').replace('gcc', 'gdc') packages = [] - j = json.loads(res) - for package in j['packages']: + description = json.loads(res) + for package in description['packages']: packages.append(package['name']) if package['name'] == name: self.is_found = True @@ -897,14 +894,24 @@ class DubDependency(ExternalDependency): not_lib = False if not_lib: - mlog.error(mlog.bold(name), 'found but it isn\'t a library') + mlog.error(mlog.bold(name), "found but it isn't a library") self.is_found = False return - self.module_path = self._find_right_lib_path(package['path'], comp, j, True, package['targetFileName']) - + self.module_path = self._find_right_lib_path(package['path'], comp, description, True, package['targetFileName']) if not os.path.exists(self.module_path): - mlog.error(mlog.bold(name), 'found but it wasn\'t compiled with', mlog.bold(comp)) + # check if the dependency was built for other archs + archs = [['x86_64'], ['x86'], ['x86', 'x86_mscoff']] + for a in archs: + description_a = copy.deepcopy(description) + description_a['architecture'] = a + arch_module_path = self._find_right_lib_path(package['path'], comp, description_a, True, package['targetFileName']) + if arch_module_path: + mlog.error(mlog.bold(name), "found but it wasn't compiled for", mlog.bold(arch)) + self.is_found = False + return + + mlog.error(mlog.bold(name), "found but it wasn't compiled with", mlog.bold(comp)) self.is_found = False return @@ -943,26 +950,29 @@ class DubDependency(ExternalDependency): for arg in pkgdep.get_link_args(raw=True): self.raw_link_args.append(arg) - for target in j['targets']: + for target in description['targets']: if target['rootPackage'] in packages: add_lib_args('libs', target) add_lib_args('libs-{}'.format(platform.machine()), target) for file in target['buildSettings']['linkerFiles']: - self.link_args.append(self._find_right_lib_path(file, comp, j)) + lib_path = self._find_right_lib_path(file, comp, description) + if lib_path: + self.link_args.append(lib_path) + else: + self.is_found = False def get_compiler(self): return self.compiler - def _find_right_lib_path(self, default_path, comp, j, folder_only=False, file_name=''): - path = '' - - module_build_path = lib_file_name = '' + def _find_right_lib_path(self, default_path, comp, description, folder_only=False, file_name=''): + module_path = lib_file_name = '' if folder_only: - module_build_path = default_path + module_path = default_path lib_file_name = file_name else: - module_build_path = os.path.dirname(default_path) + module_path = os.path.dirname(default_path) lib_file_name = os.path.basename(default_path) + module_build_path = os.path.join(module_path, '.dub', 'build') # Get D version implemented in the compiler # gdc doesn't support this @@ -970,7 +980,6 @@ class DubDependency(ExternalDependency): if ret != 0: mlog.error('Failed to run {!r}', mlog.bold(comp)) - self.is_found = False return d_ver = re.search('v[0-9].[0-9][0-9][0-9].[0-9]', res) # Ex.: v2.081.2 @@ -979,19 +988,21 @@ class DubDependency(ExternalDependency): else: d_ver = '' # gdc + if not os.path.isdir(module_build_path): + return '' + # Ex.: library-debug-linux.posix-x86_64-ldc_2081-EF934983A3319F8F8FF2F0E107A363BA - build_name = 'library-{}-{}-{}-{}_{}'.format(j['buildType'], '.'.join(j['platform']), j['architecture'][0], comp, d_ver) - for entry in os.listdir(os.path.join(module_build_path, '.dub', 'build')): + build_name = 'library-{}-{}-{}-{}_{}'.format(description['buildType'], '.'.join(description['platform']), '.'.join(description['architecture']), comp, d_ver) + for entry in os.listdir(module_build_path): if entry.startswith(build_name): - for file in os.listdir(os.path.join(module_build_path, '.dub', 'build', entry)): + for file in os.listdir(os.path.join(module_build_path, entry)): if file == lib_file_name: if folder_only: - path = os.path.join(module_build_path, '.dub', 'build', entry) + return os.path.join(module_build_path, entry) else: - path = os.path.join(module_build_path, '.dub', 'build', entry, lib_file_name) - break + return os.path.join(module_build_path, entry, lib_file_name) - return path + return '' def _call_dubbin(self, args, env=None): p, out = Popen_safe(self.dubbin.get_command() + args, env=env)[0:2] diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 35e934a..81ba54c 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -829,22 +829,22 @@ This is probably wrong, it should always point to the native compiler.''' % evar version = search_version(out) full_version = out.split('\n', 1)[0] - # Detect which MSVC build environment is currently active. - is_64 = False + # Detect the target architecture, required for proper architecture handling on Windows. c_compiler = {} - if mesonlib.is_windows() and 'VCINSTALLDIR' in os.environ: - # MSVC compiler is required for correct platform detection. - c_compiler = {'c': self.detect_c_compiler(want_cross)} + is_msvc = mesonlib.is_windows() and 'VCINSTALLDIR' in os.environ + if is_msvc: + c_compiler = {'c': self.detect_c_compiler(want_cross)} # MSVC compiler is required for correct platform detection. - if detect_cpu_family(c_compiler) == 'x86_64': - is_64 = True + arch = detect_cpu_family(c_compiler) + if is_msvc and arch == 'x86': + arch = 'x86_mscoff' if 'LLVM D compiler' in out: - return compilers.LLVMDCompiler(exelist, version, is_cross, is_64, full_version=full_version) + return compilers.LLVMDCompiler(exelist, version, is_cross, arch, full_version=full_version) elif 'gdc' in out: - return compilers.GnuDCompiler(exelist, version, is_cross, is_64, full_version=full_version) + return compilers.GnuDCompiler(exelist, version, is_cross, arch, full_version=full_version) elif 'The D Language Foundation' in out or 'Digital Mars' in out: - return compilers.DmdDCompiler(exelist, version, is_cross, is_64, full_version=full_version) + return compilers.DmdDCompiler(exelist, version, is_cross, arch, full_version=full_version) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') def detect_swift_compiler(self): |