This is a question for which I found the answer. I'm adding it to SO as it might be useful for others. If there is a better reply I'll be glad to accept it!
I'm building some Go services that need to talk to Oracle, using Bazel as the build system in conjunction with the official rules_go
. The best library for this seems to be godror, but when attempting to depend on it, the build fails with:
external/com_github_godror_godror/conn.go:10:10: fatal error: 'dpiImpl.h' file not found
#include "dpiImpl.h"
This seems to be due to the fact that gazelle
does not replicate all the magic/implicit things CGO does out of the box when invoked via go build
, and I'm left to wonder if/how there is a way to properly build that library with Bazel.
As there does not seem to be a proper standalone Go client for Oracle, the only way forward is to get this to work with CGO.
After a bit of playing around with the generated BUILD.bazel
file, I found a workaround that seems to be working at least superficially[1][2]. It involves adding C sources and headers from a subdirectory, as well as patching a C file.
See this gist for details.
Note that not patching the C file (and including the relevant dpi.c
file in the go_library
definition) will cause the build to fail with things along:
duplicate symbol '_dpiVar_getReturnedData' in:
/var/folders/8y/pztgykk94_q4j7fnmjhnbnw0001t4q/T/rules_go_work-940074786/_x3.o
/var/folders/8y/pztgykk94_q4j7fnmjhnbnw0001t4q/T/rules_go_work-940074786/_x43.o
ld: 1164 duplicate symbols for architecture x86_64
Here I guess some of the CGO magic that happens via go build
needs to be replaced by the proper flags, but at least things work with the substitution.
For the record, the exploration was mostly done on OS X while things were tested using binaries built on a Linux box.
For anyone interested in the godror specifics here is the relevant issue.
[1]: As in works for basic queries and not yet Tried out every functionality in a production setting, so YMMV.
[2]: Oddly enough, the workaround makes it impossible to go install
the sources. If a C/CGO expert has a clue I'd be curious to understand why – oh, by the way, I'm a total C/CGO newbie, so sorry if the problem is obvious.