This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new c84cc91f2 fix(go/adbc/driver): inject version to built Go drivers 
(#2916)
c84cc91f2 is described below

commit c84cc91f28b7681be8284b1f64c8acf2c6f25889
Author: Matt Topol <[email protected]>
AuthorDate: Thu Jun 19 01:41:34 2025 -0400

    fix(go/adbc/driver): inject version to built Go drivers (#2916)
    
    expanding the solution from #2889 We can make sure that we inject the
    proper version string into the internal/driverbase handling. This should
    populate the GetInfo correctly with the driver version via vcs
    information.
    
    ---------
    
    Co-authored-by: David Li <[email protected]>
---
 c/cmake_modules/GoUtils.cmake                | 10 +++++++---
 c/driver/flightsql/sqlite_flightsql_test.cc  |  3 +--
 go/adbc/driver/internal/driverbase/driver.go | 13 ++++++++++---
 go/adbc/pkg/Makefile                         |  5 ++++-
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/c/cmake_modules/GoUtils.cmake b/c/cmake_modules/GoUtils.cmake
index 20ce95e8e..a0e2ccef7 100644
--- a/c/cmake_modules/GoUtils.cmake
+++ b/c/cmake_modules/GoUtils.cmake
@@ -131,8 +131,10 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
   endif()
 
   # Go gcflags for disabling optimizations and inlining if debug
-  separate_arguments(GO_BUILD_FLAGS NATIVE_COMMAND
-                     "${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
+  separate_arguments(GO_BUILD_FLAGS
+                     NATIVE_COMMAND
+                     "${GO_BUILD_FLAGS} -buildvcs=true 
$<$<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_FLAGS "$<$<CONFIG:Debug>:-g3>")
@@ -170,7 +172,9 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
       separate_arguments(ARG_SHARED_LINK_FLAGS NATIVE_COMMAND 
"${ARG_SHARED_LINK_FLAGS}")
     endif()
 
-    set(GO_LDFLAGS "-ldflags;\"${ARG_SHARED_LINK_FLAGS};-a;${EXTLDFLAGS}\"")
+    set(GO_LDFLAGS
+        
"-ldflags;\"${ARG_SHARED_LINK_FLAGS};-X;github.com/apache/arrow-adbc/go/adbc/driver/internal/driverbase.infoDriverVersion=v${ADBC_VERSION};-a;${EXTLDFLAGS}\""
+    )
 
     set(LIBOUT_SHARED "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME_SHARED}")
 
diff --git a/c/driver/flightsql/sqlite_flightsql_test.cc 
b/c/driver/flightsql/sqlite_flightsql_test.cc
index dfe9776bd..02c41f9bc 100644
--- a/c/driver/flightsql/sqlite_flightsql_test.cc
+++ b/c/driver/flightsql/sqlite_flightsql_test.cc
@@ -103,8 +103,7 @@ class SqliteFlightSqlQuirks : public 
adbc_validation::DriverQuirks {
     switch (info_code) {
       case ADBC_INFO_DRIVER_NAME:
         return "ADBC Flight SQL Driver - Go";
-      case ADBC_INFO_DRIVER_VERSION:
-        return "(unknown or development build)";
+      // Do not test ADBC_INFO_DRIVER_VERSION; it differs in different parts 
of CI
       case ADBC_INFO_DRIVER_ADBC_VERSION:
         return ADBC_VERSION_1_1_0;
       case ADBC_INFO_VENDOR_NAME:
diff --git a/go/adbc/driver/internal/driverbase/driver.go 
b/go/adbc/driver/internal/driverbase/driver.go
index 6809facbf..019bcbc6f 100644
--- a/go/adbc/driver/internal/driverbase/driver.go
+++ b/go/adbc/driver/internal/driverbase/driver.go
@@ -36,12 +36,19 @@ var (
 
 func init() {
        if info, ok := debug.ReadBuildInfo(); ok {
+               for _, s := range info.Settings {
+                       switch s.Key {
+                       case "vcs.modified":
+                               if s.Value == "true" {
+                                       infoDriverVersion += "-dev"
+                               }
+                       }
+               }
                for _, dep := range info.Deps {
                        switch {
-                       case dep.Path == "github.com/apache/arrow-adbc/go/adbc":
-                               infoDriverVersion = dep.Version
-                       case strings.HasPrefix(dep.Path, 
"github.com/apache/arrow/go/"):
+                       case strings.HasPrefix(dep.Path, 
"github.com/apache/arrow-go/"):
                                infoDriverArrowVersion = dep.Version
+                               return
                        }
                }
        }
diff --git a/go/adbc/pkg/Makefile b/go/adbc/pkg/Makefile
index 0b09721ad..c5490d5b8 100644
--- a/go/adbc/pkg/Makefile
+++ b/go/adbc/pkg/Makefile
@@ -25,6 +25,9 @@ else
        SUFFIX=dylib
 endif
 
+GIT_VERSION=$(shell git tag -l --points-at $(shell git rev-list --tags 
--max-count=1) --sort=-v:refname | head -n 1)
+VERSION=$(subst go/adbc/,,$(GIT_VERSION))
+
 DRIVERS := \
        libadbc_driver_bigquery.$(SUFFIX) \
        libadbc_driver_flightsql.$(SUFFIX) \
@@ -35,7 +38,7 @@ DRIVERS := \
 all: $(DRIVERS)
 
 libadbc_driver_%.$(SUFFIX): %
-       $(GO_BUILD) -tags driverlib -o $@ -buildmode=c-shared -ldflags "-s -w" 
./$<
+       $(GO_BUILD) -buildvcs=true -tags driverlib -o $@ -buildmode=c-shared 
-ldflags "-s -w -X 
github.com/apache/arrow-adbc/go/adbc/driver/internal/driverbase.infoDriverVersion=$(VERSION)"
 ./$<
        $(RM) $(basename $@).h
 
 regenerate:

Reply via email to