You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2025/04/23 07:53:51 UTC

[PR] fix(c): enable linking to static builds [arrow-adbc]

lidavidm opened a new pull request, #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738

   - Correct a typo that was causing CMake to look for the shared library instead of the static library.
   - [ ] Fix CMake looking for the static library in the wrong place.
   - [ ] Test that linking against the static library works.
   - [ ] Test that linking with system-provided fmt/nanoarrow works.
   - [ ] Test that linking against multiple static drivers works.
   - [ ] Add headers to provide the entrypoint for static drivers.
   
   Fixes #2562.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "WillAyd (via GitHub)" <gi...@apache.org>.
WillAyd commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2059375495


##########
docs/source/cpp/static_linking.rst:
##########
@@ -0,0 +1,64 @@
+.. 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.
+
+==============
+Static Linking
+==============
+
+To statically link and use *multiple* drivers, the following limitations hold:
+
+#. You must build with these CMake options [#meson]_:
+
+   - ``-DADBC_BUILD_STATIC=ON``
+   - ``-DADBC_DEFINE_COMMON_ENTRYPOINTS=OFF``
+   - ``-DADBC_WITH_VENDORED_FMT=OFF``
+   - ``-DADBC_WITH_VENDORED_NANOARROW=OFF``
+
+#. You must provide ``fmt`` and ``nanoarrow`` dependencies.  (This may be
+   relaxed in the future.)
+#. You must explicitly link all the required transitive dependencies.  This
+   is:
+
+   - ``libpq`` for PostgreSQL
+   - ``sqlite3`` for SQLite
+   - ``adbc_driver_common``, ``adbc_driver_framework``, ``fmt``,
+     ``nanoarrow``, and the C++ standard library for either PostgreSQL or
+     SQLite.
+   - To link the C++ standard library, the easiest thing is to just use the
+     C++ linker, even if the code itself is in C, e.g.
+
+     .. code-block:: cmake
+
+        set_target_properties(myapp PROPERTIES LINKER_LANGUAGE CXX)
+
+   - Go-based drivers (BigQuery, Flight SQL, Snowflake) have no transitive
+     dependencies.
+
+#. You cannot link more than a single Go-based driver.  See `golang/go#20639
+   <go20639_>`_, `StackOverflow #67243572 <so67243572_>`_, and `StackOverflow
+   #34333107 <so34333107_>`_ for a discussion of the issues involved.  (This
+   may be relaxed in the future by providing a way to build a single driver
+   library with all driver implementations included.)
+
+An example of this can be seen with ``cpp_static_test.sh`` and
+``c/integration/static_test`` in the source tree.
+
+.. [#meson] There is currently no documentation for Meson, but in principle

Review Comment:
   Yea I think if we try to do this in the Meson configuration it should be as easy as something like:
   
   ```python
   if get_option('default_library') == 'static'
       add_project_arguments('-DADBC_NO_COMMON_ENTRYPOINTS', language: 'c')
       add_project_arguments('-DADBC_NO_COMMON_ENTRYPOINTS', language: 'cpp')
   endif
   ```
   
   There might be some extra work for MSVC where both shared and static are built by default. We could either punt that or ping eli on the Meson team for thoughts



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#issuecomment-2824496300

   Yup, the CMake fixes are to make it actually work with CMake :sweat_smile: 
   
   This still isn't building FWIW - I need to get adbc_driver_common exported properly


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#issuecomment-2835254342

   @WillAyd @kou any comments here? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2065217031


##########
c/cmake_modules/GoUtils.cmake:
##########
@@ -135,10 +135,20 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
                      "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
 
   # if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
-  set(GO_ENV_VARS
-      "CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
-  )
-  separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
+  set(GO_FLAGS)
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(GO_FLAGS "-g3")
+  endif()
+  string(JOIN " " GO_FLAGS "${GO_FLAGS}")
+
+  foreach(DEFINE ${ARG_DEFINES})
+    list(APPEND GO_FLAGS "-D${DEFINE}")
+  endforeach()
+
+  set(GO_ENV_VARS)
+  list(APPEND GO_ENV_VARS "CGO_ENABLED=1")
+  list(APPEND GO_ENV_VARS "CGO_CFLAGS=\"${GO_FLAGS}\"")
+  list(APPEND GO_ENV_VARS "CGO_CXXFLAGS=\"${GO_FLAGS}\"")

Review Comment:
   I _think_ I needed this for Windows to be happy but let me try



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2058584824


##########
c/driver/common/CMakeLists.txt:
##########
@@ -21,6 +21,22 @@ set_target_properties(adbc_driver_common PROPERTIES POSITION_INDEPENDENT_CODE ON
 target_include_directories(adbc_driver_common PRIVATE "${REPOSITORY_ROOT}/c/include")
 target_link_libraries(adbc_driver_common PUBLIC nanoarrow::nanoarrow)
 
+# For static builds, we need to install the static library here so downstream
+# applications can link to it
+if(ADBC_BUILD_STATIC)
+  if(ADBC_WITH_VENDORED_NANOARROW)
+    message(WARNING "adbc_driver_common is not installed when ADBC_WITH_VENDORED_NANOARROW is ON. To use the static libraries, for now you must provide nanoarrow instead of using the vendored copy"

Review Comment:
   I am guessing that it would install/require the headers and ADBC should probably not be installing headers for `nanoarrow/`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2059364314


##########
docs/source/cpp/static_linking.rst:
##########
@@ -0,0 +1,64 @@
+.. 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.
+
+==============
+Static Linking
+==============
+
+To statically link and use *multiple* drivers, the following limitations hold:
+
+#. You must build with these CMake options [#meson]_:
+
+   - ``-DADBC_BUILD_STATIC=ON``
+   - ``-DADBC_DEFINE_COMMON_ENTRYPOINTS=OFF``
+   - ``-DADBC_WITH_VENDORED_FMT=OFF``
+   - ``-DADBC_WITH_VENDORED_NANOARROW=OFF``
+
+#. You must provide ``fmt`` and ``nanoarrow`` dependencies.  (This may be
+   relaxed in the future.)
+#. You must explicitly link all the required transitive dependencies.  This
+   is:
+
+   - ``libpq`` for PostgreSQL
+   - ``sqlite3`` for SQLite
+   - ``adbc_driver_common``, ``adbc_driver_framework``, ``fmt``,
+     ``nanoarrow``, and the C++ standard library for either PostgreSQL or
+     SQLite.
+   - To link the C++ standard library, the easiest thing is to just use the
+     C++ linker, even if the code itself is in C, e.g.
+
+     .. code-block:: cmake
+
+        set_target_properties(myapp PROPERTIES LINKER_LANGUAGE CXX)
+
+   - Go-based drivers (BigQuery, Flight SQL, Snowflake) have no transitive
+     dependencies.
+
+#. You cannot link more than a single Go-based driver.  See `golang/go#20639
+   <go20639_>`_, `StackOverflow #67243572 <so67243572_>`_, and `StackOverflow
+   #34333107 <so34333107_>`_ for a discussion of the issues involved.  (This
+   may be relaxed in the future by providing a way to build a single driver
+   library with all driver implementations included.)
+
+An example of this can be seen with ``cpp_static_test.sh`` and
+``c/integration/static_test`` in the source tree.
+
+.. [#meson] There is currently no documentation for Meson, but in principle

Review Comment:
   Maybe I should learn Meson :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "WillAyd (via GitHub)" <gi...@apache.org>.
WillAyd commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2063700465


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,40 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#ifndef ADBC_DRIVER_BIGQUERY_H
+#define ADBC_DRIVER_BIGQUERY_H
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT

Review Comment:
   Ah OK - thanks for confirming



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2067721425


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,35 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT
+AdbcStatusCode BigQueryDriverInit(int version, void* raw_driver, struct AdbcError* error);

Review Comment:
   I've updated all of these. I've retained the old names for backwards compatibility.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#issuecomment-2829490369

   Ok, I think everything is working here now...more changes than I expected


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2063689641


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,40 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#ifndef ADBC_DRIVER_BIGQUERY_H
+#define ADBC_DRIVER_BIGQUERY_H
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT

Review Comment:
   I don't think it applies: `utils.c` contains the `AdbcDriverInit` only and I think that needs to keep the export. `BigQueryDriverInit` is exported by Go which won't see the declaration in C. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2064961480


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,35 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT
+AdbcStatusCode BigQueryDriverInit(int version, void* raw_driver, struct AdbcError* error);

Review Comment:
   We may want to add `Adbc` prefix for `*DriverInit()` functions:
   
   ```suggestion
   AdbcStatusCode AdbcBigQueryDriverInit(int version, void* raw_driver, struct AdbcError* error);
   ```



##########
c/cmake_modules/GoUtils.cmake:
##########
@@ -135,10 +135,20 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
                      "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
 
   # if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
-  set(GO_ENV_VARS
-      "CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
-  )
-  separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
+  set(GO_FLAGS)
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(GO_FLAGS "-g3")
+  endif()
+  string(JOIN " " GO_FLAGS "${GO_FLAGS}")
+
+  foreach(DEFINE ${ARG_DEFINES})
+    list(APPEND GO_FLAGS "-D${DEFINE}")

Review Comment:
   It seems that `GO_FLAGS` is string here.
   
   Should we use `string(APPEND)` here?
   
   ```suggestion
     string(JOIN " " GO_FLAGS "${GO_FLAGS}")
   
     foreach(DEFINE ${ARG_DEFINES})
       string(APPEND GO_FLAGS " -D${DEFINE}")
   ```



##########
c/cmake_modules/GoUtils.cmake:
##########
@@ -135,10 +135,20 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
                      "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
 
   # if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
-  set(GO_ENV_VARS
-      "CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
-  )
-  separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
+  set(GO_FLAGS)
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(GO_FLAGS "-g3")
+  endif()
+  string(JOIN " " GO_FLAGS "${GO_FLAGS}")
+
+  foreach(DEFINE ${ARG_DEFINES})
+    list(APPEND GO_FLAGS "-D${DEFINE}")
+  endforeach()
+
+  set(GO_ENV_VARS)
+  list(APPEND GO_ENV_VARS "CGO_ENABLED=1")
+  list(APPEND GO_ENV_VARS "CGO_CFLAGS=\"${GO_FLAGS}\"")
+  list(APPEND GO_ENV_VARS "CGO_CXXFLAGS=\"${GO_FLAGS}\"")

Review Comment:
   Do we need to escape `"` here? (Does `cmake -E env` care about it?)



##########
c/cmake_modules/GoUtils.cmake:
##########
@@ -135,10 +135,20 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
                      "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
 
   # if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
-  set(GO_ENV_VARS
-      "CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
-  )
-  separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
+  set(GO_FLAGS)
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(GO_FLAGS "-g3")
+  endif()

Review Comment:
   We can use generator expression:
   
   ```suggestion
     set(GO_FLAGS "$<$<CONFIG:Debug>:-g3>")
   ```
   
   In general generator expression is better than `CMAKE_BUILD_TYPE STREQUAL "Debug"` because `STREQUAL` is case sensitive but `$<CONFIG:Debug>` is case insensitive (`CMAKE_BUILD_TYPE=DEBUG` is also accepted like other `CMAKE_BUILD_TYPE` checks).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2059364172


##########
c/driver/common/utils.c:
##########
@@ -27,7 +27,7 @@
 
 static size_t kErrorBufferSize = 1024;
 
-int AdbcStatusCodeToErrno(AdbcStatusCode code) {
+int PrivateAdbcStatusCodeToErrno(AdbcStatusCode code) {

Review Comment:
   Ah, I can change it. I saw for Nanoarrow we used the 'Private' prefix which is why I went with that



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2065216785


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,35 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT
+AdbcStatusCode BigQueryDriverInit(int version, void* raw_driver, struct AdbcError* error);

Review Comment:
   From `adbc.h` it seems this should be `AdbcDriverBigQueryInit`. I'll make sure these are consistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2065217506


##########
c/cmake_modules/GoUtils.cmake:
##########
@@ -135,10 +135,20 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
                      "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
 
   # if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
-  set(GO_ENV_VARS
-      "CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
-  )
-  separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
+  set(GO_FLAGS)
+  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(GO_FLAGS "-g3")
+  endif()
+  string(JOIN " " GO_FLAGS "${GO_FLAGS}")
+
+  foreach(DEFINE ${ARG_DEFINES})
+    list(APPEND GO_FLAGS "-D${DEFINE}")
+  endforeach()
+
+  set(GO_ENV_VARS)
+  list(APPEND GO_ENV_VARS "CGO_ENABLED=1")
+  list(APPEND GO_ENV_VARS "CGO_CFLAGS=\"${GO_FLAGS}\"")
+  list(APPEND GO_ENV_VARS "CGO_CXXFLAGS=\"${GO_FLAGS}\"")

Review Comment:
   But the escape isn't for `cmake -E env`, it's to escape the nested quotes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "WillAyd (via GitHub)" <gi...@apache.org>.
WillAyd commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2058250884


##########
c/driver/common/CMakeLists.txt:
##########
@@ -21,6 +21,22 @@ set_target_properties(adbc_driver_common PROPERTIES POSITION_INDEPENDENT_CODE ON
 target_include_directories(adbc_driver_common PRIVATE "${REPOSITORY_ROOT}/c/include")
 target_link_libraries(adbc_driver_common PUBLIC nanoarrow::nanoarrow)
 
+# For static builds, we need to install the static library here so downstream
+# applications can link to it
+if(ADBC_BUILD_STATIC)
+  if(ADBC_WITH_VENDORED_NANOARROW)
+    message(WARNING "adbc_driver_common is not installed when ADBC_WITH_VENDORED_NANOARROW is ON. To use the static libraries, for now you must provide nanoarrow instead of using the vendored copy"

Review Comment:
   What is the problem with installing in this case?



##########
c/driver/common/utils.c:
##########
@@ -27,7 +27,7 @@
 
 static size_t kErrorBufferSize = 1024;
 
-int AdbcStatusCodeToErrno(AdbcStatusCode code) {
+int PrivateAdbcStatusCodeToErrno(AdbcStatusCode code) {

Review Comment:
   Nit but maybe this would be better to call Internal instead of Private just to keep in sync with the arrow repo? I know upstream there is even some confusion over the different namespace terminology https://github.com/apache/arrow/issues/45808



##########
docs/source/cpp/static_linking.rst:
##########
@@ -0,0 +1,64 @@
+.. 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.
+
+==============
+Static Linking
+==============
+
+To statically link and use *multiple* drivers, the following limitations hold:
+
+#. You must build with these CMake options [#meson]_:
+
+   - ``-DADBC_BUILD_STATIC=ON``
+   - ``-DADBC_DEFINE_COMMON_ENTRYPOINTS=OFF``
+   - ``-DADBC_WITH_VENDORED_FMT=OFF``
+   - ``-DADBC_WITH_VENDORED_NANOARROW=OFF``
+
+#. You must provide ``fmt`` and ``nanoarrow`` dependencies.  (This may be
+   relaxed in the future.)
+#. You must explicitly link all the required transitive dependencies.  This
+   is:
+
+   - ``libpq`` for PostgreSQL
+   - ``sqlite3`` for SQLite
+   - ``adbc_driver_common``, ``adbc_driver_framework``, ``fmt``,
+     ``nanoarrow``, and the C++ standard library for either PostgreSQL or
+     SQLite.
+   - To link the C++ standard library, the easiest thing is to just use the
+     C++ linker, even if the code itself is in C, e.g.
+
+     .. code-block:: cmake
+
+        set_target_properties(myapp PROPERTIES LINKER_LANGUAGE CXX)
+
+   - Go-based drivers (BigQuery, Flight SQL, Snowflake) have no transitive
+     dependencies.
+
+#. You cannot link more than a single Go-based driver.  See `golang/go#20639
+   <go20639_>`_, `StackOverflow #67243572 <so67243572_>`_, and `StackOverflow
+   #34333107 <so34333107_>`_ for a discussion of the issues involved.  (This
+   may be relaxed in the future by providing a way to build a single driver
+   library with all driver implementations included.)
+
+An example of this can be seen with ``cpp_static_test.sh`` and
+``c/integration/static_test`` in the source tree.
+
+.. [#meson] There is currently no documentation for Meson, but in principle

Review Comment:
   For Meson I believe you just need to do
   
   ```
   meson setup -Ddefault_library=static \
       -Dc_args="-DADBC_NO_COMMON_ENTRYPOINTS 
       -Dcpp_args="-DADBC_NO_COMMON_ENTRYPOINTS
       ...
   ```
   
   Or, it might be better if we detect whether a shared or static library is being built in the configuration and define those macros for the user, instead of requiring them as c{pp}_args. Doesn't need to be done here of course; can be an easy follow up
   ```
   
   fmt and nanoarrow are both taken care of by the wrap subsystem, so the user shouldn't have to do anything extra with those



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "WillAyd (via GitHub)" <gi...@apache.org>.
WillAyd commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2059375495


##########
docs/source/cpp/static_linking.rst:
##########
@@ -0,0 +1,64 @@
+.. 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.
+
+==============
+Static Linking
+==============
+
+To statically link and use *multiple* drivers, the following limitations hold:
+
+#. You must build with these CMake options [#meson]_:
+
+   - ``-DADBC_BUILD_STATIC=ON``
+   - ``-DADBC_DEFINE_COMMON_ENTRYPOINTS=OFF``
+   - ``-DADBC_WITH_VENDORED_FMT=OFF``
+   - ``-DADBC_WITH_VENDORED_NANOARROW=OFF``
+
+#. You must provide ``fmt`` and ``nanoarrow`` dependencies.  (This may be
+   relaxed in the future.)
+#. You must explicitly link all the required transitive dependencies.  This
+   is:
+
+   - ``libpq`` for PostgreSQL
+   - ``sqlite3`` for SQLite
+   - ``adbc_driver_common``, ``adbc_driver_framework``, ``fmt``,
+     ``nanoarrow``, and the C++ standard library for either PostgreSQL or
+     SQLite.
+   - To link the C++ standard library, the easiest thing is to just use the
+     C++ linker, even if the code itself is in C, e.g.
+
+     .. code-block:: cmake
+
+        set_target_properties(myapp PROPERTIES LINKER_LANGUAGE CXX)
+
+   - Go-based drivers (BigQuery, Flight SQL, Snowflake) have no transitive
+     dependencies.
+
+#. You cannot link more than a single Go-based driver.  See `golang/go#20639
+   <go20639_>`_, `StackOverflow #67243572 <so67243572_>`_, and `StackOverflow
+   #34333107 <so34333107_>`_ for a discussion of the issues involved.  (This
+   may be relaxed in the future by providing a way to build a single driver
+   library with all driver implementations included.)
+
+An example of this can be seen with ``cpp_static_test.sh`` and
+``c/integration/static_test`` in the source tree.
+
+.. [#meson] There is currently no documentation for Meson, but in principle

Review Comment:
   Yea I think if we try to do this in the Meson configuration it should be as easy as:
   
   ```python
   if get_option('default_library') == 'static'
       add_project_arguments('-DADBC_NO_COMMON_ENTRYPOINTS', language: 'c')
       add_project_arguments('-DADBC_NO_COMMON_ENTRYPOINTS', language: 'cpp')
   endif
   ```
   
   There might be some extra work for MSVC where both shared and static are built by default. We could either punt that or ping eli on the Meson team for thoughts



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2059363952


##########
c/driver/common/CMakeLists.txt:
##########
@@ -21,6 +21,22 @@ set_target_properties(adbc_driver_common PROPERTIES POSITION_INDEPENDENT_CODE ON
 target_include_directories(adbc_driver_common PRIVATE "${REPOSITORY_ROOT}/c/include")
 target_link_libraries(adbc_driver_common PUBLIC nanoarrow::nanoarrow)
 
+# For static builds, we need to install the static library here so downstream
+# applications can link to it
+if(ADBC_BUILD_STATIC)
+  if(ADBC_WITH_VENDORED_NANOARROW)
+    message(WARNING "adbc_driver_common is not installed when ADBC_WITH_VENDORED_NANOARROW is ON. To use the static libraries, for now you must provide nanoarrow instead of using the vendored copy"

Review Comment:
   Yeah, I tried to install Nanoarrow but CMake failed because of something about the header not being installable - decided to punt since to start with I don't think we need to support every possible case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#issuecomment-2823412306

   Thanks, I need to get my global .gitignore back on this new machine...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm merged PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "WillAyd (via GitHub)" <gi...@apache.org>.
WillAyd commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2063663236


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,40 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#ifndef ADBC_DRIVER_BIGQUERY_H
+#define ADBC_DRIVER_BIGQUERY_H
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT

Review Comment:
   Since you are creating these Init methods in header files now can we remove the `ADBC_EXPORT` macro from the corresponding `go/adbc/pkg/<driver>/utils.c` file? I think the export there is rather wonky; this seems like a much cleaner approach



##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,40 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#ifndef ADBC_DRIVER_BIGQUERY_H

Review Comment:
   Since we already have `#pragma once` can we get rid of the manual include guard? Should help simplify the macro usage



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#discussion_r2065216785


##########
c/include/arrow-adbc/driver/bigquery.h:
##########
@@ -0,0 +1,35 @@
+// 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.
+
+/// \file arrow-adbc/driver/bigquery.h ADBC BigQuery Driver
+///
+/// A driver for BigQuery.
+
+#pragma once
+
+#include <arrow-adbc/adbc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ADBC_EXPORT
+AdbcStatusCode BigQueryDriverInit(int version, void* raw_driver, struct AdbcError* error);

Review Comment:
   From `adbc.h` it seems this should be `AdbcDriverBigqueryInit`. I'll make sure these are consistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(c): enable linking to static builds [arrow-adbc]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #2738:
URL: https://github.com/apache/arrow-adbc/pull/2738#issuecomment-2866264509

   Any more comments here?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org