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

Various Windows fixes #537

Merged
merged 5 commits into from
Sep 27, 2024
Merged

Various Windows fixes #537

merged 5 commits into from
Sep 27, 2024

Conversation

alexdewar
Copy link
Contributor

@alexdewar alexdewar commented Sep 27, 2024

This PR fixes the Windows (MSVC) build of HGPS.

There were a few issues I had in trying to get HGPS to run on Windows:

  1. A bunch of dependent DLLs were missing from the install directory, meaning both local and CI builds wouldn't run. Fixed by scanning the exe for depending DLLs and including them.
  2. There were a few places where fstreams were being opened in text mode rather than binary mode, which won't work with binary files on Windows
  3. A trailing slash on the end of directory names was breaking things

Fixes #533. Fixes #536.

Scan the executable to figure out the dependencies and copy them into the install folder.

Fixes #533.
This affects both downloading zip files and calculating checksums for files.

Fixes #536.
It returns false if the directory already exists and we seem to be getting spurious failures. Let's not bother checking the return value; we only care about file creation anyway and we are checking that.
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 49.12%. Comparing base (46c27c1) to head (75d6469).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/HealthGPS.Input/zip_file.cpp 0.00% 2 Missing ⚠️
src/HealthGPS.Input/download_file.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #537      +/-   ##
==========================================
+ Coverage   48.72%   49.12%   +0.40%     
==========================================
  Files         164      164              
  Lines        7795     7796       +1     
  Branches     1063     1062       -1     
==========================================
+ Hits         3798     3830      +32     
+ Misses       3988     3957      -31     
  Partials        9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexdewar
Copy link
Contributor Author

Btw: Windows binaries should work fine with wine. I had to install the Visual C++ redist library too: winetricks vcrun2022

It's handy if you want to test that the CI-generated Windows binaries work without having to boot Windows.

Copy link
Contributor

@jamesturner246 jamesturner246 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Not sure I understand the CMake changes, RUNTIME, ARCHIVE, LIBRARY, RUNTIME, .... And esp. the windows part.

Also is the create directory exception not needed anymore?

I trust it's right, so LGTM.

@@ -62,11 +62,12 @@ void extract_zip_file(const std::filesystem::path &file_path,
for (const auto &entry : zf.getEntries()) {
out_path = temp_output_directory / entry.getName();
if (entry.isDirectory()) {
if (!std::filesystem::create_directories(out_path)) {
throw std::runtime_error{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the exception any more?

@alexdewar
Copy link
Contributor Author

Okay. Not sure I understand the CMake changes, RUNTIME, ARCHIVE, LIBRARY, RUNTIME, .... And esp. the windows part.

I don't entirely understand why those bits were needed either 🙃. I copied from here: https://stackoverflow.com/questions/10671916/how-to-copy-dll-files-into-the-same-folder-as-the-executable-using-cmake

The bit about installing RUNTIME_DEPENDENCIES just figures out what DLLs are needed for the EXE, excluding system libraries, and copies them to the install folder.

Also is the create directory exception not needed anymore?

I was getting spurious failures here, I think because the extra . causes Windows to try to create a directory twice which fails. Yuck. Anyway, it works fine if we just assume that directories are created successfully and raise errors if creating files fails.

@alexdewar alexdewar merged commit eaea66b into main Sep 27, 2024
6 of 7 checks passed
@alexdewar alexdewar deleted the windows-fixes branch September 27, 2024 10:36
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

Successfully merging this pull request may close these issues.

[BUG] Zip files are corrupted on download on Windows [BUG] Missing DLLs for Windows binaries
2 participants