Skip to content

Commit 80f4e22

Browse files
authored
Merge pull request #154 from clux/rm-openssl-pq
Remove `openssl` and `pq`
2 parents ca99f4c + c844e0f commit 80f4e22

File tree

20 files changed

+50
-306
lines changed

20 files changed

+50
-306
lines changed

Dockerfile.arm64

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ LABEL maintainer="Eirik Albrigtsen <sszynrae@gmail.com>"
55
# Required packages:
66
# - musl-dev, musl-tools - the musl toolchain
77
# - curl, g++, make, pkgconf, cmake - for fetching and building third party libs
8-
# - ca-certificates - openssl + curl + peer verification of downloads
9-
# - xutils-dev - for openssl makedepend
10-
# - libssl-dev and libpq-dev - for dynamic linking during diesel_codegen build process
8+
# - ca-certificates - peer verification of downloads
119
# - git - cargo builds in user projects
12-
# - linux-headers-amd64 - needed for building openssl 1.1 (stretch only)
1310
# - file - needed by rustup.sh install
1411
# - automake autoconf libtool - support crates building C deps as part cargo build
1512
# NB: does not include cmake atm
@@ -25,9 +22,6 @@ RUN apt-get update && apt-get install -y \
2522
curl \
2623
pkgconf \
2724
ca-certificates \
28-
xutils-dev \
29-
libssl-dev \
30-
libpq-dev \
3125
automake \
3226
autoconf \
3327
libtool \
@@ -53,9 +47,7 @@ RUN chmod a+X /root
5347

5448
# Convenience list of versions and variables for compilation later on
5549
# This helps continuing manually if anything breaks.
56-
ENV SSL_VER="1.1.1w" \
57-
ZLIB_VER="1.3.1" \
58-
PQ_VER="11.12" \
50+
ENV ZLIB_VER="1.3.1" \
5951
SQLITE_VER="3490100" \
6052
PROTOBUF_VER="29.2" \
6153
SCCACHE_VER="0.9.1" \
@@ -78,43 +70,13 @@ RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VE
7870
chmod +x /usr/local/bin/sccache && \
7971
rm -rf sccache-v${SCCACHE_VER}-*-unknown-linux-musl
8072

81-
# Set up a prefix for musl build libraries, make the linker's job of finding them easier
82-
# Primarily for the benefit of postgres.
83-
# Lastly, link some linux-headers for openssl 1.1 (not used herein)
84-
RUN mkdir $PREFIX && \
85-
echo "$PREFIX/lib" >> /etc/ld-musl-aarch64.path && \
86-
ln -s /usr/include/aarch64-linux-gnu/asm /usr/include/aarch64-linux-musl/asm && \
87-
ln -s /usr/include/asm-generic /usr/include/aarch64-linux-musl/asm-generic && \
88-
ln -s /usr/include/linux /usr/include/aarch64-linux-musl/linux
89-
90-
# Build zlib (used in openssl and pq)
73+
# Build zlib (used in pq)
9174
RUN curl -sSL https://zlib.net/zlib-$ZLIB_VER.tar.gz | tar xz && \
9275
cd zlib-$ZLIB_VER && \
9376
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure --static --prefix=$PREFIX && \
9477
make -j$(nproc) && make install && \
9578
cd .. && rm -rf zlib-$ZLIB_VER
9679

97-
# Build openssl (used in pq)
98-
# Would like to use zlib here, but can't seem to get it to work properly
99-
# TODO: fix so that it works
100-
RUN curl -sSL https://www.openssl.org/source/openssl-$SSL_VER.tar.gz | tar xz && \
101-
cd openssl-$SSL_VER && \
102-
CFLAGS="-mno-outline-atomics" ./Configure no-zlib no-shared -fPIC --prefix=$PREFIX --openssldir=$PREFIX/ssl linux-aarch64 && \
103-
env C_INCLUDE_PATH=$PREFIX/include make depend 2> /dev/null && \
104-
make -j$(nproc) && make all install_sw && \
105-
cd .. && rm -rf openssl-$SSL_VER
106-
107-
# Build libpq
108-
RUN curl -sSL https://ftp.postgresql.org/pub/source/v$PQ_VER/postgresql-$PQ_VER.tar.gz | tar xz && \
109-
cd postgresql-$PQ_VER && \
110-
CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \
111-
--without-readline \
112-
--with-openssl \
113-
--prefix=$PREFIX --host=x86_64-unknown-linux-musl && \
114-
cd src/interfaces/libpq make -s -j$(nproc) all-static-lib && make -s install install-lib-static && \
115-
cd ../../bin/pg_config && make -j $(nproc) && make install && \
116-
cd .. && rm -rf postgresql-$PQ_VER
117-
11880
# Build libsqlite3 using same configuration as the alpine linux main/sqlite package
11981
RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | tar xz && \
12082
cd sqlite-autoconf-$SQLITE_VER && \
@@ -124,27 +86,14 @@ RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | t
12486
make && make install && \
12587
cd .. && rm -rf sqlite-autoconf-$SQLITE_VER
12688

127-
# SSL cert directories get overridden by --prefix and --openssldir
128-
# and they do not match the typical host configurations.
129-
# The SSL_CERT_* vars fix this, but only when inside this container
130-
# musl-compiled binary must point SSL at the correct certs (muslrust/issues/5) elsewhere
131-
# Postgres bindings need vars so that diesel_codegen.so uses the GNU deps at build time
132-
# but finally links with the static libpq.a at the end.
133-
# It needs the non-musl pg_config to set this up with libpq-dev (depending on libssl-dev)
134-
# See https://github.com/sgrif/pq-sys/pull/18
13589
ENV PATH=/root/.cargo/bin:$PREFIX/bin:$PATH \
13690
RUSTUP_HOME=/root/.rustup \
13791
CARGO_BUILD_TARGET=aarch64-unknown-linux-musl \
13892
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld -Ctarget-feature=+crt-static" \
13993
PKG_CONFIG_ALLOW_CROSS=true \
14094
PKG_CONFIG_ALL_STATIC=true \
141-
PQ_LIB_STATIC_AARCH64_UNKNOWN_LINUX_MUSL=true \
14295
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
14396
PG_CONFIG_AARCH64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
144-
OPENSSL_STATIC=true \
145-
OPENSSL_DIR=$PREFIX \
146-
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
147-
SSL_CERT_DIR=/etc/ssl/certs \
14897
LIBZ_SYS_STATIC=1 \
14998
DEBIAN_FRONTEND=noninteractive \
15099
TZ=Etc/UTC

Dockerfile.x86_64

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
# syntax=docker/dockerfile:1
12
FROM ubuntu:noble
23
LABEL maintainer="Eirik Albrigtsen <sszynrae@gmail.com>"
34

45
# Required packages:
56
# - musl-dev, musl-tools - the musl toolchain
67
# - curl, g++, make, pkgconf, cmake - for fetching and building third party libs
78
# - ca-certificates - openssl + curl + peer verification of downloads
8-
# - xutils-dev - for openssl makedepend
9-
# - libssl-dev and libpq-dev - for dynamic linking during diesel_codegen build process
109
# - git - cargo builds in user projects
11-
# - linux-headers-amd64 - needed for building openssl 1.1 (stretch only)
1210
# - file - needed by rustup.sh install
1311
# - automake autoconf libtool - support crates building C deps as part cargo build
1412
# NB: does not include cmake atm
@@ -24,9 +22,6 @@ RUN apt-get update && apt-get install -y \
2422
curl \
2523
pkgconf \
2624
ca-certificates \
27-
xutils-dev \
28-
libssl-dev \
29-
libpq-dev \
3025
automake \
3126
autoconf \
3227
libtool \
@@ -52,9 +47,7 @@ RUN chmod a+X /root
5247

5348
# Convenience list of versions and variables for compilation later on
5449
# This helps continuing manually if anything breaks.
55-
ENV SSL_VER="1.1.1w" \
56-
ZLIB_VER="1.3.1" \
57-
PQ_VER="11.12" \
50+
ENV ZLIB_VER="1.3.1" \
5851
SQLITE_VER="3490100" \
5952
PROTOBUF_VER="29.2" \
6053
SCCACHE_VER="0.9.1" \
@@ -77,43 +70,13 @@ RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VE
7770
chmod +x /usr/local/bin/sccache && \
7871
rm -rf sccache-v${SCCACHE_VER}-*-unknown-linux-musl
7972

80-
# Set up a prefix for musl build libraries, make the linker's job of finding them easier
81-
# Primarily for the benefit of postgres.
82-
# Lastly, link some linux-headers for openssl 1.1 (not used herein)
83-
RUN mkdir $PREFIX && \
84-
echo "$PREFIX/lib" >> /etc/ld-musl-x86_64.path && \
85-
ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/x86_64-linux-musl/asm && \
86-
ln -s /usr/include/asm-generic /usr/include/x86_64-linux-musl/asm-generic && \
87-
ln -s /usr/include/linux /usr/include/x86_64-linux-musl/linux
88-
89-
# Build zlib (used in openssl and pq)
73+
# Build zlib (used in pq)
9074
RUN curl -sSL https://zlib.net/zlib-$ZLIB_VER.tar.gz | tar xz && \
9175
cd zlib-$ZLIB_VER && \
9276
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure --static --prefix=$PREFIX && \
9377
make -j$(nproc) && make install && \
9478
cd .. && rm -rf zlib-$ZLIB_VER
9579

96-
# Build openssl (used in pq)
97-
# Would like to use zlib here, but can't seem to get it to work properly
98-
# TODO: fix so that it works
99-
RUN curl -sSL https://www.openssl.org/source/openssl-$SSL_VER.tar.gz | tar xz && \
100-
cd openssl-$SSL_VER && \
101-
./Configure no-zlib no-shared -fPIC --prefix=$PREFIX --openssldir=$PREFIX/ssl linux-x86_64 && \
102-
env C_INCLUDE_PATH=$PREFIX/include make depend 2> /dev/null && \
103-
make -j$(nproc) && make all install_sw && \
104-
cd .. && rm -rf openssl-$SSL_VER
105-
106-
# Build libpq
107-
RUN curl -sSL https://ftp.postgresql.org/pub/source/v$PQ_VER/postgresql-$PQ_VER.tar.gz | tar xz && \
108-
cd postgresql-$PQ_VER && \
109-
CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \
110-
--without-readline \
111-
--with-openssl \
112-
--prefix=$PREFIX --host=x86_64-unknown-linux-musl && \
113-
cd src/interfaces/libpq make -s -j$(nproc) all-static-lib && make -s install install-lib-static && \
114-
cd ../../bin/pg_config && make -j $(nproc) && make install && \
115-
cd .. && rm -rf postgresql-$PQ_VER
116-
11780
# Build libsqlite3 using same configuration as the alpine linux main/sqlite package
11881
RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | tar xz && \
11982
cd sqlite-autoconf-$SQLITE_VER && \
@@ -123,26 +86,13 @@ RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | t
12386
make && make install && \
12487
cd .. && rm -rf sqlite-autoconf-$SQLITE_VER
12588

126-
# SSL cert directories get overridden by --prefix and --openssldir
127-
# and they do not match the typical host configurations.
128-
# The SSL_CERT_* vars fix this, but only when inside this container
129-
# musl-compiled binary must point SSL at the correct certs (muslrust/issues/5) elsewhere
130-
# Postgres bindings need vars so that diesel_codegen.so uses the GNU deps at build time
131-
# but finally links with the static libpq.a at the end.
132-
# It needs the non-musl pg_config to set this up with libpq-dev (depending on libssl-dev)
133-
# See https://github.com/sgrif/pq-sys/pull/18
13489
ENV PATH=/root/.cargo/bin:$PREFIX/bin:$PATH \
13590
RUSTUP_HOME=/root/.rustup \
13691
CARGO_BUILD_TARGET=x86_64-unknown-linux-musl \
13792
PKG_CONFIG_ALLOW_CROSS=true \
13893
PKG_CONFIG_ALL_STATIC=true \
139-
PQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=true \
14094
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
14195
PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
142-
OPENSSL_STATIC=true \
143-
OPENSSL_DIR=$PREFIX \
144-
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
145-
SSL_CERT_DIR=/etc/ssl/certs \
14696
LIBZ_SYS_STATIC=1 \
14797
DEBIAN_FRONTEND=noninteractive \
14898
TZ=Etc/UTC

