summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-10-03 13:47:04 +0200
committerDylan Baker <dylan@pnwbakers.com>2025-10-03 09:51:12 -0700
commit457404668579cc04697912d2863df0ec62f3fabf (patch)
tree92ab408e527ec91cd11a9458bd6d9fb02e1a0146
parentaa5f38185495100fe9d53b6358d8d7cfa8a6388d (diff)
downloadmeson-457404668579cc04697912d2863df0ec62f3fabf.tar.gz
rust: fix detection of main file
If any dependency has "sources" in it, the file from the dependency might end up in the rustc command line. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--test cases/rust/13 external c dependencies/foo.h3
-rw-r--r--test cases/rust/13 external c dependencies/meson.build7
3 files changed, 12 insertions, 2 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index db061f286..a47a948ee 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1985,7 +1985,7 @@ class NinjaBackend(backends.Backend):
return orderdeps, main_rust_file
for i in target.get_sources():
- if main_rust_file is None:
+ if main_rust_file is None and i.endswith('.rs'):
main_rust_file = i.rel_to_builddir(self.build_to_src)
for g in target.get_generated_sources():
for i in g.get_outputs():
@@ -1993,7 +1993,7 @@ class NinjaBackend(backends.Backend):
fname = os.path.join(self.get_target_private_dir(target), i)
else:
fname = os.path.join(g.get_subdir(), i)
- if main_rust_file is None:
+ if main_rust_file is None and fname.endswith('.rs'):
main_rust_file = fname
orderdeps.append(fname)
diff --git a/test cases/rust/13 external c dependencies/foo.h b/test cases/rust/13 external c dependencies/foo.h
new file mode 100644
index 000000000..891255215
--- /dev/null
+++ b/test cases/rust/13 external c dependencies/foo.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int foo;
diff --git a/test cases/rust/13 external c dependencies/meson.build b/test cases/rust/13 external c dependencies/meson.build
index c91674caa..d0baab42d 100644
--- a/test cases/rust/13 external c dependencies/meson.build
+++ b/test cases/rust/13 external c dependencies/meson.build
@@ -21,3 +21,10 @@ e = executable(
)
test('cdepstest', e)
+
+e2 = executable(
+ 'prog2', 'prog.rs',
+ dependencies : declare_dependency(link_with: l, sources: files('foo.h')),
+)
+
+test('cdepstest', e2)