Skip to content

Commit 025bb90

Browse files
authored
Fix debian docker building (#5752)
In previous attempts to get mysqlclient-sys to build and work I added some extra build variables. These are not needed if you configure pkg-config correctly. The same goes for OpenSSL btw. This PR configures the pkg-config in the right way and allows the crates to build using the right lib paths automatically. Because of this change also the lib/include paths were not needed anymore for some architectures, except for i386. Also updated crates again. Signed-off-by: BlackDex <[email protected]>
1 parent d5039d9 commit 025bb90

File tree

5 files changed

+30
-132
lines changed

5 files changed

+30
-132
lines changed

Cargo.lock

+8-85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build = "build.rs"
1818
# default = ["sqlite"]
1919
# Empty to keep compatibility, prefer to set USE_SYSLOG=true
2020
enable_syslog = []
21-
mysql = ["diesel/mysql", "diesel_migrations/mysql", "dep:mysqlclient-sys"]
21+
mysql = ["diesel/mysql", "diesel_migrations/mysql"]
2222
postgresql = ["diesel/postgres", "diesel_migrations/postgres"]
2323
sqlite = ["diesel/sqlite", "diesel_migrations/sqlite", "dep:libsqlite3-sys"]
2424
# Enable to use a vendored and statically linked openssl
@@ -87,8 +87,6 @@ diesel-derive-newtype = "2.1.2"
8787

8888
# Bundled/Static SQLite
8989
libsqlite3-sys = { version = "0.32.0", features = ["bundled"], optional = true }
90-
# Always enable buildtime bindgen for mysql/mariadb libraries
91-
mysqlclient-sys = { version = "0.4.4", features = ["buildtime_bindgen"], optional = true }
9290

9391
# Crypto-related libraries
9492
rand = "0.9.0"

docker/Dockerfile.debian

+10-17
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,24 @@ RUN USER=root cargo new --bin /app
8989
WORKDIR /app
9090

9191
# Environment variables for Cargo on Debian based builds
92-
ARG ARCH_OPENSSL_LIB_DIR \
93-
ARCH_OPENSSL_INCLUDE_DIR
92+
ARG TARGET_PKG_CONFIG_PATH
9493

9594
RUN source /env-cargo && \
9695
if xx-info is-cross ; then \
97-
# Some special variables if needed to override some build paths
98-
if [[ -n "${ARCH_OPENSSL_LIB_DIR}" && -n "${ARCH_OPENSSL_INCLUDE_DIR}" ]]; then \
99-
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_LIB_DIR=${ARCH_OPENSSL_LIB_DIR}" >> /env-cargo && \
100-
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_INCLUDE_DIR=${ARCH_OPENSSL_INCLUDE_DIR}" >> /env-cargo ; \
101-
fi && \
10296
# We can't use xx-cargo since that uses clang, which doesn't work for our libraries.
10397
# Because of this we generate the needed environment variables here which we can load in the needed steps.
10498
echo "export CC_$(echo "${CARGO_TARGET}" | tr '[:upper:]' '[:lower:]' | tr - _)=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
10599
echo "export CARGO_TARGET_$(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
106-
echo "export PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /env-cargo && \
107100
echo "export CROSS_COMPILE=1" >> /env-cargo && \
108-
# Export build env's for OpenSSL
109-
echo "export OPENSSL_INCLUDE_DIR=/usr/include/$(xx-info)" >> /env-cargo && \
110-
echo "export OPENSSL_LIB_DIR=/usr/lib/$(xx-info)" >> /env-cargo ; \
111-
# Export build env's for mysqlclient-sys (mariadb)
112-
# The version is linked to the mariadb-connector-c a.k.a libmariadb-dev version
113-
# See: https://mariadb.com/kb/en/about-mariadb-connector-c/
114-
echo "export MYSQLCLIENT_VERSION=3.3.14" >> /env-cargo ; \
115-
echo "export MYSQLCLIENT_INCLUDE_DIR=/usr/include/mariadb" >> /env-cargo && \
116-
echo "export MYSQLCLIENT_LIB_DIR=/usr/lib/$(xx-info)" >> /env-cargo ; \
101+
echo "export PKG_CONFIG_ALLOW_CROSS=1" >> /env-cargo && \
102+
# For some architectures `xx-info` returns a triple which doesn't matches the path on disk
103+
# In those cases you can override this by setting the `TARGET_PKG_CONFIG_PATH` build-arg
104+
if [[ -n "${TARGET_PKG_CONFIG_PATH}" ]]; then \
105+
echo "export TARGET_PKG_CONFIG_PATH=${TARGET_PKG_CONFIG_PATH}" >> /env-cargo ; \
106+
else \
107+
echo "export PKG_CONFIG_PATH=/usr/lib/$(xx-info)/pkgconfig" >> /env-cargo ; \
108+
fi && \
109+
echo "# End of env-cargo" >> /env-cargo ; \
117110
fi && \
118111
# Output the current contents of the file
119112
cat /env-cargo

docker/Dockerfile.j2

+10-17
Original file line numberDiff line numberDiff line change
@@ -109,31 +109,24 @@ WORKDIR /app
109109

110110
{% if base == "debian" %}
111111
# Environment variables for Cargo on Debian based builds
112-
ARG ARCH_OPENSSL_LIB_DIR \
113-
ARCH_OPENSSL_INCLUDE_DIR
112+
ARG TARGET_PKG_CONFIG_PATH
114113

115114
RUN source /env-cargo && \
116115
if xx-info is-cross ; then \
117-
# Some special variables if needed to override some build paths
118-
if [[ -n "${ARCH_OPENSSL_LIB_DIR}" && -n "${ARCH_OPENSSL_INCLUDE_DIR}" ]]; then \
119-
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_LIB_DIR=${ARCH_OPENSSL_LIB_DIR}" >> /env-cargo && \
120-
echo "export $(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_OPENSSL_INCLUDE_DIR=${ARCH_OPENSSL_INCLUDE_DIR}" >> /env-cargo ; \
121-
fi && \
122116
# We can't use xx-cargo since that uses clang, which doesn't work for our libraries.
123117
# Because of this we generate the needed environment variables here which we can load in the needed steps.
124118
echo "export CC_$(echo "${CARGO_TARGET}" | tr '[:upper:]' '[:lower:]' | tr - _)=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
125119
echo "export CARGO_TARGET_$(echo "${CARGO_TARGET}" | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER=/usr/bin/$(xx-info)-gcc" >> /env-cargo && \
126-
echo "export PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /env-cargo && \
127120
echo "export CROSS_COMPILE=1" >> /env-cargo && \
128-
# Export build env's for OpenSSL
129-
echo "export OPENSSL_INCLUDE_DIR=/usr/include/$(xx-info)" >> /env-cargo && \
130-
echo "export OPENSSL_LIB_DIR=/usr/lib/$(xx-info)" >> /env-cargo ; \
131-
# Export build env's for mysqlclient-sys (mariadb)
132-
# The version is linked to the mariadb-connector-c a.k.a libmariadb-dev version
133-
# See: https://mariadb.com/kb/en/about-mariadb-connector-c/
134-
echo "export MYSQLCLIENT_VERSION=3.3.14" >> /env-cargo ; \
135-
echo "export MYSQLCLIENT_INCLUDE_DIR=/usr/include/mariadb" >> /env-cargo && \
136-
echo "export MYSQLCLIENT_LIB_DIR=/usr/lib/$(xx-info)" >> /env-cargo ; \
121+
echo "export PKG_CONFIG_ALLOW_CROSS=1" >> /env-cargo && \
122+
# For some architectures `xx-info` returns a triple which doesn't matches the path on disk
123+
# In those cases you can override this by setting the `TARGET_PKG_CONFIG_PATH` build-arg
124+
if [[ -n "${TARGET_PKG_CONFIG_PATH}" ]]; then \
125+
echo "export TARGET_PKG_CONFIG_PATH=${TARGET_PKG_CONFIG_PATH}" >> /env-cargo ; \
126+
else \
127+
echo "export PKG_CONFIG_PATH=/usr/lib/$(xx-info)/pkgconfig" >> /env-cargo ; \
128+
fi && \
129+
echo "# End of env-cargo" >> /env-cargo ; \
137130
fi && \
138131
# Output the current contents of the file
139132
cat /env-cargo

docker/docker-bake.hcl

+1-10
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,20 @@ target "debian-386" {
133133
platforms = ["linux/386"]
134134
tags = generate_tags("", "-386")
135135
args = {
136-
ARCH_OPENSSL_LIB_DIR = "/usr/lib/i386-linux-gnu"
137-
ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/i386-linux-gnu"
136+
TARGET_PKG_CONFIG_PATH = "/usr/lib/i386-linux-gnu/pkgconfig"
138137
}
139138
}
140139

141140
target "debian-ppc64le" {
142141
inherits = ["debian"]
143142
platforms = ["linux/ppc64le"]
144143
tags = generate_tags("", "-ppc64le")
145-
args = {
146-
ARCH_OPENSSL_LIB_DIR = "/usr/lib/powerpc64le-linux-gnu"
147-
ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/powerpc64le-linux-gnu"
148-
}
149144
}
150145

151146
target "debian-s390x" {
152147
inherits = ["debian"]
153148
platforms = ["linux/s390x"]
154149
tags = generate_tags("", "-s390x")
155-
args = {
156-
ARCH_OPENSSL_LIB_DIR = "/usr/lib/s390x-linux-gnu"
157-
ARCH_OPENSSL_INCLUDE_DIR = "/usr/include/s390x-linux-gnu"
158-
}
159150
}
160151
// ==== End of unsupported Debian architecture targets ===
161152

0 commit comments

Comments
 (0)