rust: Support whole static libraries with any name

This CL allows binaries to depend on whole static libraries which
don't begin with the 'lib' prefix.

Bug: 170672854
Test: Whole static library that doesn't have lib prefix can be linked
Change-Id: I908496d9369c7bec3232e2feed0599f6cf6d9383
diff --git a/rust/rust.go b/rust/rust.go
index 13169f1..33a196a 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -1123,7 +1123,12 @@
 				if cc.IsWholeStaticLib(depTag) {
 					// rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
 					// if the library is not prefixed by "lib".
-					if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
+					if mod.Binary() {
+						// Binaries may sometimes need to link whole static libraries that don't start with 'lib'.
+						// Since binaries don't need to 'rebundle' these like libraries and only use these for the
+						// final linkage, pass the args directly to the linker to handle these cases.
+						depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
+					} else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
 						depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
 					} else {
 						ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName())