Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 71d7c07

Browse files
committed
be lenient in interpreting LD
It's often more convenient to let the compiler figure out how to invoke the linker, but setting `env LD="$CC" ... lucetc ...` poses a problem: `$CC` can often be `"$COMPILER --option1 --option2 ..."`, e.g. `clang --target=$TARGET`, and the current code assumes that `LD` is a single string specifying a program, rather than some string specifying a program along with options. While you could require that `LD` be strictly limited to a single string, it seems more flexible and more in line with other build systems to interpret `LD` as space-separated tokens, the first of which specifies the program to invoke, and the remaining tokens specifying arguments to be passed.
1 parent cf53a3b commit 71d7c07

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lucetc/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,16 @@ where
389389
Q: AsRef<Path>,
390390
{
391391
use std::process::Command;
392-
let mut cmd_ld = Command::new(env::var("LD").unwrap_or(LD_DEFAULT.into()));
392+
393+
// Let `LD` be something like "clang --target=... ..." for convenience.
394+
let env_ld = env::var("LD").unwrap_or(LD_DEFAULT.into());
395+
let mut ld_iter = env_ld.split_whitespace();
396+
let ld_prog = ld_iter.next().expect("LD must not be empty");
397+
let mut cmd_ld = Command::new(ld_prog);
398+
for flag in ld_iter {
399+
cmd_ld.arg(flag);
400+
}
401+
393402
cmd_ld.arg(objpath.as_ref());
394403
let env_ldflags = env::var("LDFLAGS").unwrap_or_else(|_| ldflags_default(target));
395404
for flag in env_ldflags.split_whitespace() {

0 commit comments

Comments
 (0)