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

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

Closed
steveklabnik opened this issue Oct 5, 2018 · 10 comments
Closed

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

steveklabnik opened this issue Oct 5, 2018 · 10 comments
Labels
A-environment-variables Area: environment variables A-rustflags Area: rustflags

Comments

@steveklabnik
Copy link
Member

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\git.luolix.top-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.

@codyps
Copy link
Contributor

codyps 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
Copy link
Contributor

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
Copy link
Contributor

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/

@nathan-osman
Copy link

nathan-osman commented Dec 27, 2020

For those looking for a temporary workaround, Windows still supports short filenames, so you could do:

"C:\Users\SteveK~1\.cargo\registry\src\git.luolix.top-..."

Ugly? Yes. But it works. 😛

@zshift
Copy link

zshift commented Jul 13, 2021

Is there any traction on this? This issue has been open for 3 years now, and it's not obvious how to resolve without doing some searching.

@kupiakos
Copy link

If the problem is xargo setting RUSTFLAGS unconditionally then that can be fixed with the recently added feature of CARGO_ENCODED_RUSTFLAGS. This is Cargo's "fix" to the solution for xargo.

#10232 (comment)

@RalfJung
Copy link
Member

RalfJung commented Apr 10, 2022

This is the first time I hear about CARGO_ENCODED_RUSTFLAGS. Not sure since when it exists, but if it can replace setting RUSTFLAGS xargo should definitely use that, yeah. :D

However, at https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts it sounds more like CARGO_ENCODED_RUSTFLAGS is something that cargo sets for build scripts, not something it reads itself.

@RalfJung
Copy link
Member

Ah, here it is. Yeah that sounds like exactly what we need!

@RalfJung
Copy link
Member

I can confirm that with japaric/xargo#336, using a directory with a space for XARGO_HOME (which becomes the sysroot) works fine.

This issue should probably be closed then?

@weihanglo
Copy link
Member

It seems to be there since 1.55.
https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-155-2021-09-09

Thanks for the reminder! Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-environment-variables Area: environment variables A-rustflags Area: rustflags
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants