Repository: mesonbuild/meson

Issue:
rust executable complains about multiple input filenames
```python
logmailer2 = executable('logmailer2', ['logmailer/src/logmailer.rs',  'logmailer/src/main.rs',  'logmailer/src/ses_mailer.rs'])
```

this generates the following error:

```
mqudsi@ZBook /m/c/U/M/g/easyre> ninja -C build
ninja: Entering directory `build'
[4/7] Compiling Rust source ../logmailer/src/logmailer.rs ../logmailer/src/main.rs ../logmailer/src/ses_mailer.rs.
FAILED: rustc --crate-type bin --crate-name logmailer2 -C debuginfo=2 --emit dep-info=logmailer2.d --emit link -o logmailer2 ../logmailer/src/logmailer.rs ../logmailer/src/main.rs ../logmailer/src/ses_mailer.rs
error: multiple input filenames provided
```



Discussion:
Is there a simple example with a multi-file Rust program (or lib) which is preferably standalone or at most depends on only a few crates so I can this fixed?
Sure, I just threw this together: https://git.neosmart.net/mqudsi/meson-rust

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1253,11 +1253,17 @@ def generate_vala_compile(self, target, outfile):
 
     def generate_rust_target(self, target, outfile):
         rustc = target.compilers['rust']
-        relsrc = []
+        # Rust compiler takes only the main file as input and
+        # figures out what other files are needed via import
+        # statements and magic.
+        main_rust_file = None
         for i in target.get_sources():
             if not rustc.can_compile(i):
                 raise InvalidArguments('Rust target %s contains a non-rust source file.' % target.get_basename())
-            relsrc.append(i.rel_to_builddir(self.build_to_src))
+            if main_rust_file is None:
+                main_rust_file = i.rel_to_builddir(self.build_to_src)
+        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):
@@ -1324,7 +1330,7 @@ def generate_rust_target(self, target, outfile):
         if target.is_cross:
             crstr = '_CROSS'
         compiler_name = 'rust%s_COMPILER' % crstr
-        element = NinjaBuildElement(self.all_outputs, target_name, compiler_name, relsrc)
+        element = NinjaBuildElement(self.all_outputs, target_name, compiler_name, main_rust_file)
         if len(orderdeps) > 0:
             element.add_orderdep(orderdeps)
         element.add_item('ARGS', args)


Test patch:
diff --git a/test cases/rust/8 many files/foo.rs b/test cases/rust/8 many files/foo.rs
new file mode 100644
--- /dev/null
+++ b/test cases/rust/8 many files/foo.rs	
@@ -0,0 +1,3 @@
+pub fn bar() -> () {
+    println!("Hello, world!");
+}
diff --git a/test cases/rust/8 many files/main.rs b/test cases/rust/8 many files/main.rs
new file mode 100644
--- /dev/null
+++ b/test cases/rust/8 many files/main.rs	
@@ -0,0 +1,5 @@
+mod foo;
+
+fn main() {
+    foo::bar();
+}
diff --git a/test cases/rust/8 many files/meson.build b/test cases/rust/8 many files/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/rust/8 many files/meson.build	
@@ -0,0 +1,3 @@
+project('manyfiles', 'rust')
+
+test('manyfiles', executable('manyfiles', 'main.rs', 'foo.rs'))