Open Frank-Buss opened 2 years ago
One problem with Visual Studio is this line: https://github.com/cjdelisle/packetcrypt_rs/blob/9cce37edd78f94f8ddd8b451022b5b34b3a766ca/packetcrypt-sys/build.rs#L113 Another problem might be this line: https://github.com/cjdelisle/packetcrypt_rs/blob/9cce37edd78f94f8ddd8b451022b5b34b3a766ca/packetcrypt-sys/build.rs#L113 but it still uses "-O2" from somewhere when deleted.
But I managed to cross-compile it from Linux now. Prerequisite (on Debian) : apt install mingw-w64
. Then install the Rust cross compilation tool, as described here:
https://rust-lang.github.io/rustup/cross-compilation.html
and finally you can build it for Windows on Linux like this:
cargo build --target x86_64-pc-windows-gnu --release
I was able to successfully compile the repo on my Windows system by switching to the GNU toolchain for rustup, which would second that the problem is with an interaction with MSVC. Anyone having issues might want to try these commands:
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup set default-host x86_64-pc-windows-gnu
Before attempting to compile as normal. Obviously, it would be ideal if this were not necessary and the default MSVC toolchain could be used, but it may be a functional workaround.
The problem here is that there is C code in packetcrypt_rs and when we're on windows it's trying to use cl.exe
to compile it. The language which cl.exe compiles is "not really C", it's Microsoft's flavor of C++, projects which support cl.exe are lined with ifdef _MSC_VER to adjust to this compiler's dialect, something which I would ideally like to keep out of this codebase.
However, new versions of microsoft visual studio do ship with the option of using the clang compiler, but last time I checked, the rust package cc, which manages the compiling, was not capable of finding the clang executable in order to use it.
The bug has nothing to do with how MSVC implements the C++ standard, but with wrong compiler options. And MSVC is pretty standard conform last time I checked, I don't expect many MSC_VER tests. Except for the Microsoft declspec mess for using DLLs, but this is just one place and a few defines for exported/imported functions, in case a DLL is used at all and it is not linked statically.
Oh, interesting. I don't have a windows computer handy but if you can get it building with the right flags then we should be able to put it on github actions so that we're sure it doesn't break in the future. The build flags are in build.rs inside of packetcrypt-sys
I don't know if github actions support Visual Studio. But I managed to compile it now on a clean Windows 10 installation. Needs only msys2, probably this could be used with github actions. Here are the steps: https://github.com/cjdelisle/packetcrypt_rs/issues/39#issuecomment-999982652 I tested it in a Oracle Virtual Box VM, so should be possible for you to reproduce this (a Windows 10 Pro licence key on eBay costs about $20, and the ISO is officially available from the Microsoft webpage), and then add the instructions to the readme. Or maybe better a separate build-readme for Windows, because most people might just download the binary release.
When I try to compile it on Windows, I get the following error:
Tested with Visual Studio Community 2019 and 2022.