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

GH-41134: [GLib] Support building arrow-glib with MSVC #41599

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

adamreeve
Copy link
Contributor

@adamreeve adamreeve commented May 9, 2024

Rationale for this change

Allow Windows users to more easily build the GLib libraries.

What changes are included in this PR?

  • Minor fixes to allow building with MSVC:
    • Changes some uses of variable length arrays to std::vector, because MSVC doesn't support variable length arrays
    • Moves some function definitions that use C++ types outside of G_BEGIN_DECLS/G_END_DECLS blocks (which expand to extern C { }), because this caused MSVC to error
  • Fix libraries not having any exported symbols with MSVC, which defaults to hiding symbols
    • Add visibility.h which defines a new GARROW_EXTERN macro that adds dllimport or dllexport attributes when using MSVC.
    • Include the GARROW_EXTERN macro in the definitions of the GARROW_AVAILABLE_IN_* macros.
  • Add a new CI job that builds the GLib libraries with MSVC on Windows, using vcpkg to install pkgconfig and glib.
  • For now only arrow-glib is built, I can follow up with the other libraries after this PR. That will require introducing new per-library version macros.

Are these changes tested?

The build will be tested in CI but I've only done some quick manual tests that the built library works correctly, I haven't got the ruby tests running against the build yet.

Are there any user-facing changes?

No? Eventually some documentation should be updated when all the GLib libraries can be built with MSVC though

Copy link

github-actions bot commented May 9, 2024

⚠️ GitHub issue #41134 has been automatically assigned in GitHub to PR creator.

@adamreeve adamreeve changed the title GH-41134: [GLib] Support building arrow-glib with MSVC WIP: GH-41134: [GLib] Support building arrow-glib with MSVC May 9, 2024
Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

Thanks!

c_glib/arrow-glib/visibility.h Outdated Show resolved Hide resolved
c_glib/arrow-glib/visibility.h Outdated Show resolved Hide resolved
c_glib/arrow-glib/visibility.h Outdated Show resolved Hide resolved
.github/workflows/ruby.yml Outdated Show resolved Hide resolved
env:
# We can invalidate the current cache by updating this.
CACHE_VERSION: "2024-05-09"
- name: Build
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- name: Build
- name: Build C++

Copy link
Member

Choose a reason for hiding this comment

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

