From e430c01ef51f0fabba8bd6170287c42f718e7854 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 10 Nov 2020 12:05:47 -0800 Subject: [PATCH 1/3] compilers/rust: Add vs_crt support As far as I can Tell, rust just handles this for us (it's always worked with no special arguments from us). However, since we're going to add support for base options for rust, we need to add the method. --- mesonbuild/compilers/rust.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 469859bfe..3b392ec51 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -52,6 +52,8 @@ class RustCompiler(Compiler): linker=linker) self.exe_wrapper = exe_wrapper self.id = 'rustc' + if 'link' in self.linker.id: + self.base_options.append('b_vscrt') def needs_static_linker(self) -> bool: return False @@ -141,3 +143,7 @@ class RustCompiler(Compiler): if std.value != 'none': args.append('--edition=' + std.value) return args + + def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: + # Rust handles this for us, we don't need to do anything + return [] From a28b430b681f790122415a371382565d19ea947b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 10 Nov 2020 09:48:21 -0800 Subject: [PATCH 2/3] ninjabackend: apply base compile_args to rust targets --- mesonbuild/backend/ninjabackend.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 09f06daa3..daada12b2 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1494,6 +1494,10 @@ int dummy; # Rust compiler takes only the main file as input and # figures out what other files are needed via import # statements and magic. + base_proxy = self.get_base_options_for_target(target) + args = rustc.compiler_args() + # Compiler args for compiling this target + args += compilers.get_base_compile_args(base_proxy, rustc) main_rust_file = None for i in target.get_sources(): if not rustc.can_compile(i): @@ -1503,7 +1507,6 @@ int dummy; if main_rust_file is None: raise RuntimeError('A Rust target has no Rust sources. This is weird. Also a bug. Please report') target_name = os.path.join(target.subdir, target.get_filename()) - args = ['--crate-type'] if isinstance(target, build.Executable): cratetype = 'bin' elif hasattr(target, 'rust_crate_type'): @@ -1514,7 +1517,7 @@ int dummy; cratetype = 'rlib' else: raise InvalidArguments('Unknown target type for rustc.') - args.append(cratetype) + args.extend(['--crate-type', cratetype]) # If we're dynamically linking, add those arguments # From ce46070b4ee69fe573ff4105d06b970445fea0aa Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 10 Nov 2020 09:38:41 -0800 Subject: [PATCH 3/3] compilers/rust: Add color output Rust has color output, although it's help doesn't document it. It uses the same values as cargo (and everything else), auto, never, always. --- mesonbuild/compilers/rust.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 3b392ec51..1be0cd8a7 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -17,7 +17,7 @@ import textwrap import typing as T from .. import coredata -from ..mesonlib import EnvironmentException, MachineChoice, Popen_safe +from ..mesonlib import EnvironmentException, MachineChoice, MesonException, Popen_safe from .compilers import Compiler, rust_buildtype_args, clike_debug_args if T.TYPE_CHECKING: @@ -52,6 +52,7 @@ class RustCompiler(Compiler): linker=linker) self.exe_wrapper = exe_wrapper self.id = 'rustc' + self.base_options.append('b_colorout') if 'link' in self.linker.id: self.base_options.append('b_vscrt') @@ -147,3 +148,8 @@ class RustCompiler(Compiler): def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: # Rust handles this for us, we don't need to do anything return [] + + def get_colorout_args(self, colortype: str) -> T.List[str]: + if colortype in {'always', 'never', 'auto'}: + return [f'--color={colortype}'] + raise MesonException(f'Invalid color type for rust {colortype}')