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

Add ubuntu-musl for ldc #13

Closed
wants to merge 3 commits into from
Closed

Conversation

tom-tan
Copy link

@tom-tan tom-tan commented Sep 20, 2019

This PR is to solve #2 partially by providing a way to build a single binary with dlang.

Preparing host compilers for Alpine Linux (i.e. with musl libc) is time consuming task because dmd, gdc and ldc do not provide a binary for it.

Instead of that, this request provides a way to build an ubuntu image with a cross compiler for musl libc.
It enables us to build a single binary with dlang and I guess it covers most use cases that use Alpine Linux.
This request only adds ldc-ubuntu-musl image because ldc provides ldc-build-runtime that easily builds runtime libraries for other architecture but other compilers do not.

ldc-ubuntu-musl image is built based on the dockerfile for ldc-ubuntu.
It sets -mtriple=x86_64-alpine-linux-musl and -static by default.
Sorry, I found that rdmd does not work if these options are the default setting.

root@da690b9721ba:/# echo 'import std; void main() { writeln("Hello!"); }' > sample.d
root@da690b9721ba:/# ldc2 -unittest -run sample.d # ldc2 works
Hello!
root@da690b9721ba:/# rdmd -unittest sample.d # but rdmd does not work
Aborted

To make less confusion, I make them as an option.

root@6de061b342bc:/# echo 'import std; void main() { writeln("Hello!"); }' > sample.d
root@6de061b342bc:/# ldc2 sample.d # compile with x86_64-unknown-linux-gnu by default
root@6de061b342bc:/# ldd sample
        linux-vdso.so.1 (0x00007fff4f1fe000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fca5efd0000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fca5edcc000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fca5ebad000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fca5e80f000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fca5e5f7000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca5e206000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fca5f1d8000)
root@6de061b342bc:/# ldc2 -mtriple=x86_64-alpine-linux-musl -static sample.d # specify to build a statically-linked binary with musl libc
root@6de061b342bc:/# ldd sample
        not a dynamic executable

Limitations:

  • std.net.curl does not work because libcurl (installed via apt) is build with glibc
  • It only supports -static (it is provided in the default settings) because I failed to prepare dynamic link libraries with musl libc(See a thread in gitter chat of ldc)

@wilzbach
Copy link
Owner

wilzbach commented Dec 2, 2019

@tom-tan thanks a lot for your PR and I'm sorry that I missed this one.

Since a few weeks there's an ldc package in Alpine:

https://pkgs.alpinelinux.org/package/edge/testing/x86_64/ldc

Do you think we should change this PR to use this package instead?

@tom-tan
Copy link
Author

tom-tan commented Dec 5, 2019

@wilzbach Thank you for your reply!
IMO it is better to use Alpine package. It is easier to maintain and can build docker image faster than the current PR that builds cross compiler.

I will fix this PR to use Alpine package.

@tom-tan
Copy link
Author

tom-tan commented Oct 28, 2020

I close this request to investigate better solution using Alpine Linux instead of using tentative plan to use Ubuntu with musl libc.

@tom-tan tom-tan closed this Oct 28, 2020
@tom-tan tom-tan mentioned this pull request Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants