a1ien / libusb1-sys

MIT License
13 stars 10 forks source link

Failure to build on Windows with MSVC toolchain #15

Closed elfmimi closed 4 years ago

elfmimi commented 4 years ago

libusb1-sys fails to build on Windows. It could be only for specific languages.

active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.42.0 (b8cedc004 2020-03-09)

Console log does not describe much.

   Compiling libusb1-sys v0.3.5 (C:\Users\applause\CratesIO\libusb1-sys)
error: failed to run custom build command for `libusb1-sys v0.3.5 (C:\Users\applause\CratesIO\libusb1-sys)`

Caused by:
  process didn't exit successfully: `C:\Users\applause\CratesIO\libusb1-sys\target\debug\build\libusb1-sys-702cb1b342a9d53d\build-script-build` (exit code: 1)
--- stderr

error occurred: Command "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "C:\\Users\\applause\\CratesIO\\libusb1-sys\\target\\debug\\build\\libusb1-sys-e0a913180831be5c\\out\\source\\libusb-1.0.22" "-I" "C:\\Users\\applause\\CratesIO\\libusb1-sys\\target\\debug\\build\\libusb1-sys-e0a913180831be5c\\out\\source\\libusb-1.0.22\\libusb" "-DENABLE_LOGGING=1" "-D_TIMESPEC_DEFINED=1" "-DOS_WINDOWS=1" "-DDEFAULT_VISIBILITY=" "-DPOLL_NFDS_TYPE=unsigned int" "-DHAVE_SIGNAL_H=1" "-DHAVE_SYS_TYPES_H=1" "-FoC:\\Users\\applause\\CratesIO\\libusb1-sys\\target\\debug\\build\\libusb1-sys-e0a913180831be5c\\out\\source\\libusb-1.0.22\\libusb/strerror.o" "-c" "C:\\Users\\applause\\CratesIO\\libusb1-sys\\target\\debug\\build\\libusb1-sys-e0a913180831be5c\\out\\source\\libusb-1.0.22\\libusb/strerror.c" with args "cl.exe" did not execute successfully (status code exit code: 2).

Running the command line in question alone manually, reveals this error message. C:\Users\applause\CratesIO\libusb1-sys\target\debug\build\libusb1-sys-e0a913180831be5c\out\source\libusb-1.0.22\libusb/strerror.c: warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式で保存してください。 See Compiler Warning C4819 for translation.

The problem is that libusb-1.0.22/libusb/strerror.c is in UTF-8 without BOM . If there were BOM it compiles OK. I tested that. Another way to solve this is to add the following compiler option. /source-charset:utf-8 See Set Source Character Set for document.

As a workaround for now, say you wanted to install cargo-flash, you can do it as following. CL=/source-charset:utf-8 cargo install cargo-flash Assuming you are using Msys2 or Cygwin bash.

elfmimi commented 4 years ago

I confirm that now I can do just cargo install cargo-flash .