diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-01 18:56:07 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-01 18:56:07 +0300 |
commit | 46ce7a9d4ba3eb10f310657242524053a96e5ed9 (patch) | |
tree | 8797ab81fb97ea3e1f51b20a6846f1036877796e | |
parent | 2e2df70dd041a632f4fa7460066c2cc222877210 (diff) | |
parent | 2bdaa1f0c181511fab143eccf68c77fcc60c46e2 (diff) | |
download | meson-46ce7a9d4ba3eb10f310657242524053a96e5ed9.zip meson-46ce7a9d4ba3eb10f310657242524053a96e5ed9.tar.gz meson-46ce7a9d4ba3eb10f310657242524053a96e5ed9.tar.bz2 |
Merge pull request #516 from centricular/cross-compile_32bit-x86_on_64bit-x86_exe-wrapper
Special-case the 32-bit executable on 64-bit x86 case while cross-compiling
-rw-r--r-- | mesonbuild/backend/backends.py | 9 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 8 | ||||
-rw-r--r-- | mesonbuild/environment.py | 63 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 29 |
4 files changed, 81 insertions, 28 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 19f50ad..7c6caa6 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -357,7 +357,9 @@ class Backend(): fname = exe.fullpath else: fname = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(t.get_exe()))] - is_cross = self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler() + is_cross = self.environment.is_cross_build() and \ + self.environment.cross_info.need_cross_compiler() and \ + self.environment.cross_info.need_exe_wrapper() if is_cross: exe_wrapper = self.environment.cross_info.config['binaries'].get('exe_wrapper', None) else: @@ -408,8 +410,9 @@ class Backend(): def exe_object_to_cmd_array(self, exe): if self.environment.is_cross_build() and \ - isinstance(exe, build.BuildTarget) and exe.is_cross: - if 'exe_wrapper' not in self.environment.cross_info: + self.environment.cross_info.need_exe_wrapper() and \ + isinstance(exe, build.BuildTarget) and exe.is_cross: + if 'exe_wrapper' not in self.environment.cross_info.config: s = 'Can not use target %s as a generator because it is cross-built\n' s += 'and no exe wrapper is defined. You might want to set it to native instead.' s = s % exe.name diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5a21a6c..ce8968c 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -409,9 +409,11 @@ int dummy; if isinstance(texe, build.Executable): abs_exe = os.path.join(self.environment.get_build_dir(), self.get_target_filename(texe)) deps.append(self.get_target_filename(texe)) - if self.environment.is_cross_build() \ - and self.environment.cross_info.config['binaries'].get('exe_wrapper', None) is not None: - cmd += [self.environment.cross_info.config['binaries']['exe_wrapper']] + if self.environment.is_cross_build() and \ + self.environment.cross_info.need_exe_wrapper(): + exe_wrap = self.environment.cross_info.config['binaries'].get('exe_wrapper', None) + if exe_wrap is not None: + cmd += [exe_wrap] cmd.append(abs_exe) else: cmd.append(target.command) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index a0f410a..41e8531 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os, re, subprocess +import os, re, subprocess, platform from . import coredata, mesonlib from .compilers import * import configparser @@ -52,6 +52,33 @@ def detect_ninja(): if p.returncode == 0: return n +def detect_cpu_family(): + """ + Python is inconsistent in its platform module. + It returns different values for the same cpu. + For x86 it might return 'x86', 'i686' or somesuch. + Do some canonicalization. + """ + trial = platform.machine().lower() + if trial.startswith('i') and trial.endswith('86'): + return 'x86' + if trial.startswith('arm'): + return 'arm' + if trial == 'amd64': + return 'x86_64' + # Add fixes here as bugs are reported. + return trial + +def detect_cpu(): + trial = platform.machine().lower() + if trial == 'amd64': + return 'x86_64' + # Add fixes here as bugs are reported. + return trial + +def detect_system(): + return platform.system().lower() + class Environment(): private_dir = 'meson-private' @@ -182,7 +209,10 @@ class Environment(): compilers = [self.cross_info.config['binaries']['c']] ccache = [] is_cross = True - exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None) + if self.cross_info.need_exe_wrapper(): + exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None) + else: + exe_wrap = [] elif evar in os.environ: compilers = os.environ[evar].split() ccache = [] @@ -247,7 +277,10 @@ class Environment(): if self.is_cross_build() and want_cross: compilers = [self.cross_info['fortran']] is_cross = True - exe_wrap = self.cross_info.get('exe_wrapper', None) + if self.cross_info.need_exe_wrapper(): + exe_wrap = self.cross_info.get('exe_wrapper', None) + else: + exe_wrap = [] elif evar in os.environ: compilers = os.environ[evar].split() is_cross = False @@ -322,7 +355,10 @@ class Environment(): compilers = [self.cross_info.config['binaries']['cpp']] ccache = [] is_cross = True - exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None) + if self.cross_info.need_exe_wrapper(): + exe_wrap = self.cross_info.config['binaries'].get('exe_wrapper', None) + else: + exe_wrap = [] elif evar in os.environ: compilers = os.environ[evar].split() ccache = [] @@ -385,7 +421,10 @@ class Environment(): if self.is_cross_build() and want_cross: exelist = [self.cross_info['objc']] is_cross = True - exe_wrap = self.cross_info.get('exe_wrapper', None) + if self.cross_info.need_exe_wrapper(): + exe_wrap = self.cross_info.get('exe_wrapper', None) + else: + exe_wrap = [] else: exelist = self.get_objc_compiler_exelist() is_cross = False @@ -415,7 +454,10 @@ class Environment(): if self.is_cross_build() and want_cross: exelist = [self.cross_info['objcpp']] is_cross = True - exe_wrap = self.cross_info.get('exe_wrapper', None) + if self.cross_info.need_exe_wrapper(): + exe_wrap = self.cross_info.get('exe_wrapper', None) + else: + exe_wrap = [] else: exelist = self.get_objcpp_compiler_exelist() is_cross = False @@ -721,3 +763,12 @@ class CrossBuildInfo(): # But not when cross compiling a cross compiler. def need_cross_compiler(self): return 'host_machine' in self.config + + def need_exe_wrapper(self): + if self.has_host() and detect_cpu_family() == 'x86_64' and \ + self.config['host_machine']['cpu_family'] == 'x86' and \ + self.config['host_machine']['system'] == detect_system(): + # Can almost always run 32-bit binaries on 64-bit natively if the + # host and build systems are the same + return False + return True diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index d6a3a3e..e51692e 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -322,24 +322,14 @@ class BuildMachine(InterpreterObject): 'endian' : self.endian_method, }) - # Python is inconsistent in its platform module. - # It returns different values for the same cpu. - # For x86 it might return 'x86', 'i686' or somesuch. - # Do some canonicalization. def cpu_family_method(self, args, kwargs): - trial = platform.machine().lower() - if trial.startswith('i') and trial.endswith('86'): - return 'x86' - if trial.startswith('arm'): - return 'arm' - # Add fixes here as bugs are reported. - return trial + return environment.detect_cpu_family() def cpu_method(self, args, kwargs): - return platform.machine().lower() + return environment.detect_cpu() def system_method(self, args, kwargs): - return platform.system().lower() + return environment.detect_system() def endian_method(self, args, kwargs): return sys.byteorder @@ -883,9 +873,16 @@ class MesonMain(InterpreterObject): return self.interpreter.environment.build_dir def has_exe_wrapper_method(self, args, kwargs): - if self.is_cross_build_method(None, None) and 'binaries' in self.build.environment.cross_info.config: - return 'exe_wrap' in self.build.environment.cross_info.config['binaries'] - return True # This is semantically confusing. + if self.is_cross_build_method(None, None) and \ + 'binaries' in self.build.environment.cross_info.config and \ + self.build.environment.cross_info.need_exe_wrapper(): + exe_wrap = self.build.environment.cross_info.config['binaries'].get('exe_wrap', None) + if exe_wrap is None: + return False + # We return True when exe_wrap is defined, when it's not needed, and + # when we're compiling natively. The last two are semantically confusing. + # Need to revisit this. + return True def is_cross_build_method(self, args, kwargs): return self.build.environment.is_cross_build() |