Skip to content

Commit

Permalink
Merge pull request #4724 from jon-turney/lib-machine-always
Browse files Browse the repository at this point in the history
Fix linking when cross-compiling and a windows resource is first object
  • Loading branch information
jpakkane authored Mar 19, 2019
2 parents 3d0b110 + a223b20 commit 44dd553
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
9 changes: 8 additions & 1 deletion mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,13 @@ def __init__(self, exelist, version, is_cross, exe_wrap, target):
self.base_options = ['b_pch', 'b_ndebug', 'b_vscrt'] # FIXME add lto, pgo and the like
self.target = target
self.is_64 = ('x64' in target) or ('x86_64' in target)
# do some canonicalization of target machine
if 'x86_64' in target:
self.machine = 'x64'
elif '86' in target:
self.machine = 'x86'
else:
self.machine = target

# Override CCompiler.get_always_args
def get_always_args(self):
Expand Down Expand Up @@ -1475,7 +1482,7 @@ def get_linker_always_args(self):
return ['/nologo']

def get_linker_output_args(self, outputname):
return ['/OUT:' + outputname]
return ['/MACHINE:' + self.machine, '/OUT:' + outputname]

def get_linker_search_args(self, dirname):
return ['/LIBPATH:' + dirname]
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def detect_static_linker(self, compiler):
popen_exceptions[' '.join(linker + [arg])] = e
continue
if '/OUT:' in out.upper() or '/OUT:' in err.upper():
return VisualStudioLinker(linker)
return VisualStudioLinker(linker, getattr(compiler, 'machine', None))
if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker):
return ArmarLinker(linker)
if 'DMD32 D Compiler' in out or 'DMD64 D Compiler' in out:
Expand Down
9 changes: 7 additions & 2 deletions mesonbuild/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def can_linker_accept_rsp(self):
class VisualStudioLinker(StaticLinker):
always_args = ['/NOLOGO']

def __init__(self, exelist):
def __init__(self, exelist, machine):
self.exelist = exelist
self.machine = machine

def get_exelist(self):
return self.exelist[:]
Expand All @@ -39,7 +40,11 @@ def get_buildtype_linker_args(self, buildtype):
return []

def get_output_args(self, target):
return ['/OUT:' + target]
args = []
if self.machine:
args += ['/MACHINE:' + self.machine]
args += ['/OUT:' + target]
return args

def get_coverage_link_args(self):
return []
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions test cases/windows/5 resources/res/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ win = import('windows')
res = win.compile_resources('myres.rc',
depend_files: 'sample.ico',
include_directories : inc)

# test that with MSVC tools, LIB/LINK invokes CVTRES with correct /MACHINE
static_library('reslib', res, 'dummy.c')
shared_library('shreslib', res, 'dummy.c')

0 comments on commit 44dd553

Please sign in to comment.