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

Windows username with space breaks linking #115

Closed
MarcoBrieden opened this issue Mar 21, 2023 · 11 comments
Closed

Windows username with space breaks linking #115

MarcoBrieden opened this issue Mar 21, 2023 · 11 comments
Labels
upstream Upstream issue

Comments

@MarcoBrieden
Copy link

My Windows username contains a space, resulting in this profile directory: "C:\Users\Marco Brieden".

Trying to compile my code results in this error:

❯ cargo zigbuild --release --target x86_64-unknown-linux-gnu
   Compiling rust-resolver v0.1.0 (D:\Development\vp360\rust)
error: linking with `C:\Users\Marco Brieden\AppData\Local\cargo-zigbuild\0.16.3\zigcc-x86_64-unknown-linux-gnu.bat` failed: exit code: 1
  |
  = note: "cmd" "/c" "C:\\Users\\Marco Brieden\\AppData\\Local\\cargo-zigbuild\\0.16.3\\zigcc-x86_64-unknown-linux-gnu.bat" "-m64" "D:\\Temp\\rustcEc453k\\symbols.o" "D:\\Development\\vp360\\rust\\target\\x86_64-unknown-linux-gnu\\release\\deps\\rust_resolver-f8bda55ce059fbe0.rust_resolver.ff2b47e7-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "D:\\Development\\vp360\\rust\\target\\x86_64-unknown-linux-gnu\\release\\deps" "-L" "D:\\Development\\vp360\\rust\\target\\release\\deps" "-L" "C:\\Users\\Marco Brieden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-unknown-linux-gnu\\lib" "-Wl,-Bstatic" "C:\\Users\\Marco Brieden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-unknown-linux-gnu\\lib\\libcompiler_builtins-87185c5e58e44fea.rlib" "-Wl,-Bdynamic" "-llibpq" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "C:\\Users\\Marco Brieden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-unknown-linux-gnu\\lib" "-o" "D:\\Development\\vp360\\rust\\target\\x86_64-unknown-linux-gnu\\release\\deps\\rust_resolver-f8bda55ce059fbe0" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,--strip-all" "-nodefaultlibs"
  = note: 'C:\Users\Marco' is not recognized as an internal or external command,
          operable program or batch file.


error: could not compile `rust-resolver` due to previous error
@messense
Copy link
Member

I don't personally use Windows, so help appreciated.

@MarcoBrieden
Copy link
Author

The zigcc-x86_64-unknown-linux-gnu.bat that is failing contains this:

C:\Users\Marco Brieden\.cargo\bin\cargo-zigbuild.exe zig cc -- -target x86_64-linux-gnu  -g -Wl,--version-script=C:\Users\Marco Brieden\AppData\Local\cargo-zigbuild\0.16.3\fcntl.map -include C:\Users\Marco Brieden\AppData\Local\cargo-zigbuild\0.16.3\fcntl.h %*

Surrounding all paths with spaces might fix it:

"C:\Users\Marco Brieden\.cargo\bin\cargo-zigbuild.exe" zig cc -- -target x86_64-linux-gnu  -g -Wl,--version-script="C:\Users\Marco Brieden\AppData\Local\cargo-zigbuild\0.16.3\fcntl.map" -include "C:\Users\Marco Brieden\AppData\Local\cargo-zigbuild\0.16.3\fcntl.h" %*

I tried editing it, but it gets newly generated every run. Write protecting it causes zigbuild to complain and error out.

The same folder has two more files that have the same issue: "zigcxx-x86_64-unknown-linux-gnu.bat" and "zigranlib.bat".

@messense
Copy link
Member

You can change it here

cargo-zigbuild/src/zig.rs

Lines 868 to 874 in fb64c65

writeln!(
&mut custom_linker_file,
"{} zig {} -- {} %*",
adjust_canonicalization(current_exe),
command,
args
)?;

And run cargo run zigbuild instead of cargo zigbuild to test it.

@messense messense added the bug Something isn't working label Mar 22, 2023
@MarcoBrieden
Copy link
Author

I think it fails to execute the .bat file in the first place, because of the path.
Any idea where that happens?

@messense
Copy link
Member

I think it's rust-lang/rust#29494, unfortunate it's out of our control because we didn't use cmd /c, something else did.

@MarcoBrieden
Copy link
Author

MarcoBrieden commented Mar 22, 2023

That bug has been fixed a year ago though, right?

Are you saying the batch file isn't executed from within cargo-zigbuild?
Where is it executed from then?

@messense
Copy link
Member

That bug has been fixed a year ago though, right?

They just added a new API which needs to be adopted.

Are you saying the batch file isn't executed from within cargo-zigbuild?
Where is it executed from then?

Probably cargo or cc-rs.

@MarcoBrieden
Copy link
Author

Thanks for finding this!

@messense messense added upstream Upstream issue and removed bug Something isn't working labels Mar 22, 2023
@messense
Copy link
Member

I think you can workaround it by setting the CARGO_ZIGBUILD_CACHE_DIR env var to a directory that doesn't contain whitespace.

@MarcoBrieden
Copy link
Author

That worked, thank you very much messense!

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

No branches or pull requests

2 participants