Replies: 18 comments
-
Hi Tom, thanks for the report. Could you please provide a sample repo to reproduce the problem. And could you please provide additional information about your build system/architecture that you are using. Thanks |
Beta Was this translation helpful? Give feedback.
-
I'm seeing the following build errors when trying to use this library:
These errors go away when I:
I'm not sure if it's due to the way these builds are being built. |
Beta Was this translation helpful? Give feedback.
-
We've seen this problem when switching the underlying build OS from Ubuntu 20.04 to 22.04. It seems, that 22.04 ships with a different std library. What happens if you take the libduckdb.a from the master branch? Does this work? |
Beta Was this translation helpful? Give feedback.
-
I'm on |
Beta Was this translation helpful? Give feedback.
-
I'm wondering if these compile issues on linux_amd64 are due to the current build not being hermetic. I'm not an expert of c++ toolchains, but this article mentions some properties of hermetric toolchains which lead me to believe that the issues I'm (we're) seeing (#58, ba7f5a8) might be due to relying on the C++ toolchain of the host running the GitHub action. One suggestion I have is to consider using zig c++ to cross-compile for all targets. This also allows you to run all the build actions on one machine and simplify your Github action. See envoyproxy/envoy#19535 (comment) for zig's use on envoyproxy. Let me know your thoughts. The change seems simple, and likely would have strong benefits in making the behavior more consistent across linux flavors. Change would look like:
More info about zig: https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html |
Beta Was this translation helpful? Give feedback.
-
The problem here is that C++ does not have a stable ABI. Therefore, we cannot compile our application with clang (i.e. Most Linux systems use GCC, therefore most developers ship gcc pre-compiled binaries. This is, unfortunately, quite prominent in Go ecosystem. I've seen this done with zstd, v8, now with libduckdb. Not only we lose ability to use a different compiler by bundling static libraries, we lose flexibility:
We should work on making compilations faster instead, not avoiding them altogether. |
Beta Was this translation helpful? Give feedback.
-
@chrisirhc Does it also compile if you're using @motiejus Do you have an idea on how to make compilation faster? |
Beta Was this translation helpful? Give feedback.
-
There are a few ways to go about it:
The fastest and slowest optimization modes ( Go does not support explicit "build modes" (e.g.
Most library users do not set Therefore, I don't have a good answer here besides "use a build system that supports compilation modes". But I acknowledge it's not for everyone. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the benchmark. I've create a branch to play around with different compilers and versions to see what works the best. You can find the latest version here https://github.com/marcboeker/go-duckdb/tree/switch-compiler |
Beta Was this translation helpful? Give feedback.
-
@TN1ck @chrisirhc I've switched from g++ to clang++. Could you please check, if the precompiled libs in the https://github.com/marcboeker/go-duckdb/tree/switch-compiler branch fix your problem? |
Beta Was this translation helpful? Give feedback.
-
Just saw this thread and wanted to share some notes from when I contributed the pre-built static builds:
# On Linux:
$ ldd duckdb
linux-vdso.so.1 (0x0000ffff91eec000)
libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff8fa60000)
libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff8fa40000)
libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff8f9a0000)
libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff8f7f0000)
/lib/ld-linux-aarch64.so.1 (0x0000ffff91eb3000)
# On macOS:
$ otool -L /opt/homebrew/bin/duckdb
/opt/homebrew/bin/duckdb:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.32.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0) Would love input from someone familiar with the trade-offs of fully static vs. not (as well as how to configure a fully static build).
|
Beta Was this translation helpful? Give feedback.
-
Wow, thanks for your thoughtful reply!
I wasn't aware of the Darwin issues for C++ code, thanks for pointing this out. Linux, though, is a different story -- as of a few weeks ago
Runnable executables are trivial, at least on Linux --
I don't think it's possible to create a fully static executable on MacOS (If I remember correctly what @kubkon told me). But also there is no point: MacOS is much more homogenous.
If we are talking about static binaries, there is one caveat: that kind-of implies using musl these days. However, musl's malloc implementation is quite different from glibc: it is much smaller and simpler, but may exhibit contention when many threads are allocating/freeing memory concurrently. This is not a problem in 99% of cases, but if someone were to make it official, they should benchmark it. I do not know, however, how much multi-threaded duckdb is.
I do not have an opinion here.
The problem here is that the pre-built libraries are incompatible between clang and gcc. Most of the cases Linux users use gcc, but some weird ones (like me) prefer clang, which results in a very strange linker erorr, or, even worse, runtime crash. I did not look into go-duckdb carefully though. If it can be made to use the C ABI only (i.e. only the functions that are behind |
Beta Was this translation helpful? Give feedback.
-
I just wanted to mention that the MachO linker in Zig handles C++ exceptions since about a week or so: ziglang/zig#14397 ;-) |
Beta Was this translation helpful? Give feedback.
-
Also, re static binaries on macOS, they are completely unsupported on Apple Silicon, however, still work on x86_64. Zig's MachO linker currently doesn't emitting a non-PIE binaries. |
Beta Was this translation helpful? Give feedback.
-
Hey, just wanted to come back to this to report back that due to the constraint mentioned before that I'm using this go-duckdb library in a monorepo that implements a hermetic c++ compiler (zig c++, in our scenario), I won't be able to test this branch (due to I also want to report back that I've successfully gotten everything to work via zig c++. I haven't seen the MacOS crash. Perhaps I haven't hit that code path... yet. |
Beta Was this translation helpful? Give feedback.
-
Still showcases the same problems for me, but this is actually not important or us, I simply used a Docker image with those shared libraries. I did create a test repo where the problem is showcased: https://github.com/TN1ck/go-duckdb-static-test |
Beta Was this translation helpful? Give feedback.
-
@chrisirhc Could you share your build setup? I've been having issues building for linux-x64 from a Mac M3. |
Beta Was this translation helpful? Give feedback.
-
In case it's useful for anyone reading this issue, this is how we're building / running with go-duckdb # docker build --platform=linux/amd64 -t my/repo .
FROM golang:1.22-bookworm AS build-stage
WORKDIR /app
# copy go mod and sum files to initialize dependencies first. This improves docker layer caching, so we don't have
# to download dependencies every time we change the source code.
COPY go.mod go.sum ./
RUN go mod download
# copy the rest of the source code
COPY . .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -C duckdb -o /main_linux64
# We use debian:bookworm-slim because it has the necessary dependencies for DuckDB. Even though go-duckdb statically
# links the DuckDB library, it still needs some dependencies to be present on the system. This is a known issue:
# https://github.com/marcboeker/go-duckdb/issues/54
FROM debian:bookworm-slim
COPY --from=build-stage /main_linux64 /main_linux64
CMD ["/main_linux64"] |
Beta Was this translation helpful? Give feedback.
-
First off, thanks so much for the project, it works very well already.
I encountered a problem with the provided duckdb binary (linux x64) referencing shared libraries and the binary crashing if those are not there.
I'm not too familiar with c++ build chains / how static libraries are supposed to behave, but right now, the duckdb binary requires certain shared libraries to be available like libstdc++.so.6, libm.so.6, libgcc_s.so.1, glibc etc. Is that expected behavior? I would have expected a static library to have no dependencies, else it should be written somewhere that the OS should have those. The problem was mostly encountered in our deployment image, as this is very minimal without any build chains etc and there it would complain about those missing libraries.
I can make an example repo with a Docker build that exhibits this behavior if needed.
Beta Was this translation helpful? Give feedback.
All reactions