Musl docker images #912

Open
opened 2025-07-25 22:15:57 +00:00 by Jade · 7 comments
Owner

So continuwuity historically provided static binaries built using Nix. Unfortunately due to changes in the build, that no longer works for cross compilation - and the team doesn't have the Nix knowledge to maintain it. Instead we want to build the binary using docker, building on our existing dynamic binary pipeline.

We want to build statically linked musl binaries. For that we need the static version of at least liburing built against musl, possibly some other stuff. Debian doesn't provide this. I've tried running a build process on alpine - unfortunately something in the build of our process needs to dynamically link stuff that doesn't work on alpine.

So what needs to happen is you need to update the main debian build image to switch between glibc and musl binaries - when building for glibc, do the process we already have in place. When building for musl, copy the libraries from an alpine container and configure package config to find the system dependencies there

See also:

#911
#740

So continuwuity historically provided static binaries built using Nix. Unfortunately due to changes in the build, that no longer works for cross compilation - and the team doesn't have the Nix knowledge to maintain it. Instead we want to build the binary using docker, building on our existing dynamic binary pipeline. We want to build statically linked musl binaries. For that we need the static version of at least liburing built against musl, possibly some other stuff. Debian doesn't provide this. I've tried running a build process on alpine - unfortunately something in the build of our process needs to dynamically link stuff that doesn't work on alpine. So what needs to happen is you need to update the main debian build image to switch between glibc and musl binaries - when building for glibc, do the process we already have in place. When building for musl, copy the libraries from an alpine container and configure package config to find the system dependencies there See also: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/911 https://forgejo.ellis.link/continuwuation/continuwuity/issues/740
Owner

@gan got static compiles working for ARM64 outside of docker: https://codeberg.org/skhron/continuwuity_compilation_lxc/src/branch/main/autostart.sh

@gan got static compiles working for ARM64 outside of docker: https://codeberg.org/skhron/continuwuity_compilation_lxc/src/branch/main/autostart.sh
Contributor

I just tried translating the work of @gan into Dockerfile instructions, and it worked!
I have though only tried to build for target aarch64-alpine-linux-musl, so please test it with other targets as well, those who have the platforms available:
https://forgejo.ellis.link/oddlid/continuwuity/src/branch/docker_musl_build/docker/Dockerfile

I just tried translating the work of @gan into Dockerfile instructions, and it worked! I have though only tried to build for target aarch64-alpine-linux-musl, so please test it with other targets as well, those who have the platforms available: https://forgejo.ellis.link/oddlid/continuwuity/src/branch/docker_musl_build/docker/Dockerfile
Author
Owner

Is that a cross-compile?

Is that a cross-compile?
Contributor

I haven’t tested if that works yet. I’ve only run it on my mac, where Docker is aarch64-linux.
This was more intended as a first step to get static compilation working at all, and then we can add more changes to get it working for cross-compilation, from/to any platform, if possible.

I haven’t tested if that works yet. I’ve only run it on my mac, where Docker is aarch64-linux. This was more intended as a first step to get static compilation working at all, and then we can add more changes to get it working for cross-compilation, from/to any platform, if possible.
Contributor

I did some quick tests now, and it does NOT work to cross-compile with the Dockerfile as is.
I tried some modifications to derive from rust:alpine instead of alpine:edge, since that image has rust installed via rustup, so that one can ”rustup target add”, but it seems we need gcc/g++ in cross-compile version as well, since it fails with ”unrecognized command-line option ’-m64’” during compilation.

Another thing I haven’t tried yet, is to run the build on another host platform and adjust ”—build-arg BUILD_TARGET=xxx” accordingly. I’ll report back after having tried that.

I did some quick tests now, and it does NOT work to cross-compile with the Dockerfile as is. I tried some modifications to derive from rust:alpine instead of alpine:edge, since that image has rust installed via rustup, so that one can ”rustup target add”, but it seems we need gcc/g++ in cross-compile version as well, since it fails with ”unrecognized command-line option ’-m64’” during compilation. Another thing I haven’t tried yet, is to run the build on another host platform and adjust ”—build-arg BUILD_TARGET=xxx” accordingly. I’ll report back after having tried that.
Author
Owner

The latter should work fine, but we don't have any arm runners. I'll have a look when I get an opportunity. Challenge is probably figuring out the thing that this is doing that the one in the repo is not.

The latter should work fine, but we don't have any arm runners. I'll have a look when I get an opportunity. Challenge is probably figuring out the thing that this is doing that the one in the repo is not.
Contributor

I’m sorry to report that running ”docker build —build-arg BUILD_TARGET=x84_64-alpine-linux-musl …” on an x86_64 linux host failed at the linking stage:

/usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object /usr/lib/liburing.so' /usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object /usr/lib/libstdc++.so'
/usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object `/usr/lib/libc.so'

Why the same worked on arm64 but not x86_64 is a mystery to me.
So, this might not be a feasible solution after all.

I’m sorry to report that running ”docker build —build-arg BUILD_TARGET=x84_64-alpine-linux-musl …” on an x86_64 linux host failed at the linking stage: /usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object `/usr/lib/liburing.so' /usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object `/usr/lib/libstdc++.so' /usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: attempted static link of dynamic object `/usr/lib/libc.so' Why the same worked on arm64 but not x86_64 is a mystery to me. So, this might not be a feasible solution after all.
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
continuwuation/continuwuity#912
No description provided.