README.md

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
[![stable](https://github.com/clux/muslrust/actions/workflows/stable.yml/badge.svg)](https://github.com/clux/muslrust/actions/workflows/stable.yml)
55
[![docker pulls](https://img.shields.io/docker/pulls/clux/muslrust.svg)](https://hub.docker.com/r/clux/muslrust/tags)
66

7-
A docker environment for building **static** rust binaries for `x86_64` and `arm64` **linux** environments using **[musl](https://musl.libc.org/)**. Built daily via [github actions](https://github.com/clux/muslrust/actions).
7+
A docker environment for building **static** rust binaries for `x86_64` and `arm64` environments using **[musl](https://musl.libc.org/)**. Built daily via [github actions](https://github.com/clux/muslrust/actions).
88

9-
Binaries compiled with `muslrust` are **light-weight**, call straight into the kernel without other dynamic system library dependencies, can be shipped to most linux distributions without compatibility issues, and can be inserted as-is into lightweight docker images such as [static distroless](https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md), [scratch](https://hub.docker.com/_/scratch), or [alpine](https://hub.docker.com/_/alpine).
9+
Binaries compiled with `muslrust` are **light-weight**, call straight into the kernel without other dynamic system library dependencies, can be shipped to most distributions without compatibility issues, and can be inserted as-is into lightweight docker images such as [static distroless](https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md), [scratch](https://hub.docker.com/_/scratch), or [alpine](https://hub.docker.com/_/alpine).
1010

1111
The goal is to **simplify** the creation of small and **efficient cloud containers**, or **stand-alone linux binary releases**.
1212

13-
This image includes popular [C libraries](#c-libraries) compiled with `musl-gcc`, enabling static builds even when these libraries are used.
13+
This image includes some hard-to-avoid [C libraries](#c-libraries) compiled with `musl-gcc`, enabling static builds even when these libraries are used.
1414

1515
## Usage
1616

@@ -50,14 +50,20 @@ For pinned, or historical builds, see the [available tags on dockerhub](https://
5050

5151
The following system libraries are compiled against `musl-gcc`:
5252

53-
- [x] openssl ([openssl crate](https://github.com/sfackler/rust-openssl))
54-
- [x] pq ([pq-sys crate](https://github.com/sgrif/pq-sys) used by [diesel](https://github.com/diesel-rs/diesel))
55-
- [x] sqlite3 ([libsqlite3-sys crate](https://github.com/jgallagher/rusqlite/tree/master/libsqlite3-sys) used by [diesel](https://github.com/diesel-rs/diesel))
56-
- [x] zlib (used by pq and openssl)
53+
- sqlite3 ([libsqlite3-sys crate](https://github.com/jgallagher/rusqlite/tree/master/libsqlite3-sys) used by [diesel](https://github.com/diesel-rs/diesel))
54+
- zlib
5755

58-
We **[try](https://github.com/clux/muslrust/blob/main/update_libs.py)** to keep these up to date.
56+
Note that these libraries **may be removed** if sensible and popular Rust crates can replace them in the future.
5957

60-
NB: C library for `curl` has been removed in newer tags from 2025. See [#96](https://github.com/clux/muslrust/issues/96).
58+
In the mean time, we **[try](https://github.com/clux/muslrust/blob/main/update_libs.py)** to keep these up to date.
59+
60+
Removed Libraries;
61+
62+
- `openssl` has been removed in 2025. See [#153](https://github.com/clux/muslrust/issues/153).
63+
- `curl` has been removed in 2025. See [#96](https://github.com/clux/muslrust/issues/96).
64+
- `pq` has been removed in 2025. See [#81](https://github.com/clux/muslrust/issues/81)
65+
66+
Consider [blackdex/rust-musl](https://github.com/BlackDex/rust-musl) for `openssl`, `curl` and `pq`.
6167

6268
## Developing
6369

@@ -74,10 +80,9 @@ just test
7480
Before we push a new version of muslrust we [test](https://github.com/clux/muslrust/blob/main/test.sh#L4-L17) to ensure that we can use and statically link:
7581

7682
- [x] [serde](https://crates.io/crates/serde)
77-
- [x] [diesel](https://crates.io/crates/diesel)
78-
- [x] [hyper](https://crates.io/crates/hyper)
83+
- [x] [diesel](https://crates.io/crates/diesel) (using sqlite)
7984
- [x] [rustls](https://crates.io/crates/rustls)
80-
- [x] [openssl](https://crates.io/crates/openssl)
85+
- [x] [hyper](https://crates.io/crates/hyper) (using hyper-rustls and rustls's default crypto backend)
8186
- [x] [flate2](https://crates.io/crates/flate2)
8287
- [x] [rand](https://crates.io/crates/rand)
8388

@@ -139,32 +144,6 @@ static GLOBAL: Jemalloc = Jemalloc;
139144

140145
## Troubleshooting
141146

142-
### SSL Verification
143-
144-
You might need to point `openssl` at the location of your certificates **explicitly** to avoid certificate errors on https requests.
145-
146-
```sh
147-
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
148-
export SSL_CERT_DIR=/etc/ssl/certs
149-
```
150-
151-
These can be [hardcoded in your Dockerfile](https://docs.docker.com/engine/reference/builder/#env), or you can rely on the [openssl-probe crate](https://crates.io/crates/openssl-probe) to detect the cert location. You should not have to do this if you are using the static variants of `distroless` or `chainguard`.
152-
153-
### Diesel and PQ builds
154-
155-
Works with the older version of libpq we bundle (see [#81](https://github.com/clux/muslrust/issues/81)). See the [test/dieselpgcrate](./test/dieselpgcrate) for specifics.
156-
157-
For stuff like `infer_schema!` to work you need to explicitly pass on `-e DATABASE_URL=$DATABASE_URL` to the `docker run`. It's probably easier to just make `diesel print-schema > src/schema.rs` part of your migration setup though.
158-
159-
Note that diesel compiles with `openssl` statically since `1.34.0`, so you need to include the `openssl` crate **before** `diesel` due to [pq-sys#25](https://github.com/sgrif/pq-sys/issues/25):
160-
161-
```rs
162-
extern crate openssl;
163-
#[macro_use] extern crate diesel;
164-
```
165-
166-
This is true even if you connect without `sslmode=require`.
167-
168147
### Filesystem permissions on local builds
169148

170149
When building locally, the permissions of the musl parts of the `./target` artifacts dir will be owned by `root` and requires `sudo rm -rf target/` to clear. This is an [intended](https://github.com/clux/muslrust/issues/65) complexity tradeoff with user builds.

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ _ti crate:
3232
just _t_{{ os() }}_{{ arch() }} {{crate}}
3333

3434
# when running locally we can use one of these instead of _t
35-
_t_linux_amd64 crate:
35+
_t_linux_x86_64 crate:
3636
#!/bin/bash
3737
export PLATFORM="linux/amd64"
3838
export TARGET_DIR="x86_64-unknown-linux-musl"
@@ -46,9 +46,9 @@ _t_macos_aarch64 crate:
4646
./test.sh {{crate}}
4747

4848
# Test all crates against built container locally
49-
test: (_ti "plain") (_ti "ssl") (_ti "rustls") (_ti "pq") (_ti "serde") (_ti "zlib") (_ti "hyper") (_ti "dieselpg") (_ti "dieselsqlite")
49+
test: (_ti "plain") (_ti "serde") (_ti "zlib") (_ti "hypertls") (_ti "dieselsqlite")
5050
# Test all crates against built container in ci (inheriting set PLATFORM/TARGET_DIR/AR vars)
51-
test-ci: (_t "plain") (_t "ssl") (_t "rustls") (_t "pq") (_t "serde") (_t "zlib") (_t "hyper") (_t "dieselpg") (_t "dieselsqlite")
51+
test-ci: (_t "plain") (_t "serde") (_t "zlib") (_t "hypertls") (_t "dieselsqlite")
5252

5353
# Cleanup everything
5454
clean: clean-docker clean-tests

test/dieselpgcrate/Cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/dieselpgcrate/src/main.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

test/dieselsqlitecrate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ name = "dieselsqlitecrate"
44
version = "0.1.0"
55

66
[dependencies]
7-
diesel = { version = "2.1.*", features = ["sqlite"] }
7+
diesel = { version = "2.2.*", features = ["sqlite"] }

0 commit comments

Comments
 (0)