Closed amsam0 closed 1 year ago
Cargo splits RUSTFLAGS
by spaces without any other kind of processing. The newer CARGO_ENCODED_RUSTFLAGS
is split by \x1f
(ASCII Unit Separator) so it can handle arguments with spaces. https://github.com/bjorn3/rustc_codegen_cranelift/commit/68f7b826be24b023a625081c43d4e8af7952dd84 switches from RUSTFLAGS
to CARGO_ENCODED_RUSTFLAGS
.
Hi, I've been having issues building from source due to there being a space in the path of the directory I have cloned rustc_codegen_cranelift to.
It doesn't seem to be an issue with the build system; it actually seems to be an issue with how cargo handles the
RUSTFLAGS
environment variable.These two lines both cause an issue: https://github.com/bjorn3/rustc_codegen_cranelift/blob/master/build_system/build_sysroot.rs#L247 https://github.com/bjorn3/rustc_codegen_cranelift/blob/master/build_system/build_sysroot.rs#L255
The issue is that the paths are not escaped. Because of the spaces, rustc complains about being given multiple input files.
However, simply adding quotes around the path, escaping spaces, etc does not solve the issue. cargo seems to add a bunch of single quotes around the
-Zcodegen-backend=...
argument when you attempt to escape the path in any way.For example, changing
format!(" -Zcodegen-backend={}", ...)
toformat!(" -Zcodegen-backend=\"{}\"", ...)
causes cargo to run rustc with these arguments:[...] '-Zcodegen-backend="/a/directory' with 'spaces_in_it/rustc_codegen_cranelift/./dist/lib/librustc_codegen_cranelift.dylib"' [...]
. I've confirmed this happens even if you don't set theRUSTFLAGS
environment variable throughCommand
. Cargo seems to be unescaping the path.For now, I'll just clone rustc_codegen_cranelift to a directory without spaces in the path, but if there's a way to fix this, I'd like to.