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 build #68

Closed
pepijndevos opened this issue Nov 27, 2020 · 3 comments
Closed

Windows build #68

pepijndevos opened this issue Nov 27, 2020 · 3 comments

Comments

@pepijndevos
Copy link
Collaborator

Currently the CI is failing on the windows build. This process is based on the no longer existing gtk-rs documentation:
https://github.com/gtk-rs/gtk-rs.github.io/blob/0ae94ecbeaea692db8775229b06d66a7612b1653/docs-src/requirements.md

I'll document my progress and solicit input in this issue.

I am following the official GTK instructions which documents MSYS2, which installs a GNU toolchain, and suggests using gvsbuild if you want a MSVC toolchain. vcpkg isn't mentioned anywhere. I think gvsbuild builds GTK completely from source. I don't know if people have strong feelings over different Windows toolchains and package managers, but I'm inclined to follow the GTK documentation and use MSYS2.

After some initial confusion that is common when I touch Windows, it was actually quite easy.

Install MSYS2 and launch their "MSYS2 MSYS" terminal

pacman -Syu ##restart terminal after this
pacman -S mingw-w64-x86_64-gtk3
pacman -S mingw-w64-x86_64-toolchain # needed for pkg-config

Then I installed rust with rustup-init.exe as per https://forge.rust-lang.org/infra/other-installation-methods.html#other-ways-to-install-rustup I did not pay attention and ended up with a MSVC. So had to do tell rustup to install the GNU one.

rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu

Now the confusing bit is that cargo lives is in the Windows universe, but GTK lives in the MSYS2 universe. To get access to the mingw toolchain you need to run the "MSYS2 MinGW 64-bit" app. From there you need to break out to the Windows world and run cargo.

cd /c/Users/me/vgtk
export PATH="/c/Users/me/.cargo/bin:$PATH"
cargo build

This actually gets you a working app. So now the challenge is getting this into CI. The good news is the windows-latest image includes MSYS2 already. The bad news is it doesn't allow installation caching. The most annoying part is figuring out how to enter the "MSYS2 MinGW 64-bit" universe without the GUI launcher.

I found on StackOverflow you can call their bash binary like \msys64\usr\bin\bash -l -c "pwd" but that seems to get you into the MSYS2 universe, which is different from the MinGW universe. This will probably involve reveres-engineering the GUI launcher, which is a struggle for another day.

@pepijndevos
Copy link
Collaborator Author

pepijndevos commented Nov 28, 2020

FWIW the CI error on windows is

Failed to run `"pkg-config" "--libs" "--cflags" "glib-2.0" "glib-2.0 >= 2.44"`: The system cannot find the file specified. (os error 2)` 

which is because there is no pkg-config on the path, and the gtk-rs sys crates use system_deps which only support pkg-config according to the docs. It's not clear to me how this used to work. Did the sys crates look at the LIB and GTK_LIB_DIR variables? Did vcpkg include pkg-config on the path? As far as I can tell there is no pkg-config package in vcpkg, it appears very much centred around Visual Studio and CMake.

So given that apparently the method with environment variables no longer works and pkg-config is not a thing in MSVC land, the GNU way seems more appealing for now. Just need to reverse-engineer those pesky launchers.

After a bit of prodding, this seems to do the trick:

msys2_shell.cmd -mingw64 -defterm -no-start -c "/c/Users/pepij/.cargo/bin/cargo"

Problem: this would require wrapping every single command in this mess.

It appears another way is to source the /etc/profile from a bash shell on windows. Currently this gets you the git for windows shell, but there is actually a PR to change it to the MSYS2 git shell: actions/runner-images#1525

I'll probably hold off on this until that gets merged. This should make everything a lot easier. Just a single pacman command and the already existing cargo commands.

@eine
Copy link

eine commented Nov 28, 2020

This actually gets you a working app. So now the challenge is getting this into CI. The good news is the windows-latest image includes MSYS2 already. The bad news is it doesn't allow installation caching.

You might want to have a look at https://github.com/msys2/setup-msys2#context

The most annoying part is figuring out how to enter the "MSYS2 MinGW 64-bit" universe without the GUI launcher.

Also https://github.com/msys2/setup-msys2#usage and https://github.com/msys2/setup-msys2#path-type.

@pepijndevos
Copy link
Collaborator Author

Thanks @eine I managed to get it working :)

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

No branches or pull requests

2 participants