[Solved] Build ripgrep for Windows XP with static linking


#1

Hi,
I want to build ripgrep for Windows XP.
I use rustup with nightly-x86_64-pc-windows-msvc toolchain and i686-pc-windows-msvc target.
After reading Standalone 32bit Windows App using MSVC? and rustc: Implement #[link(cfg(…))] and crt-static, I tried to build it with the

cargo rustc --release --target i686-pc-windows-msvc -- -Clink-args="/SUBSYSTEM:CONSOLE,5.01" -Ctarget-feature=+crt-static

But unfortunately cargo gives the error on this command.

 Compiling ripgrep v0.4.0 (file:///C:/Users/Veselkov/projects/ripgrep-0.4.0)
     Running `rustc --crate-name rg src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -Clink-args=/SUBSYSTEM:CONSOLE,5.01 –-Ctarget-feature=+crt-static -C metadata=54bee75e2ecc0b1b -C extra-filename=-54bee75e2ecc0b1b --out-dir C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps --target i686-pc-windows-msvc -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\release\deps --extern bytecount=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libbytecount-204b5bd5918fd15d.rlib --extern same_file=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libsame_file-2be6f1960313b7c6.rlib --extern clap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libclap-12327399030f9ae6.rlib --extern ignore=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libignore-75d5049e5b24714a.rlib --extern grep=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libgrep-df8683765a6d42fd.rlib --extern num_cpus=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libnum_cpus-da9c69f71bca8dc5.rlib --extern memchr=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemchr-7286d8d76045474b.rlib --extern regex=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libregex-521d73f39453dc41.rlib --extern memmap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemmap-1992515301662dc0.rlib --extern lazy_static=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblazy_static-a91e9f0b67df5a0e.rlib --extern kernel32=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libkernel32-0210e344c626c1fd.rlib --extern termcolor=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libtermcolor-9e26e1f026736c7a.rlib --extern libc=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblibc-ef6c3553a2e8a9f8.rlib --extern env_logger=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libenv_logger-e33074140507e3b3.rlib --extern winapi=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libwinapi-ce96ff307a9c1d5d.rlib --extern log=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblog-9067f8cbf2793fa9.rlib`
error: multiple input filenames provided

error: Could not compile `ripgrep`.

Caused by:
  process didn't exit successfully: `rustc --crate-name rg src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -Clink-args=/SUBSYSTEM:CONSOLE,5.01 –-Ctarget-feature=+crt-static -C metadata=54bee75e2ecc0b1b -C extra-filename=-54bee75e2ecc0b1b --out-dir C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps --target i686-pc-windows-msvc -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\release\deps --extern bytecount=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libbytecount-204b5bd5918fd15d.rlib --extern same_file=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libsame_file-2be6f1960313b7c6.rlib --extern clap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libclap-12327399030f9ae6.rlib --extern ignore=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libignore-75d5049e5b24714a.rlib --extern grep=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libgrep-df8683765a6d42fd.rlib --extern num_cpus=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libnum_cpus-da9c69f71bca8dc5.rlib --extern memchr=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemchr-7286d8d76045474b.rlib --extern regex=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libregex-521d73f39453dc41.rlib --extern memmap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemmap-1992515301662dc0.rlib --extern lazy_static=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblazy_static-a91e9f0b67df5a0e.rlib --extern kernel32=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libkernel32-0210e344c626c1fd.rlib --extern termcolor=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libtermcolor-9e26e1f026736c7a.rlib --extern libc=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblibc-ef6c3553a2e8a9f8.rlib --extern env_logger=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libenv_logger-e33074140507e3b3.rlib --extern winapi=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libwinapi-ce96ff307a9c1d5d.rlib --extern log=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblog-9067f8cbf2793fa9.rlib` (exit code: 101)

Can someone help me fix this?


#2

Any suggestions?


#3

In the Cargo output you’ve pasted, there’s a weird control character just before -Ctarget-feature=+crt-static. That may just weird stuff from terminal or discourse, but I’d try to retype this fragment: (LE,5.01" -Ctarget) just for sure. I’d also try to put the quotes around the whole argument, or maybe get rid of them (the argument does’t seem to contain any special characters). Windows is known for poor handling of commandline arguments.


#4

Thanks for the reply.

I use cygwin terminal. After your reply I tried to put the arguments into the variable.
R_FLAGS="-Clink-args=\"/SUBSYSTEM:CONSOLE,5.01\" -Ctarget-feature=+crt-static"
cargo rustc --release --target i686-pc-windows-msvc -v -- $R_FLAGS
And I got the error
error: specifying the crt-static target feature is only allowed on the nightly channel with -Z unstable-options passed as well

I added this option to the variable
R_FLAGS="-Z unstable-options -Clink-args=\"/SUBSYSTEM:CONSOLE,5.01\" -Ctarget-feature=+crt-static"
cargo rustc --release --target i686-pc-windows-msvc -v -- $R_FLAGS

And I got the error…

Compiling ripgrep v0.4.0 (file:///C:/Users/Veselkov/projects/ripgrep-0.4.0)
     Running `rustc --crate-name rg src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -Z unstable-options "-Clink-args=\"/SUBSYSTEM:CONSOLE,5.01\"" -Ctarget-feature=+crt-static -C metadata=52958abed4bad6c6 -C extra-filename=-52958abed4bad6c6 --out-dir C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps --target i686-pc-windows-msvc -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\release\deps --extern libc=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblibc-ef6c3553a2e8a9f8.rlib --extern regex=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libregex-521d73f39453dc41.rlib --extern memchr=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemchr-7286d8d76045474b.rlib --extern winapi=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libwinapi-ce96ff307a9c1d5d.rlib --extern clap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libclap-12327399030f9ae6.rlib --extern env_logger=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libenv_logger-e33074140507e3b3.rlib --extern termcolor=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libtermcolor-9e26e1f026736c7a.rlib --extern lazy_static=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblazy_static-a91e9f0b67df5a0e.rlib --extern same_file=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libsame_file-2be6f1960313b7c6.rlib --extern log=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblog-9067f8cbf2793fa9.rlib --extern bytecount=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libbytecount-204b5bd5918fd15d.rlib --extern ignore=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libignore-75d5049e5b24714a.rlib --extern memmap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemmap-1992515301662dc0.rlib --extern grep=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libgrep-df8683765a6d42fd.rlib --extern kernel32=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libkernel32-0210e344c626c1fd.rlib --extern num_cpus=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libnum_cpus-da9c69f71bca8dc5.rlib`
error: linking with `link.exe` failed: exit code: 1104
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64_x86\\link.exe" "/LIBPATH:C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.10240.0\\ucrt\\x86" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\8.1\\lib\\winv6.3\\um\\x86" "/NOLOGO" "/NXCOMPAT" "/LARGEADDRESSAWARE" "/SAFESEH" "/LIBPATH:C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\rg-52958abed4bad6c6.0.o" "/OUT:C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\rg-52958abed4bad6c6.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps" "/LIBPATH:C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\release\\deps" "/LIBPATH:C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libbytecount-204b5bd5918fd15d.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libenv_logger-e33074140507e3b3.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libignore-75d5049e5b24714a.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libnum_cpus-da9c69f71bca8dc5.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libgrep-df8683765a6d42fd.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libglobset-e0e7e5605a15e96c.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libfnv-afa95737e6b2da08.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libwalkdir-f06ef33df9f505f3.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libsame_file-2be6f1960313b7c6.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libclap-12327399030f9ae6.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libunicode_segmentation-bb02c4927a6029b4.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libterm_size-d29f6ad9f85b5cb1.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libbitflags-923bf1a30cd72d80.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libunicode_width-cdfa97d41cf85ce8.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libansi_term-7ef0d8419d85cce5.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libstrsim-b9dfa0d070efa9e3.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libvec_map-bdb291c8a09f38e3.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\liblog-9067f8cbf2793fa9.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libregex-521d73f39453dc41.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libutf8_ranges-3bc57ff5be92e8a8.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libthread_local-8bbc3c04161bffe6.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libunreachable-2782e7a7013f1a4a.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libvoid-cbe41697e8f5c5c3.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libaho_corasick-596d054ab8db2fe6.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libmemchr-7286d8d76045474b.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\liblibc-ef6c3553a2e8a9f8.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libthread_id-f82329de91b5e2b6.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libregex_syntax-533550baaabb0a14.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libcrossbeam-0ba817723a895199.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\liblazy_static-a91e9f0b67df5a0e.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libmemmap-1992515301662dc0.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libfs2-a19d59cf965414ef.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libtermcolor-9e26e1f026736c7a.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libwincolor-3afc38faca845ffa.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libkernel32-0210e344c626c1fd.rlib" "C:\\Users\\Veselkov\\projects\\ripgrep-0.4.0\\target\\i686-pc-windows-msvc\\release\\deps\\libwinapi-ce96ff307a9c1d5d.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libstd-aec987e27dc02a81.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libpanic_unwind-32a6e6d4db29ff21.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libunwind-db05e9c9e3cb1ac3.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\liblibc-2f04cb56bb92416d.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\librand-504068b1a9c8a16f.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcollections-024d727290462965.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\liballoc-def9bc0f10aea489.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\liballoc_system-d9f32f61be03643a.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libstd_unicode-2734b07f1aee8e47.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcore-1fd444b09a0656e0.rlib" "C:\\Users\\Veselkov\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\i686-pc-windows-msvc\\lib\\libcompiler_builtins-1b4c59b237fa4981.rlib" "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "libcmt.lib" "\"/SUBSYSTEM:CONSOLE,5.01\""
  = note: Non-UTF-8 output: LINK : fatal error LNK1104: \xed\xe5 \xf3\xe4\xe0\xe5\xf2\xf1\xff \xee\xf2\xea\xf0\xfb\xf2\xfc \xf4\xe0\xe9\xeb \"\"/SUBSYSTEM:CONSOLE,5.01\"\"\r\n

error: aborting due to previous error

error: Could not compile `ripgrep`.

Caused by:
  process didn't exit successfully: `rustc --crate-name rg src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -Z unstable-options -Clink-args="/SUBSYSTEM:CONSOLE,5.01" -Ctarget-feature=+crt-static -C metadata=52958abed4bad6c6 -C extra-filename=-52958abed4bad6c6 --out-dir C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps --target i686-pc-windows-msvc -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps -L dependency=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\release\deps --extern libc=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblibc-ef6c3553a2e8a9f8.rlib --extern regex=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libregex-521d73f39453dc41.rlib --extern memchr=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemchr-7286d8d76045474b.rlib --extern winapi=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libwinapi-ce96ff307a9c1d5d.rlib --extern clap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libclap-12327399030f9ae6.rlib --extern env_logger=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libenv_logger-e33074140507e3b3.rlib --extern termcolor=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libtermcolor-9e26e1f026736c7a.rlib --extern lazy_static=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblazy_static-a91e9f0b67df5a0e.rlib --extern same_file=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libsame_file-2be6f1960313b7c6.rlib --extern log=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\liblog-9067f8cbf2793fa9.rlib --extern bytecount=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libbytecount-204b5bd5918fd15d.rlib --extern ignore=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libignore-75d5049e5b24714a.rlib --extern memmap=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libmemmap-1992515301662dc0.rlib --extern grep=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libgrep-df8683765a6d42fd.rlib --extern kernel32=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libkernel32-0210e344c626c1fd.rlib --extern num_cpus=C:\Users\Veselkov\projects\ripgrep-0.4.0\target\i686-pc-windows-msvc\release\deps\libnum_cpus-da9c69f71bca8dc5.rlib` (exit code: 101)

#5

Please stop using the cygwin terminal. Use a normal Windows console, either cmd or powershell, and set your code page to UTF8 by doing chcp 65001.

Windows has very simple rules for how it splits command line arguments. Weird control characters are treated literally with no special meaning, so if you cram your command line full of them of course whatever program that gets them is going to be confused. If some weird shell such as cygwin’s shell decides to mangle your input, then don’t blame Windows, blame cygwin’s shell. In fact, it isn’t even Windows that splits command line arguments. It literally just passes through the entire command line as an opaque string and the spawned program is responsible for splitting the command line to parse the arguments.


#6

So now every program has to use its own argument parser and encoder. I consider this a bad design decision.

Anyway, @vessd, it seems that the quotes are still being passed to link.exe. Try without them? I feel no matter the shell they will be passed, since they’re escaped now.


#7

Nonsense, there is a standard Windows function you can call to split the command line for you CommandLineToArgvW and every sane program (including every Rust program) relies on it. It cares about only three characters: ", \, and space. I don’t think there’s a built in way in win32 to encode arguments, but any sane standard library will encode them correctly for you (and it’s quite trivial to do correctly).


#8

Well, I ran it in cmd.exe, and it is successfully executed.

cargo rustc --release --target i686-pc-windows-msvc -v -- -Z unstable-options -Clink-args="/SUBSYSTEM:CONSOLE,5.01" -Ctarget-feature=+crt-static 

But unfortunately the ripgrep still does not work.

The procedure entry point GetFileInformationByHandleEx could not be located in the dynamic link library KERNEL32.dll

I also tried to change the +crt-static to the -crt-static, but the result remains the same.

Maybe I should try this patch


#9

The problem is that at some point ripgrep either relies directly on GetFileInformationByHandleEx or it relies on the functionality of a library which relies on GetFileInformationByHandleEx. Patching winapi will not fix anything. You have to fix the code which actually depends on GetFileInformationByHandleEx in the first place to dynamically load GetFileInformationByHandleEx and have a fallback for older Windows. I’m sure a well made PR to the relevant libraries will be appreciated, but definitely nobody will be fixing this for you because very few Rust developers care about the massively outdated Windows XP, just caring about Windows at all is hard enough as is.


#10

Looks like this function has been added in this pull request. Not sure that I can figure out how to replace it.


#11

It’s used in the atty crate here: https://github.com/softprops/atty/blob/db8d55f88eabfcc22cde39533c2b1d688d1cdfc6/src/lib.rs#L116

It’s used to find the file name of standard streams, which in turn is used to detect whether ripgrep is run from inside cygwin or not.


#12

If I can guarantee that rg.exe will run only in the cmd.exe, then can I just always return false from msys_tty_on, right?


#13

Yes.


#14

Thanks for the help.