Can we also use vcpkg to install dependencies of C++?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into this and got it working on another branch (https://github.com/adamreeve/arrow/tree/msvc_glib_vcpkg), but it's quite slow to build all the vcpkg dependencies (48 minutes on my GitHub actions run) and this isn't integrated with ccache so will be slow every time. If you think it's worth doing I can look at caching the vcpkg builds too? We do this in ParquetSharp so it shouldn't be too hard to add: https://github.com/G-Research/ParquetSharp/blob/ef8e7c447ecd5d84205eb73293162f5689e977b8/.github/workflows/ci.yml#L99-L118

Copy link
Member

Choose a reason for hiding this comment

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

OK. Let's work on it as a separated task.

FYI: We have a job that uses VCPKG_BINARY_SOURCES:

VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'

It may also work.

GArrowArray *
garrow_array_builder_finish(GArrowArrayBuilder *builder, GError **error);

GARROW_AVAILABLE_IN_2_0
GARROW_EXPORT
Copy link
Member

Choose a reason for hiding this comment

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

Let's add this macro to GARROW_AVAILABLE_IN_XXX. GLib does it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I was originally thinking of doing, but then I was worried about how this works with the different garrow libraries. We'd probably need separate available/deprecated macros per library like:

GARROW_AVAILABLE_IN_XXX
GARROW_DEPRECATED_IN_XXX
GARROW_DATASET_AVAILABLE_IN_XXX
GARROW_DATASET_DEPRECATED_IN_XXX
GARROW_FLIGHT_AVAILABLE_IN_XXX
GARROW_FLIGHT_DEPRECATED_IN_XXX
GARROW_FLIGHT_SQL_AVAILABLE_IN_XXX
GARROW_FLIGHT_SQL_DEPRECATD_IN_XXX
...

That way when you build eg. arrow-dataset-glib and include headers from arrow-glib, they can correctly get the dllimport attribute while code in arrow-dataset-glib gets dllexport.

Maybe I should look at integrating that Python script from GLib to reduce the boilerplate required. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Right. We need separated version macros per library.

Copy link
Contributor Author

@adamreeve adamreeve May 10, 2024

Choose a reason for hiding this comment

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

I thought I could have this PR only change the arrow-glib library and do the others in a follow up to keep the changes manageable, but the MinGW build fails with link errors like "redeclared without dllimport attribute after being referenced with dll linkage", so I might need to add the separated version macros as part of this PR too, or make the visibility attributes MSVC only for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the macro definitions to only add dllimport/dllexport for MSVC for now, so this works as currently only the arrow-glib library is built for MSVC. But I can follow up to also add them under MinGW GCC later after adding version macros per-library. Does that work for you or would you rather include the per-library macros in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

How about opening a separated PR that adds version macros per-library, merging it and rebasing on main?

(I'm OK with a follow up approach.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that idea, I've made #41681 for this and will make a PR for that before updating this PR.

ci/scripts/install_vcpkg.sh Outdated Show resolved Hide resolved
ci/scripts/c_glib_build.sh Outdated Show resolved Hide resolved
ci/scripts/c_glib_build.sh Outdated Show resolved Hide resolved
c_glib/vcpkg.json Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting changes Awaiting changes awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting changes Awaiting changes awaiting committer review Awaiting committer review labels May 10, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 10, 2024
@adamreeve adamreeve force-pushed the msvc_glib branch 3 times, most recently from b1ba360 to beffceb Compare May 13, 2024 23:18
ARROW_FLIGHT: OFF
ARROW_FLIGHT_SQL: OFF
ARROW_HDFS: OFF
ARROW_HOME: "${{ github.workspace }}/dist"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to change ARROW_HOME to be in the workspace directory rather than /usr, as /usr becomes C:\Program Files\Git\usr as a Windows path and I was getting errors when linking like:

[47/54] Linking target arrow-glib/arrow-glib-1700.dll
FAILED: arrow-glib/arrow-glib-1700.dll arrow-glib/arrow-glib-1700.pdb 
"link" @arrow-glib/arrow-glib-1700.dll.rsp
LINK : fatal error LNK1181: cannot open input file 'Files\Git\usr\bin.obj'

I didn't get to the bottom of where this was going wrong but it seems like something in meson is failing to quote the linker command inputs.

@adamreeve adamreeve changed the title WIP: GH-41134: [GLib] Support building arrow-glib with MSVC GH-41134: [GLib] Support building arrow-glib with MSVC May 14, 2024
@adamreeve adamreeve marked this pull request as ready for review May 14, 2024 01:38
@raulcd
Copy link
Member

raulcd commented May 14, 2024

@github-actions crossbow submit -g release

Copy link

Invalid group(s) {'release'}. Must be one of {'homebrew', 'linux', 'example-cpp', 'verify-rc-wheels', 'packaging', 'c-glib', 'nightly-packaging', 'wheel', 'verify-rc-binaries', 'linux-arm64', 'python', 'vcpkg', 'linux-amd64', 'fuzz', 'java', 'verify-rc-source-macos', 'example-python', 'test', 'example', 'cpp', 'verify-rc-source', 'ruby', 'verify-rc', 'go', 'nightly-tests', 'conan', 'verify-rc-jars', 'r', 'verify-rc-source-linux', 'nightly-release', 'integration', 'nightly', 'conda'}
The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/9083989638

@raulcd
Copy link
Member

raulcd commented May 14, 2024

@github-actions crossbow submit -g nightly-release

Copy link

Revision: 4dc31f8

Submitted crossbow builds: ursacomputing/crossbow @ actions-012c96d84c

Task Status
verify-rc-source-cpp-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-cpp-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-cpp-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-cpp-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-cpp-macos-amd64 GitHub Actions
verify-rc-source-cpp-macos-arm64 GitHub Actions
verify-rc-source-cpp-macos-conda-amd64 GitHub Actions
verify-rc-source-csharp-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-csharp-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-csharp-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-csharp-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-csharp-macos-amd64 GitHub Actions
verify-rc-source-csharp-macos-arm64 GitHub Actions
verify-rc-source-go-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-go-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-go-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-go-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-go-macos-amd64 GitHub Actions
verify-rc-source-go-macos-arm64 GitHub Actions
verify-rc-source-integration-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-integration-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-integration-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-integration-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-integration-macos-amd64 GitHub Actions
verify-rc-source-integration-macos-arm64 GitHub Actions
verify-rc-source-integration-macos-conda-amd64 GitHub Actions
verify-rc-source-java-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-java-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-java-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-java-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-java-macos-amd64 GitHub Actions
verify-rc-source-js-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-js-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-js-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-js-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-js-macos-amd64 GitHub Actions
verify-rc-source-js-macos-arm64 GitHub Actions
verify-rc-source-python-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-python-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-python-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-python-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-python-macos-amd64 GitHub Actions
verify-rc-source-python-macos-arm64 GitHub Actions
verify-rc-source-python-macos-conda-amd64 GitHub Actions
verify-rc-source-ruby-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-ruby-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-ruby-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-ruby-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-ruby-macos-amd64 GitHub Actions
verify-rc-source-ruby-macos-arm64 GitHub Actions
verify-rc-source-windows GitHub Actions

@adamreeve
Copy link
Contributor Author

I've rebased on top of the changes from #41721 to add per-library version headers, and added per-library visibility headers too. I've had to keep the Gandiva build disabled due to #36958 and also disabled the Flight libraries due to a missing zlib dependency, but I'm hoping that should be fixed by switching to vcpkg dependencies for the C++ library build.



def write_header(output_file: TextIOBase, library: str):
output_file.write(f"""#pragma once
Copy link
Member

Choose a reason for hiding this comment

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

Could you also generate license header?
Or how about adding this to version.h instead of creating a separated visibility.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah adding this to version.h makes sense, there isn't any good reason it needs to be separate.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels May 23, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants