Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect RUSTFLAGS parsing #3287

Closed
lucab opened this issue Nov 12, 2016 · 5 comments
Closed

Incorrect RUSTFLAGS parsing #3287

lucab opened this issue Nov 12, 2016 · 5 comments

Comments

@lucab
Copy link
Contributor

lucab commented Nov 12, 2016

It looks like env_args() is blindly splitting env args on spaces, making -C link-args impossible to use.

This happens when trying to use multiple linker args:

$ rustc -C help | grep link-args
    -C         link-args=val -- extra arguments to pass to the linker (space separated)

$ RUSTFLAGS='-C link-args="-fPIE -pie -Wl,-z,relro -Wl,-z,now"' ./target/release/cargo build --verbose
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name _ --print=file-names -C link-args="-fPIE -pie -Wl,-z,relro -Wl,-z,now" --crate-type bin --crate-type rlib --target x86_64-unknown-linux-gnu` (exit code: 101)
--- stderr
error: Unrecognized option: 'p'.

Output above is from current master (0.15.0-pre).

@alexcrichton
Copy link
Member

Thanks for the report! This is working as expected, however, as this is defined behavior of how RUSTFLAGS is parsed. You can work around this, however, with .cargo/config which supports spaces in paths.

@alexcrichton
Copy link
Member

er, spaces, in arguments*

@lucab
Copy link
Contributor Author

lucab commented Nov 14, 2016

While I understand the dotfile feature, I'm a bit puzzled on the UX side of this.

How are scripts supposed to pass existing/dynamic environmental $LDFLAGS to cargo/rustc? Especially when those are inherited though makefile or similar automation tools, I can't envision doing dotfile manipulation all the times.

Is there any other way which doesn't require going back and forward through user files?

@alexcrichton
Copy link
Member

In some sense $LDFLAGS is a bash-ism (or shell-ism), and Cargo isn't a shell, so interpretation is inevitable no matter what. With more recent versions of rustc you can split $LDFLAGS on spaces and pass each as -Clink-arg=$foo (note the link-arg, not link-args).

@lucab
Copy link
Contributor Author

lucab commented Nov 14, 2016

Thanks for the answer, that's indeed a good way forward! For readers from the future, recent here means >= 1.13.0.

With the answer at hand, it was easier finding references (which I'm dumping here for cross-linking):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants