Skip to content

Commit

Permalink
compilers/rust: add and use an implementation of use_linker_args
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Nov 13, 2020
1 parent 5c74ccc commit 5afd608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
def get_output_args(self, outputname: str) -> T.List[str]:
return ['-o', outputname]

@classmethod
def use_linker_args(cls, linker: str) -> T.List[str]:
return ['-C', 'linker={}'.format(linker)]

# Rust does not have a use_linker_args because it dispatches to a gcc-like
# C compiler for dynamic linking, as such we invoke the C compiler's
# use_linker_args method instead.
Expand Down
14 changes: 7 additions & 7 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,12 +1655,12 @@ def detect_rust_compiler(self, for_machine: MachineChoice) -> RustCompiler:
extra_args = {}
always_args = []
if is_link_exe:
compiler.extend(['-C', 'linker={}'.format(cc.linker.exelist[0])])
compiler.extend(RustCompiler.use_linker_args(cc.linker.exelist[0]))
extra_args['direct'] = True
extra_args['machine'] = cc.linker.machine
else:
c = cc.linker.exelist[1] if cc.linker.exelist[0].endswith('ccache') else cc.linker.exelist[0]
compiler.extend(['-C', 'linker={}'.format(c)])
compiler.extend(RustCompiler.use_linker_args(c))

# This trickery with type() gets us the class of the linker
# so we can initialize a new copy for the Rust Compiler
Expand All @@ -1677,21 +1677,21 @@ def detect_rust_compiler(self, for_machine: MachineChoice) -> RustCompiler:
# rustc takes linker arguments without a prefix, and
# inserts the correct prefix itself.
linker.direct = True
compiler.extend(['-C', 'linker={}'.format(linker.exelist[0])])
compiler.extend(RustCompiler.use_linker_args(linker.exelist[0]))
else:
# We're creating a new type of "C" compiler, that has rust
# as it's language. This is gross, but I can't figure out
# another way to handle this, because rustc is actually
# invoking the c compiler as it's linker.
breakpoint()
b = type('b', (type(cc), ), {})
b.language = RustCompiler.language
linker = self._guess_nix_linker(cc.exelist, b, for_machine)
linker = self._guess_nix_linker(override, b, for_machine)
linker = cc.linker

# Of course, we're not going to use any of that, we just
# need it to get the proper arguments to pass to rustc
c = cc.exelist[1] if cc.exelist[0].endswith('ccache') else cc.exelist[0]
compiler.extend(['-C', 'linker={}'.format(c)])
compiler.extend(['-C', 'link-args={}'.format(' '.join(cc.use_linker_args(override[0])))])
compiler.extend(RustCompiler.use_linker_args(c))

self.coredata.add_lang_args(RustCompiler.language, RustCompiler, for_machine, self)
return RustCompiler(
Expand Down

0 comments on commit 5afd608

Please sign in to comment.