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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUSTFLAGS + a sysroot with spaces in its path = 馃槶 #6139

Open
steveklabnik opened this issue Oct 5, 2018 · 3 comments
Open

RUSTFLAGS + a sysroot with spaces in its path = 馃槶 #6139

steveklabnik opened this issue Oct 5, 2018 · 3 comments

Comments

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Oct 5, 2018

When using cargo-xbuild to do things like "build an OS", you need to set the sysroot via RUSTFLAGS.

Here's an example rustc invocation on my machine that builds:

rustc --crate-name ux "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\ux-0.1.2\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=b446262c41a4777f -C extra-filename=-b446262c41a4777f --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\sysroot"

The last bit is the important part:

--sysroot "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\sysroot"

It appears the space in my username causes this to be impossible to set via RUSTFLAGS. With an invocation like this:

~\src\intermezzos\kernel [master 鈫1]> $env:RUSTFLAGS="--sysroot ""C:\Users\Steve Klabnik\src\intermezzos\kernel\target\sysroot"""
~\src\intermezzos\kernel [master 鈫1]> $env:RUSTFLAGS
--sysroot "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\sysroot"

You can see that it's all good. However, this fails when passed to rustc:

> cargo build
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --sysroot "\"C:\Users\Steve" "Klabnik\src\intermezzos\kernel\target\sysroot\"" --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro` (exit code: 1)
--- stderr
error: multiple input filenames provided

I am not sure what to do here.

@jmesmon

This comment has been minimized.

Copy link
Contributor

@jmesmon jmesmon commented Oct 5, 2018

As a workaround, you could add build.rustflags = [ "--sysroot", "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\sysroot" ] to some .cargo (https://doc.rust-lang.org/cargo/reference/config.html).

This issue basically stems from just doing .split(" ") on RUSTFLAGS in env_args().

One plausible solution is to define some escaping mechanism for RUSTFLAGS (or to maintain backwards compat, another env variable).

@ehuss

This comment has been minimized.

Copy link
Contributor

@ehuss ehuss commented Oct 5, 2018

Although it won't work in this situation (because it uses the wrong API), I added an experimental feature that allows you to specify lists in environment variables using TOML syntax. I could extend it to cover this situation, I doubt RUSTFLAGS starting with [ is ever valid.

@luser

This comment has been minimized.

Copy link
Contributor

@luser luser commented Oct 5, 2018

There is a shlex crate that implements POSIX shell style splitting which would probably make this work: https://docs.rs/shlex/0.1.1/shlex/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can鈥檛 perform that action at this time.