Skip to content

Commit

Permalink
apacheGH-42130: [GLib] Fix building gir files with MSVC (apache#42131)
Browse files Browse the repository at this point in the history
### Rationale for this change

This is a blocker for apache#41885

### What changes are included in this PR?

* Adds `*_AVAILABLE_IN_ALL` macros to generated enum functions
* Defines `*_COMPILATION` variables when compiling C code, not just C++
* Fixes checking for MSVC in version.h to work when compiling C code as well as C++ code
* Sets the PATH variable to allow loading required dlls when running the binary generated by g-ir-scanner

### Are these changes tested?

Yes (build is run in CI)

### Are there any user-facing changes?

No
* GitHub Issue: apache#42130

Authored-by: Adam Reeve <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
adamreeve authored Jun 20, 2024
1 parent ec28590 commit a01fe03
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ jobs:
ARROW_FLIGHT: ON
ARROW_FLIGHT_SQL: ON
ARROW_GANDIVA: OFF
ARROW_GLIB_VAPI: "false"
ARROW_HDFS: OFF
ARROW_HOME: "${{ github.workspace }}/dist"
ARROW_JEMALLOC: OFF
Expand All @@ -345,6 +346,7 @@ jobs:
CMAKE_UNITY_BUILD: ON
VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'
VCPKG_ROOT: "${{ github.workspace }}/vcpkg"
VCPKG_TRIPLET: x64-windows
permissions:
packages: write
steps:
Expand Down Expand Up @@ -405,7 +407,7 @@ jobs:
-source "https://nuget.pkg.github.com/$GITHUB_REPOSITORY_OWNER/index.json"
- name: Build C++ vcpkg dependencies
run: |
vcpkg\vcpkg.exe install --triplet x64-windows --x-manifest-root cpp --x-install-root build\cpp\vcpkg_installed
vcpkg\vcpkg.exe install --triplet $env:VCPKG_TRIPLET --x-manifest-root cpp --x-install-root build\cpp\vcpkg_installed
- name: Build C++
shell: cmd
run: |
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-dataset-glib/enums.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <glib-object.h>

#include <arrow-dataset-glib/version.h>

G_BEGIN_DECLS
/*** END file-header ***/

Expand All @@ -31,6 +33,7 @@ G_BEGIN_DECLS
/*** END file-production ***/

/*** BEGIN value-header ***/
GADATASET_AVAILABLE_IN_ALL
GType @enum_name@_get_type(void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
/*** END value-header ***/
Expand Down
1 change: 1 addition & 0 deletions c_glib/arrow-dataset-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ libarrow_dataset_glib = library('arrow-dataset-glib',
implicit_include_directories: false,
include_directories: base_include_directories,
cpp_args: ['-DGADATASET_COMPILATION'],
c_args: ['-DGADATASET_COMPILATION'],
soversion: so_version,
version: library_version)
arrow_dataset_glib = declare_dependency(link_with: libarrow_dataset_glib,
Expand Down
3 changes: 3 additions & 0 deletions c_glib/arrow-glib/enums.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <glib-object.h>

#include <arrow-glib/version.h>

G_BEGIN_DECLS
/*** END file-header ***/

Expand All @@ -31,6 +33,7 @@ G_BEGIN_DECLS
/*** END file-production ***/

/*** BEGIN value-header ***/
GARROW_AVAILABLE_IN_ALL
GType @enum_name@_get_type(void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
/*** END value-header ***/
Expand Down
1 change: 1 addition & 0 deletions c_glib/arrow-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ libarrow_glib = library('arrow-glib',
implicit_include_directories: false,
include_directories: base_include_directories,
cpp_args: ['-DGARROW_COMPILATION'],
c_args: ['-DGARROW_COMPILATION'],
soversion: so_version,
version: library_version)
arrow_glib = declare_dependency(link_with: libarrow_glib,
Expand Down
3 changes: 3 additions & 0 deletions c_glib/gandiva-glib/enums.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <glib-object.h>

#include <gandiva-glib/version.h>

G_BEGIN_DECLS
/*** END file-header ***/

Expand All @@ -31,6 +33,7 @@ G_BEGIN_DECLS
/*** END file-production ***/

/*** BEGIN value-header ***/
GGANDIVA_AVAILABLE_IN_ALL
GType @enum_name@_get_type(void) G_GNUC_CONST;
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
/*** END value-header ***/
Expand Down
1 change: 1 addition & 0 deletions c_glib/gandiva-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ libgandiva_glib = library('gandiva-glib',
implicit_include_directories: false,
include_directories: base_include_directories,
cpp_args: ['-DGGANDIVA_COMPILATION'],
c_args: ['-DGGANDIVA_COMPILATION'],
soversion: so_version,
version: library_version)
gandiva_glib = declare_dependency(link_with: libgandiva_glib,
Expand Down
2 changes: 1 addition & 1 deletion c_glib/tool/generate-version-header.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def write_header(


def generate_visibility_macros(library: str) -> str:
return f"""#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_MSVC_LANG) && \
return f"""#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_MSC_VER) && \
!defined({library}_STATIC_COMPILATION)
# define {library}_EXPORT __declspec(dllexport)
# define {library}_IMPORT __declspec(dllimport)
Expand Down
1 change: 1 addition & 0 deletions c_glib/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version-string": "17.0.0-SNAPSHOT",
"dependencies": [
"glib",
"gobject-introspection",
"pkgconf"
]
}
13 changes: 10 additions & 3 deletions ci/scripts/c_glib_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ if [ -n "${MSYSTEM:-}" ]; then
export ARROW_HOME="$(cygpath --unix "${ARROW_HOME}")"
fi

export PATH="${ARROW_HOME}/bin:${PATH}"

meson_pkg_config_path="${ARROW_HOME}/lib/pkgconfig"

mkdir -p ${build_dir}

if [ -n "${VCPKG_ROOT:-}" ]; then
if [ -n "${VCPKG_ROOT:-}" -a -n "${VCPKG_TRIPLET:-}" ]; then
vcpkg_install_root="${build_root}/vcpkg_installed"
$VCPKG_ROOT/vcpkg install --x-manifest-root=${source_dir} --x-install-root=${vcpkg_install_root}
export PKG_CONFIG="${vcpkg_install_root}/x64-windows/tools/pkgconf/pkgconf.exe"
meson_pkg_config_path="${vcpkg_install_root}/x64-windows/lib/pkgconfig:${meson_pkg_config_path}"
export PKG_CONFIG="${vcpkg_install_root}/${VCPKG_TRIPLET}/tools/pkgconf/pkgconf.exe"
meson_pkg_config_path="${vcpkg_install_root}/${VCPKG_TRIPLET}/lib/pkgconfig:${meson_pkg_config_path}"
# Configure PATH for libraries required by the gobject-introspection generated binary
cpp_vcpkg_install_root="${build_root}/cpp/vcpkg_installed"
PATH="${cpp_vcpkg_install_root}/${VCPKG_TRIPLET}/debug/bin:${PATH}"
PATH="${cpp_vcpkg_install_root}/${VCPKG_TRIPLET}/bin:${PATH}"
export PATH="${vcpkg_install_root}/${VCPKG_TRIPLET}/bin:${PATH}"
fi

if [ -n "${VCToolsInstallDir:-}" -a -n "${MSYSTEM:-}" ]; then
Expand Down

0 comments on commit a01fe03

Please sign in to comment.