From 3ae115b57ad7f8eca09c03f5bd6bf65604dcaf59 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 19 Jan 2021 10:12:38 -0800 Subject: Replace NinjaBackend is_rust_target with build.uses_rust we have two functions to do the exact same thing, and they're basically implemented the same way. Instead, let's just use the BuildTarget one, as it's more generally available. --- mesonbuild/backend/ninjabackend.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index d66708c..d3350bb 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -691,13 +691,6 @@ int dummy; src_block['sources'] += sources src_block['generated_sources'] += generated_sources - def is_rust_target(self, target): - if len(target.sources) > 0: - first_file = target.sources[0] - if first_file.fname.endswith('.rs'): - return True - return False - def generate_target(self, target): try: if isinstance(target, build.BuildTarget): @@ -723,7 +716,7 @@ int dummy; if isinstance(target, build.Jar): self.generate_jar_target(target) return - if self.is_rust_target(target): + if target.uses_rust(): self.generate_rust_target(target) return if 'cs' in target.compilers: -- cgit v1.1 From bff0b415250b4f4f7cd750b60e6c01daaa61af15 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 5 Jan 2021 15:55:02 -0800 Subject: rust: Accept generated sources for main.rs There are still caveats here. Rust/cargo handles generated sources by writing out all targets of a single repo into a single output directory, setting a path to that via a build-time environment variable, and then include those files via a set of functions and macros. Meson's build layout is naturally different, and ninja makes working with environment variables at compile time difficult. Fixes #8157 --- mesonbuild/backend/ninjabackend.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index d3350bb..9f2e649 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -45,7 +45,7 @@ from ..mesonlib import ( ) from ..mesonlib import get_compiler_for_source, has_path_sep, OptionKey from .backends import CleanTrees -from ..build import InvalidArguments +from ..build import GeneratedList, InvalidArguments from ..interpreter import Interpreter if T.TYPE_CHECKING: @@ -1581,12 +1581,23 @@ int dummy; args = rustc.compiler_args() # Compiler args for compiling this target args += compilers.get_base_compile_args(base_proxy, rustc) + self.generate_generator_list_rules(target) main_rust_file = None for i in target.get_sources(): if not rustc.can_compile(i): raise InvalidArguments('Rust target {} contains a non-rust source file.'.format(target.get_basename())) if main_rust_file is None: main_rust_file = i.rel_to_builddir(self.build_to_src) + for g in target.get_generated_sources(): + for i in g.get_outputs(): + if not rustc.can_compile(i): + raise InvalidArguments('Rust target {} contains a non-rust source file.'.format(target.get_basename())) + if isinstance(g, GeneratedList): + fname = os.path.join(self.get_target_private_dir(target), i) + else: + fname = i + if main_rust_file is None: + main_rust_file = fname 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()) -- cgit v1.1 From caa6d5e16b6b12f64269246e83d29e2189bb5e92 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 6 Jan 2021 11:56:52 -0800 Subject: backend/ninja: Add order dependencies for generated sources in rust --- mesonbuild/backend/ninjabackend.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mesonbuild/backend') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 9f2e649..c1c4c93 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1582,6 +1582,9 @@ int dummy; # Compiler args for compiling this target args += compilers.get_base_compile_args(base_proxy, rustc) self.generate_generator_list_rules(target) + + orderdeps = [os.path.join(t.subdir, t.get_filename()) for t in target.link_targets] + main_rust_file = None for i in target.get_sources(): if not rustc.can_compile(i): @@ -1598,6 +1601,7 @@ int dummy; fname = i if main_rust_file is None: main_rust_file = fname + orderdeps.append(fname) 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()) @@ -1635,7 +1639,6 @@ int dummy; args += target.get_extra_args('rust') args += rustc.get_output_args(os.path.join(target.subdir, target.get_filename())) args += self.environment.coredata.get_external_args(target.for_machine, rustc.language) - orderdeps = [os.path.join(t.subdir, t.get_filename()) for t in target.link_targets] linkdirs = OrderedDict() for d in target.link_targets: linkdirs[d.subdir] = True @@ -1682,7 +1685,7 @@ int dummy; args += ['-C', 'link-arg=' + rpath_arg + ':' + os.path.join(rustc.get_sysroot(), 'lib')] compiler_name = self.get_compiler_rule_name('rust', target.for_machine) element = NinjaBuildElement(self.all_outputs, target_name, compiler_name, main_rust_file) - if len(orderdeps) > 0: + if orderdeps: element.add_orderdep(orderdeps) element.add_item('ARGS', args) element.add_item('targetdep', depfile) -- cgit v1.1