Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[---] Build docker executable with musl libc. #751

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

looked-at-me
Copy link
Contributor

The issue with gist not working seems to be related to a bug in glibc when it is used as a static library in a static executable. Possibly something related to the shared binaries not being able to access TLS of the executable. Found a few issues related to this, that were years old. Don't imagine using glibc as a static library is high on their list.

This should work now, this needs the regression in vibe-d fixed first though as it uses a newer ldc2, which is required for musl libc support.

Bit messy to build, the dockerfile will be much simpler if LDC2 starts releasing musl libc builds again.

Also not 100% on the tracis script, so WIP for now to test..

@dlang-bot dlang-bot added the WIP label May 8, 2020
Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your help!
I don't have much time, but I wanted to drop a few notes:

  1. there's an alpine package for ldc (https://pkgs.alpinelinux.org/package/edge/community/x86_64/ldc)
  2. IIRC the gists were broken because of an API/token issue (GitHub blocking the requests)

dub.sdl Outdated
@@ -22,7 +22,9 @@ configuration "static" {
targetType "executable"
versions "VibeDefaultMain"
lflags "-lz" "-lssl" "-lcrypto" "-ldl" platform="posix"
dflags "-static" platform="posix"

// gcc on alpine has issues with the ld.gold linker, use bfd instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to pass this as DFLAGS from alpine as ld.gold does drastically speed-up the build time locally.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately ld.gold has some issues on musl, so either BFD or LLD has to be used.

@Geod24
Copy link
Member

Geod24 commented May 8, 2020

@Cogitri and myself maintain the Alpine packages.
If you use alpine:edge, you have gdc in main, dub, ldc, and rdmd in community, and dmd in testing. The 3.12 release shouldn't be too far either. That should save you a lot of time.

ci/Dockerfile Outdated
@@ -0,0 +1,10 @@
FROM alpine:edge

RUN apk add --no-cache g++ binutils-gold clang \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need gold though, LDC doesn't use it (doesn't quite work on Alpine).
See https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/community/ldc/01-conf.patch

set -e -u

cd /core/
DFLAGS="-linker=bfd" dub build -c static --compiler=ldc2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bfd is the default, see my above comment.

@looked-at-me
Copy link
Contributor Author

Got called back into work, has been a bit hectic. I'll see if I can get this building now.

@Geod24 How often do you update the packages? Is it a lot of work to maintain? Could be automated when LDC2 does a release? Preferably it would be nice to be able to select a specific version of LDC2.

@looked-at-me looked-at-me force-pushed the master branch 2 times, most recently from dd00dd5 to 8d0f876 Compare May 23, 2020 19:09
@looked-at-me
Copy link
Contributor Author

Alright looks to be good to go?

@Geod24
Copy link
Member

Geod24 commented May 24, 2020

@Geod24 How often do you update the packages? Is it a lot of work to maintain? Could be automated when LDC2 does a release? Preferably it would be nice to be able to select a specific version of LDC2.

It is fairly trivial to do, except that there are still some quirks (read: bugs) to be worked out. There's quite a few things that could be automated, not only on the Alpine side, but also other package managers (e.g. Homebrew, Nix...).

@looked-at-me
Copy link
Contributor Author

@wilzbach Any ETA on when this will be merged? Github links are still broken, though for a different reason than you mentioned. Right now it's crashing due to a bug in glibc with local thread variables not being accessible as the binary doesn't have a dynamic table for lookup for by the dynamic glibc library that is still loaded dynamically.

@looked-at-me
Copy link
Contributor Author

@wilzbach Plonk. Is there someone else I can ping?

ci/Dockerfile Outdated Show resolved Hide resolved
@@ -19,7 +19,9 @@ dub --compiler=${DC} -- --sanitycheck

# Compile to static binary with ldc
if [[ "${DC}" == "ldc2" ]]; then
dub build -c static --compiler=${DC}
docker build -t dlangtour_build ./ci/
docker run --rm -v `pwd`:/core/ -ti dlangtour_build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the interactive run ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from the docker run below.


# remove dub folder generated with build
# as it has root permissions from docker in the build folder
rm -rf ./.dub/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the rm inside of the docker image ? It doesn't make much sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker is run with a root user, the folder is generated inside the build folder it is connected to. Without this the remove outside would need root access, which it doesn't have.

@Geod24
Copy link
Member

Geod24 commented Jun 24, 2020

@looked-at-me : This is still listed as a WIP tho

Co-authored-by: Mathias LANG <[email protected]>
@looked-at-me looked-at-me changed the title [WIP] Build docker executable with musl libc. [---] Build docker executable with musl libc. Jul 12, 2020
@ljmf00
Copy link
Member

ljmf00 commented Oct 20, 2020

@looked-at-me @Geod24 what's the state of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants