Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/native-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,65 @@ jobs:
BUILD_DRIVER_SQLITE: "1"
run: .\ci\scripts\cpp_test.ps1 $pwd\build

# ------------------------------------------------------------
# C/C++ build w/ vcpkg (builds and tests)
# ------------------------------------------------------------
drivers-build-vcpkg:
name: "C/C++ (vcpkg/${{ matrix.os }}/${{ matrix.arch }}/${{ matrix.config }})"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["windows-latest"]
arch: ["x64"]
config: ["Debug"]
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2

- name: Clone vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
git checkout 9e4b86d4871c47f125e9f631de07d963fcd38389
.\bootstrap-vcpkg.bat

- name: Cache vcpkg dependencies
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/vcpkg/packages
${{ github.workspace }}/vcpkg/installed
~\AppData\Local\vcpkg\archives
key: vcpkg-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('c/vcpkg.json', 'c/driver/*/vcpkg.json') }}

- name: Install vcpkg dependencies
working-directory: c
env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
run: |
${{ github.workspace }}/vcpkg/vcpkg.exe install --triplet ${{ matrix.arch }}-windows

- name: Build
env:
BUILD_ALL: "1"
BUILD_DRIVER_MANAGER_USER_CONFIG_TEST: "1"
CMAKE_BUILD_TYPE: ${{ matrix.config }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
run: .\ci\scripts\cpp_build.ps1 $pwd $pwd\build

- name: Test
env:
BUILD_ALL: "0"
BUILD_DRIVER_MANAGER: "1"
BUILD_DRIVER_MANAGER_USER_CONFIG_TEST: "1"
BUILD_DRIVER_SQLITE: "1"
run: .\ci\scripts\cpp_test.ps1 $pwd\build

# ------------------------------------------------------------
# Go build
# ------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

vcpkg_installed/
38 changes: 38 additions & 0 deletions c/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,44 @@
"ADBC_USE_ASAN": "OFF",
"ADBC_USE_UBSAN": "OFF"
}
},
{
"name": "vcpkg",
"hidden": true,
"generator": "Ninja",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"ADBC_BUILD_TESTS": "ON",
"ADBC_DRIVER_FLIGHTSQL": "ON",
"ADBC_DRIVER_MANAGER": "ON",
"ADBC_DRIVER_POSTGRESQL": "ON",
"ADBC_DRIVER_SNOWFLAKE": "ON",
"ADBC_DRIVER_SQLITE": "ON",
"ADBC_BUILD_SHARED": "ON",
"ADBC_BUILD_STATIC": "OFF",
"ADBC_USE_ASAN": "OFF",
"ADBC_USE_UBSAN": "OFF"
}
},
{
"name": "windows-debug",
"displayName": "Windows x64 Debug",
"inherits": "vcpkg",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "windows-release",
"displayName": "Windows x64 Release",
"inherits": "vcpkg",
"binaryDir": "${sourceDir}/build-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"testPresets": [
Expand Down
14 changes: 14 additions & 0 deletions c/cmake_modules/AdbcDefines.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ if(MSVC)
# Nanoarrow emits a lot of conversion warnings
add_compile_options(/wd4365)
add_compile_options(/wd4242)
# Don't warn about hidden virtual functions (see DriverQuirks)
add_compile_options(/wd4266)
add_compile_options(/wd4458)
add_compile_options(/wd4514)
add_compile_options(/wd4582)
Expand All @@ -97,6 +99,18 @@ if(MSVC)
add_compile_options(/wd4820)
# Don't warn about enforcing left-to-right evaluation order for operator[]
add_compile_options(/wd4866)
# Don't warn about unary minus applied to unsigned type
add_compile_options(/wd4146)
# Don't warn about type conversions that may lose data
add_compile_options(/wd4244)
# Don't warn about size_t to int conversions
add_compile_options(/wd4267)
# Don't warn about double to float truncation
add_compile_options(/wd4305)
# Don't warn about signed integral constant overflow
add_compile_options(/wd4307)
# Don't warn about implicitly deleted move constructors in GoogleTest fixtures
add_compile_options(/wd5026)
add_compile_options(/wd5027)
add_compile_options(/wd5039)
add_compile_options(/wd5045)
Expand Down
126 changes: 96 additions & 30 deletions c/cmake_modules/GoUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
find_program(GO_BIN "go" REQUIRED)
message(STATUS "Detecting Go executable: Found ${GO_BIN}")

if(WIN32)
# Find tools for generating import libraries from Go DLLs since Go doesn't
# produce .lib files
find_program(GENDEF_BIN NAMES gendef)
find_program(DLLTOOL_BIN NAMES dlltool)
if(GENDEF_BIN AND DLLTOOL_BIN)
message(STATUS "Found gendef: ${GENDEF_BIN}")
message(STATUS "Found dlltool: ${DLLTOOL_BIN}")
else()
message(WARNING "gendef and/or dlltool not found - Go driver import libraries won't be automatically created"
)
message(WARNING "Install MinGW64 and add it to your PATH to make them available")
endif()
endif()

set(ADBC_GO_PACKAGE_INIT
[=[
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
Expand Down Expand Up @@ -184,36 +199,88 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
list(APPEND GO_ENV_VARS "GOARCH=arm64")
endif()

add_custom_command(OUTPUT "${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}"
Copy link
Member Author

Choose a reason for hiding this comment

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

Reviewer note: The rest of this file I used a combination of Claude Code and the previous PR and comments therein to come up with something that worked. I want to go back over this tomorrow with fresh eyes but I thought I'd point it out in case it helps review.

WORKING_DIRECTORY ${GO_MOD_DIR}
DEPENDS ${ARG_SOURCES}
COMMAND ${CMAKE_COMMAND} -E env ${GO_ENV_VARS} ${GO_BIN} build
${GO_BUILD_TAGS} "${GO_BUILD_FLAGS}" -o
${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}
-buildmode=c-shared ${GO_LDFLAGS} .
COMMAND ${CMAKE_COMMAND} -E remove -f
"${LIBOUT_SHARED}.${ADBC_SO_VERSION}.0.h"
COMMENT "Building Go Shared lib ${GO_LIBNAME}"
COMMAND_EXPAND_LISTS)
# Set platform-specific library output paths and generate header name
if(WIN32)
# On Windows, Go generates .dll and .lib with the base name (no version suffix)
set(GO_OUTPUT_LIB "${LIBOUT_SHARED}")
set(GO_OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/${GO_LIBNAME}.h")
set(LIBIMPLIB_SHARED
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}${GO_LIBNAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
)
set(LIBDEF_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${GO_LIBNAME}.def")
else()
# On Unix-like systems, use version suffixes
set(GO_OUTPUT_LIB "${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}")
set(GO_OUTPUT_HEADER "${LIBOUT_SHARED}.${ADBC_SO_VERSION}.0.h")
endif()

add_custom_command(OUTPUT "${LIBOUT_SHARED}.${ADBC_SO_VERSION}" "${LIBOUT_SHARED}"
DEPENDS "${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${LIB_NAME_SHARED}.${ADBC_FULL_SO_VERSION}"
"${LIB_NAME_SHARED}.${ADBC_SO_VERSION}"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${LIB_NAME_SHARED}.${ADBC_SO_VERSION}"
"${LIB_NAME_SHARED}")

add_custom_target(${GO_LIBNAME}_target ALL
DEPENDS "${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}"
"${LIBOUT_SHARED}.${ADBC_SO_VERSION}" "${LIBOUT_SHARED}")
# Common Go build command
set(GO_BUILD_COMMAND
${CMAKE_COMMAND} -E env ${GO_ENV_VARS} ${GO_BIN} build ${GO_BUILD_TAGS}
"${GO_BUILD_FLAGS}" -o ${GO_OUTPUT_LIB} -buildmode=c-shared ${GO_LDFLAGS} .)

if(WIN32)
if(GENDEF_BIN AND DLLTOOL_BIN)
# Generate import library using gendef + dlltool
add_custom_command(OUTPUT "${GO_OUTPUT_LIB}" "${LIBIMPLIB_SHARED}"
WORKING_DIRECTORY ${GO_MOD_DIR}
DEPENDS ${ARG_SOURCES}
COMMAND ${GO_BUILD_COMMAND}
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}
${GENDEF_BIN} ${GO_OUTPUT_LIB} -a
COMMAND ${DLLTOOL_BIN} --input-def ${LIBDEF_OUTPUT} --dllname
${LIB_NAME_SHARED} --output-lib ${LIBIMPLIB_SHARED}
COMMAND ${CMAKE_COMMAND} -E remove -f "${GO_OUTPUT_HEADER}"
COMMENT "Building Go Shared lib ${GO_LIBNAME}"
COMMAND_EXPAND_LISTS)
set(TARGET_DEPENDS "${GO_OUTPUT_LIB}" "${LIBIMPLIB_SHARED}")
else()
# Fallback: try to build without import library generation
add_custom_command(OUTPUT "${GO_OUTPUT_LIB}"
WORKING_DIRECTORY ${GO_MOD_DIR}
DEPENDS ${ARG_SOURCES}
COMMAND ${GO_BUILD_COMMAND}
COMMAND ${CMAKE_COMMAND} -E remove -f "${GO_OUTPUT_HEADER}"
COMMENT "Building Go Shared lib ${GO_LIBNAME}"
COMMAND_EXPAND_LISTS)
set(TARGET_DEPENDS "${GO_OUTPUT_LIB}")
endif()
else()
add_custom_command(OUTPUT "${GO_OUTPUT_LIB}"
WORKING_DIRECTORY ${GO_MOD_DIR}
DEPENDS ${ARG_SOURCES}
COMMAND ${GO_BUILD_COMMAND}
COMMAND ${CMAKE_COMMAND} -E remove -f "${GO_OUTPUT_HEADER}"
COMMENT "Building Go Shared lib ${GO_LIBNAME}"
COMMAND_EXPAND_LISTS)

add_custom_command(OUTPUT "${LIBOUT_SHARED}.${ADBC_SO_VERSION}" "${LIBOUT_SHARED}"
DEPENDS "${GO_OUTPUT_LIB}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${LIB_NAME_SHARED}.${ADBC_FULL_SO_VERSION}"
"${LIB_NAME_SHARED}.${ADBC_SO_VERSION}"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${LIB_NAME_SHARED}.${ADBC_SO_VERSION}"
"${LIB_NAME_SHARED}")
set(TARGET_DEPENDS "${GO_OUTPUT_LIB}" "${LIBOUT_SHARED}.${ADBC_SO_VERSION}"
"${LIBOUT_SHARED}")
endif()

# Create custom target with platform-specific dependencies
add_custom_target(${GO_LIBNAME}_target ALL DEPENDS ${TARGET_DEPENDS})

# Create imported library with platform-specific properties
add_library(${GO_LIBNAME}_shared SHARED IMPORTED GLOBAL)
set_target_properties(${GO_LIBNAME}_shared
PROPERTIES IMPORTED_LOCATION
"${LIBOUT_SHARED}.${ADBC_FULL_SO_VERSION}"
IMPORTED_SONAME "${LIB_NAME_SHARED}")
if(WIN32)
set_target_properties(${GO_LIBNAME}_shared
PROPERTIES IMPORTED_LOCATION "${LIBOUT_SHARED}"
IMPORTED_IMPLIB "${LIBIMPLIB_SHARED}")
else()
set_target_properties(${GO_LIBNAME}_shared
PROPERTIES IMPORTED_LOCATION "${GO_OUTPUT_LIB}"
IMPORTED_SONAME "${LIB_NAME_SHARED}")
endif()
add_dependencies(${GO_LIBNAME}_shared ${GO_LIBNAME}_target)
if(ARG_OUTPUTS)
list(APPEND ${ARG_OUTPUTS} ${GO_LIBNAME}_shared)
Expand Down Expand Up @@ -259,8 +326,7 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
${CMAKE_INSTALL_LIBDIR})
endif()
if(WIN32)
# This symlink doesn't get installed
install(FILES "${LIBOUT_SHARED}.${ADBC_SO_VERSION}" TYPE BIN)
install(FILES "${LIBIMPLIB_SHARED}" TYPE LIB)
else()
install(FILES "${LIBOUT_SHARED}" "${LIBOUT_SHARED}.${ADBC_SO_VERSION}" TYPE LIB)
endif()
Expand Down
14 changes: 14 additions & 0 deletions c/driver/postgresql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ foreach(LIB_TARGET ${ADBC_LIBRARIES})
if(NOT ADBC_DEFINE_COMMON_ENTRYPOINTS)
target_compile_definitions(${LIB_TARGET} PRIVATE ${ADBC_TARGET_COMPILE_DEFINITIONS})
endif()

# On Windows, install libpq.dll and its dependencies alongside the driver
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
install(RUNTIME_DEPENDENCY_SET
${LIB_TARGET}_runtime_deps
PRE_EXCLUDE_REGEXES
"api-ms-"
"ext-ms-"
POST_EXCLUDE_REGEXES
".*system32/.*\\.dll"
DESTINATION
${RUNTIME_INSTALL_DIR})
install(TARGETS ${LIB_TARGET} RUNTIME_DEPENDENCY_SET ${LIB_TARGET}_runtime_deps)
endif()
endforeach()

if(ADBC_TEST_LINKAGE STREQUAL "shared")
Expand Down
14 changes: 14 additions & 0 deletions c/driver/sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ foreach(LIB_TARGET ${ADBC_LIBRARIES})
if(NOT ADBC_DEFINE_COMMON_ENTRYPOINTS)
target_compile_definitions(${LIB_TARGET} PRIVATE ${ADBC_TARGET_COMPILE_DEFINITIONS})
endif()

# On Windows, install sqlite3.dll alongside the driver
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need a cmake version check?

Copy link
Member Author

Choose a reason for hiding this comment

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

This whole block was mainly to copy runtime deps, I came up with using RUNTIME_DEPENDENCY_SET like this with LLM help and RUNTIME_DEPENDENCY_SET is 3.21, see https://cmake.org/cmake/help/latest/command/install.html. I tried something similar before this and didn't get something working.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's probably a much better way to do this, I can keep working on this part.

Copy link
Member

Choose a reason for hiding this comment

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

I guess then the problem is it won't work on older CMake!

Our minimum is 3.18 right now but maybe we can bump it up?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'll try to come up with something simpler in this PR. It boils down to copying one DLL in the case of sqlite and three in the case of postgresql.

install(RUNTIME_DEPENDENCY_SET
${LIB_TARGET}_runtime_deps
PRE_EXCLUDE_REGEXES
"api-ms-"
"ext-ms-"
POST_EXCLUDE_REGEXES
".*system32/.*\\.dll"
DESTINATION
${RUNTIME_INSTALL_DIR})
install(TARGETS ${LIB_TARGET} RUNTIME_DEPENDENCY_SET ${LIB_TARGET}_runtime_deps)
endif()
endforeach()

include(CheckTypeSize)
Expand Down
7 changes: 7 additions & 0 deletions c/driver/sqlite/statement_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,15 @@ AdbcStatusCode InternalAdbcSqliteBinderBindNext(struct AdbcSqliteBinder* binder,
}
case NANOARROW_TYPE_TIMESTAMP: {
struct ArrowSchemaView bind_schema_view;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4244) // ArrowErrorCode to AdbcStatusCode conversion
#endif
RAISE_NA(ArrowSchemaViewInit(&bind_schema_view, binder->schema.children[col],
&arrow_error));
#ifdef _MSC_VER
#pragma warning(pop)
#endif
enum ArrowTimeUnit unit = bind_schema_view.time_unit;
int64_t value =
ArrowArrayViewGetIntUnsafe(binder->batch.children[col], binder->next_row);
Expand Down
7 changes: 7 additions & 0 deletions c/driver/sqlite/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "adbc-driver-sqlite",
"version-string": "1.0.0a0",
"dependencies": [
"sqlite3"
]
}
2 changes: 1 addition & 1 deletion c/driver_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ if(ADBC_BUILD_TESTS)

if(ADBC_DRIVER_SQLITE)
target_compile_definitions(adbc-driver-manager-test
PRIVATE ADBC_DRIVER_MANAGER_TEST_LIB="${CMAKE_BINARY_DIR}/driver/sqlite/libadbc_driver_sqlite${CMAKE_SHARED_LIBRARY_SUFFIX}"
PRIVATE ADBC_DRIVER_MANAGER_TEST_LIB="${CMAKE_BINARY_DIR}/driver/sqlite/${CMAKE_SHARED_LIBRARY_PREFIX}adbc_driver_sqlite${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
endif()
if(ADBC_DRIVER_MANAGER_TEST_MANIFEST_USER_LEVEL)
Expand Down
Loading
Loading