|
8 | 8 | //! make gcc/clang pass `-flavor <flavor>` as the first two arguments in the linker invocation
|
9 | 9 | //! and since Windows does not support symbolic links for files this wrapper is used in place of a
|
10 | 10 | //! symbolic link. It execs `../rust-lld -flavor <flavor>` by propagating the flavor argument
|
11 |
| -//! passed to the wrapper as the first two arguments. On Windows it spawns a `..\rust-lld.exe` |
12 |
| -//! child process. |
| 11 | +//! obtained from the wrapper's name as the first two arguments. |
| 12 | +//! On Windows it spawns a `..\rust-lld.exe` child process. |
13 | 13 |
|
14 | 14 | use std::fmt::Display;
|
15 | 15 | use std::path::{Path, PathBuf};
|
@@ -53,29 +53,32 @@ fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
|
53 | 53 | rust_lld_path
|
54 | 54 | }
|
55 | 55 |
|
| 56 | +/// Extract LLD flavor name from the lld-wrapper executable name. |
| 57 | +fn get_lld_flavor(current_exe_path: &Path) -> Result<&'static str, String> { |
| 58 | + let stem = current_exe_path.file_stem(); |
| 59 | + Ok(match stem.and_then(|s| s.to_str()) { |
| 60 | + Some("ld.lld") => "gnu", |
| 61 | + Some("ld64.lld") => "darwin", |
| 62 | + Some("lld-link") => "link", |
| 63 | + Some("wasm-ld") => "wasm", |
| 64 | + _ => return Err(format!("{:?}", stem)), |
| 65 | + }) |
| 66 | +} |
| 67 | + |
56 | 68 | /// Returns the command for invoking rust-lld with the correct flavor.
|
57 |
| -/// LLD only accepts the flavor argument at the first two arguments, so move it there. |
| 69 | +/// LLD only accepts the flavor argument at the first two arguments, so pass it there. |
58 | 70 | ///
|
59 | 71 | /// Exits on error.
|
60 | 72 | fn get_rust_lld_command(current_exe_path: &Path) -> process::Command {
|
61 | 73 | let rust_lld_path = get_rust_lld_path(current_exe_path);
|
62 | 74 | let mut command = process::Command::new(rust_lld_path);
|
63 | 75 |
|
64 |
| - let mut flavor = None; |
65 |
| - let args = env::args_os() |
66 |
| - .skip(1) |
67 |
| - .filter(|arg| match arg.to_str().and_then(|s| s.strip_prefix("-rustc-lld-flavor=")) { |
68 |
| - Some(suffix) => { |
69 |
| - flavor = Some(suffix.to_string()); |
70 |
| - false |
71 |
| - } |
72 |
| - None => true, |
73 |
| - }) |
74 |
| - .collect::<Vec<_>>(); |
| 76 | + let flavor = |
| 77 | + get_lld_flavor(current_exe_path).unwrap_or_exit_with("executable has unexpected name"); |
75 | 78 |
|
76 | 79 | command.arg("-flavor");
|
77 |
| - command.arg(flavor.unwrap_or_exit_with("-rustc-lld-flavor=<flavor> is not passed")); |
78 |
| - command.args(args); |
| 80 | + command.arg(flavor); |
| 81 | + command.args(env::args_os().skip(1)); |
79 | 82 | command
|
80 | 83 | }
|
81 | 84 |
|
|
0 commit comments