D for microservices: ldc, rdmd, dub now available on Alpine x86_64

Mathias Lang pro.mathias.lang at gmail.com
Tue Nov 5 02:16:28 UTC 2019

Hi all,
Recently there have been inquiries about support for D on Alpine 
Linux, a distribution mostly used in combination with Docker to 
create lightweight container images for microservices.

At BPF Korea, we're working on a blockchain written in D, and 
wanted to be able to easily test and distribute our node using 
Alpine images, but there was no package for it yet.

However, thanks to the work of many contributors before (Joakim 
Noah, yshui, Petar Kirov/zombinedev, and many others), most of 
the porting was already done and it was just a matter of fixing a 
few small issues and and creating the package definitions.

A package for `dub` (v1.18.0), `dtools` (ddemangle & rdmd), and 
`ldc` (v1.18.0) are now available in the `testing` repository of 
Alpine Linux edge. As `testing` is not enabled by default, you 
will need to specify the repository (or add it to your 
`/etc/apk/repositories`) when installing the packages.
For example:
apk --no-cache add -X 
http://dl-cdn.alpinelinux.org/alpine/edge/testing ldc ldc-static 
dtools-rdmd dub
This command needs to originate from an `alpine:edge` image as it 
links with a recent libc and LLVM.
If you just want the compiler, you still need to provide `ldc` & 
`ldc-static` for things to work out of the box.

More complete example of how we use it to build a D program, 
using multi-stage builds:
# Build from source
FROM alpine:edge AS Builder
RUN apk --no-cache add build-base git <other dependencies>
RUN apk --no-cache add -X 
http://dl-cdn.alpinelinux.org/alpine/edge/testing ldc ldc-static 
dtools-rdmd dub
ADD . /root/myproject/
WORKDIR /root/myproject/
# Note: This will redownload your dependencies every time, which 
doesn't play well with docker
# We use submodules for dependencies, hence we have 
RUN dub build --compiler=ldc2 ${DUB_OPTIONS}

# Runner
FROM alpine:edge
COPY --from=Builder /root/project/executable /usr/bin/executable
RUN apk --no-cache add libexecinfo <runtime dependencies>
WORKDIR /root/
ENTRYPOINT [ "/usr/bin/executable" ]
`DUB_OPTIONS` can be used to select a build, for example enabling 
coverage in a CI pipeline.

What's next ?
1) There is a pending PR 
(https://github.com/alpinelinux/aports/pull/12006) to have GDC 
working on all architectures alpine supports, not just x86_64.
2) Adding a package for gdmd
3) Rebuild packages based on GDC, so that all architectures are 
4) Move the packages to community so they are available out of 
the box. It would be great for it to happen by the end of the 
month, as the next alpine release would be around end of December 
according to their schedule, but that depends on how long PR take 
to be reviewed.
5) A DMD package for x86 and x86_64 shouldn't be hard to make 

More information about the Digitalmars-d-announce mailing list