Support just running lib tests

And set stack size the way the build does it.

Change-Id: Icb7307efc5c5aa3842005d2415166f0917dc4d31
Testing: manual
Reviewed-on: https://fuchsia-review.googlesource.com/c/fargo/+/493303
Reviewed-by: Rob Tsuk <robtsuk@google.com>
diff --git a/src/command_line.rs b/src/command_line.rs
index 0eb90ed..675c384 100644
--- a/src/command_line.rs
+++ b/src/command_line.rs
@@ -298,6 +298,10 @@
     /// Test only the specified test target.
     test: Option<String>,
 
+    #[structopt(long)]
+    /// Test only this package's library unit tests.
+    lib: bool,
+
     /// Display all output when running tests.
     // Allow multiple occurences since fargo writes out a .cargo/config runner
     // command that includes "--nocapture", but some tools like VSCode additionally
@@ -694,6 +698,7 @@
                     .nocapture(test_opts.nocapture),
                 test_opts.no_run,
                 test_opts.doc,
+                test_opts.lib,
                 &target_options,
                 &params,
                 to_opt_str(&test_args),
diff --git a/src/lib.rs b/src/lib.rs
index 86bfab9..25b3a3b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -120,7 +120,8 @@
                 // TODO(raggi): provide a fuller ignore flag/pattern match solution here.
                 if !path.starts_with(&tgt) && !path.starts_with(&git) {
                     println!("autotest: running tests because {:?}", path);
-                    run_tests(run_cargo_options, false, false, target_options, &[], None).ok();
+                    run_tests(run_cargo_options, false, false, false, target_options, &[], None)
+                        .ok();
                 }
             }
             _ => {}
@@ -132,6 +133,7 @@
     run_cargo_options: &RunCargoOptions,
     no_run: bool,
     doc: bool,
+    lib: bool,
     target_options: &TargetOptions<'_, '_>,
     params: &[&str],
     target_params: Option<&str>,
@@ -146,6 +148,10 @@
         args.push("--doc");
     }
 
+    if lib {
+        args.push("--lib");
+    }
+
     for param in params {
         args.push(param);
     }
@@ -362,6 +368,7 @@
         // http://fuchsia.googlesource.com/fuchsia/+/08dce526941ac5be23cec1b50f841aad5ed37ea1/build/config/BUILD.gn#547
         "--cfg=rust_panic=\"abort\"".to_string(),
         "-Clink-arg=--pack-dyn-relocs=relr".to_string(),
+        "-Clink-args=-zstack-size=0x200000".to_string(),
         format!("-Clink-arg=-L{}", sysroot_lib),
         format!("-Clink-arg=-L{}/gen/zircon/public/lib/fdio", shared_lib_path.to_string_lossy(),),
         format!("-Clink-arg=-L{}/gen/zircon/public/lib/syslog", shared_lib_path.to_string_lossy(),),