GuillaumeGomez / rust-GSL

A GSL (the GNU Scientific Library) binding for Rust
189 stars 46 forks source link

Build on Windows using `vcpkg` #143

Open CGMossa opened 7 months ago

CGMossa commented 7 months ago

I've finally got this to work on the recommended rust toolchain. Previously discussed here #53 and #75. On Windows, we are recommended to use stable-msvc / nightly-msvc.

You can install that using scoop, or manually here https://github.com/microsoft/vcpkg#quick-start-windows

scoop install vcpkg

Then, you set the following environment variables globally

VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
VCPKG_INSTALLED_DIR=C:/Users/minin/scoop/apps/vcpkg/current/installed
LIB=%VCPKG_INSTALLED_DIR%/%VCPKG_DEFAULT_TRIPLET%/lib
INCLUDE=%VCPKG_INSTALLED_DIR%/%VCPKG_DEFAULT_TRIPLET%/include

That's it, this made my test project compile just fine.

Use of these environment variables is described in https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#path_and_environment, and https://stackoverflow.com/questions/20483619/lib-vs-libpath-environment-variables-difference-for-ms-visual-c-c,

You can choose different triplet, see vckpkg help triplet, but x64-windows-static-md is recommended by vcpkg-rs.

Even the blas-example works with this!

vcpkg would also (presumably) make CMake work on Windows.

GuillaumeGomez commented 7 months ago

Nice. Do you want to update the README documentation to mention it? Or update the crate documentation in lib.rs?

CGMossa commented 7 months ago

With your blessing I can do either or both :) I'm also exploring this option a bit more. Right now, I find the scoop lacking. I've made one PR over there to help out (with one line also :( )

GuillaumeGomez commented 7 months ago

Let's go for both then please. :)

CGMossa commented 7 months ago

I've made pijul compile on Windows as well, with these instructions:

set VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
vcpkg install openssl zstd pkgconf
set LIB=C:\dev\vcpkg\installed\x64-windows-static-md\lib
set PKG_CONFIG_PATH=C:\dev\vcpkg\installed\x64-windows-static-md\lib\pkgconfig

Apparently, if pkgconfig is used then the last thing has to be set. https://stackoverflow.com/questions/74498102/why-doesnt-my-windows-environment-properly-install-external-c-libraries These instructions are very much scattered. I'm almost sure that I got the system figured out. It cannot be done with using RUSTCWRAPPER="vcpkg env" if you're wondering.