diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-07-21 18:55:08 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-07-29 21:58:47 +0300 |
| commit | 394b218be7945d8ea4b291cc7955b9f7e8c12536 (patch) | |
| tree | fd0cfeabc9470113276079db10ad1994863b7cbc | |
| parent | c15f3cb28f65bf74be6a801e3e6587267466a502 (diff) | |
| download | meson-394b218be7945d8ea4b291cc7955b9f7e8c12536.tar.gz | |
build: allow non-Rust files in non-structured sources
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/backend/ninjabackend.py | 1 | ||||
| -rw-r--r-- | mesonbuild/build.py | 12 | ||||
| -rw-r--r-- | test cases/rust/28 mixed/meson.build | 6 |
3 files changed, 15 insertions, 4 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 1780e96e9..52063866b 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1980,6 +1980,7 @@ class NinjaBackend(backends.Backend): for s in f.get_outputs()]) self.all_structured_sources.update(_ods) orderdeps.extend(_ods) + return orderdeps, main_rust_file for i in target.get_sources(): if main_rust_file is None: diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 4f581de31..410b4d243 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -771,18 +771,22 @@ class BuildTarget(Target): ''' Initialisations and checks requiring the final list of compilers to be known ''' self.validate_sources() - if self.structured_sources and any([self.sources, self.generated]): - raise MesonException('cannot mix structured sources and unstructured sources') - if self.structured_sources and 'rust' not in self.compilers: - raise MesonException('structured sources are only supported in Rust targets') if self.uses_rust(): if self.link_language and self.link_language != 'rust': raise MesonException('cannot build Rust sources with a different link_language') + if self.structured_sources: + # TODO: the interpreter should be able to generate a better error message? + if any((s.endswith('.rs') for s in self.sources)) or \ + any(any((s.endswith('.rs') for s in g.get_outputs())) for g in self.generated): + raise MesonException('cannot mix Rust structured sources and unstructured sources') # relocation-model=pic is rustc's default and Meson does not # currently have a way to disable PIC. self.pic = True self.pie = True + else: + if self.structured_sources: + raise MesonException('structured sources are only supported in Rust targets') if 'vala' in self.compilers and self.is_linkable_target(): self.outputs += [self.vala_header, self.vala_vapi] diff --git a/test cases/rust/28 mixed/meson.build b/test cases/rust/28 mixed/meson.build index b00d8ac88..fac3d466f 100644 --- a/test cases/rust/28 mixed/meson.build +++ b/test cases/rust/28 mixed/meson.build @@ -2,5 +2,11 @@ project('mixed', ['cpp', 'rust']) e1 = executable('mixed', 'hello.rs', 'main.cc') +e2 = executable('mixed-structured', structured_sources('hello.rs'), 'main.cc') + +hello2 = import('fs').copyfile('hello.rs', 'hello2.rs') +e3 = executable('mixed-structured-gen', structured_sources(hello2), 'main.cc') test('mixed', e1) +test('mixed-structured', e2) +test('mixed-structured-gen', e3) |
