Building FoundationDB C API static Library for Rust Programing language

Hi everyone,
I’m using FDB with Rust for my application. I have a problem with build Rust Binary file with FDB C API that i want to build Rust application Binary as static libarary but FDB is a dynamic(sharing Libary), so that the build error.
Anyone have experience with Rust + FoundationDB? Or can i build the FDB C API as static library instead of

Thanks for reading!

Technically you could, but linking libfdb_c as a static library would be strongly discouraged. Each libfdb_c is tied to a specific version of FDB, and statically linking to it would tie your application to one specific version of FDB. This would mean that there would be no way to upgrade your FDB cluster without having application downtime.

There is a project on the roadmap to introduce a stable wire protocol, which would allow a client to be written that would be free of libfdb_c, and thus safe to fully statically link.

Thanks for your reply, i know the problem you said. But now, is there any solution for my problem? is there any solution to get libfdb_c static?

I don’t think there’s an officially supported way to get a static library (for the reasons Alex mentioned above).

It probably is possible to build one yourself. You could change SHARED to STATIC in this line and it probably will work (I didn’t test this though):

Be aware that even if you do this, your application will still link at least against glibc. So you won’t get a completely static executable.

Why do you want a static binary? Rust can link to dynamic library files, and the rust foundationdb bindings I’ve seen out there do just that.

Hi josephg,
I want to build my Rust Application to binary using musl libc to optimize my CI/CD pipeline for Rust Application. I have used Rust FoundationDB dynamic ok, but when using like that, it take a long time to build Docker Image because of recompile the denpendent everytime.

I expect to build the Docker image with Dockerfile like that:

FROM rust:latest AS builder
RUN apt-get update && apt-get install musl-tools llvm clang -y
RUN wget && dpkg -i foundationdb-clients_6.2.15-1_amd64.deb
RUN rustup target add x86_64-unknown-linux-musl
RUN USER=root cargo new app
COPY Cargo.toml Cargo.lock ./
RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
RUN rm -f target/x86_64-unknown-linux-musl/release/deps/ranker*
RUN rm src/*.rs
COPY src ./src
RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl

But it failed because of FDB is a share library.

Have you had some experience with Rust and FoundationDB and have any solution for my problem?


I would also recommend against building with musl in this fashion. libfdb_c uses dlopen() to load other versions of libfdb_c for upgrade support, and a statically linked executable and dlopen() isn’t supported in musl: Even if it does work, in the best case, you’ll be the first person running FDB on musl, and all stability bets are off. In the worst case, the dlopen ends up bringing in the base system’s glibc, and then you have two libc’s both trying to manipulate the program.

Thanks so much for all your supports!