浏览代码

fix chosing launch target
it used to match in order:
* first binary alphabetically
* library
now matches in order:
1. default-run binary
2. binary with name of crate or located at src/main.rs
3. first binary alphabetically
4. library

erithax 2 年之前
父节点
当前提交
ae80702ed9
共有 1 个文件被更改,包括 15 次插入9 次删除
  1. 15 9
      src/config.rs

+ 15 - 9
src/config.rs

@@ -186,15 +186,21 @@ impl CrateConfig {
 
         let manifest = cargo_toml::Manifest::from_path(&cargo_def).unwrap();
 
-        // We just assume they're using a 'main.rs'
-        // Anyway, we've already parsed the manifest, so it should be easy to change the type
-        let output_filename = manifest
-            .bin
-            .first()
-            .or(manifest.lib.as_ref())
-            .and_then(|product| product.name.clone())
-            .or_else(|| manifest.package.as_ref().map(|pkg| pkg.name.clone()))
-            .expect("No lib found from cargo metadata");
+        let output_filename = {
+            match &manifest.package.as_ref().unwrap().default_run {
+                Some(default_run_target) => {
+                    default_run_target.to_owned()
+                },
+                None => {
+                    manifest.bin.iter().find(|b| b.name == manifest.package.as_ref().map(|pkg| pkg.name.clone()))
+                        .or(manifest.bin.iter().find(|b| b.path == Some("src/main.rs".to_owned())))
+                        .or(manifest.bin.first())
+                        .or(manifest.lib.as_ref())
+                        .and_then(|prod| prod.name.clone())
+                        .expect("No executable or library found from cargo metadata.")
+                }
+            }
+        };
         let executable = ExecutableType::Binary(output_filename);
 
         let release = false;