Skip to content

Instantly share code, notes, and snippets.

@trikko
Created November 2, 2024 14:09
Show Gist options
  • Save trikko/172e6c988bc6b19183ba80ed4b2bd123 to your computer and use it in GitHub Desktop.
Save trikko/172e6c988bc6b19183ba80ed4b2bd123 to your computer and use it in GitHub Desktop.
Build dlang fully static executable

Docker with Alpine+MUSL

FROM alpine:latest
RUN apk add gcc musl-dev ldc dub llvm-libunwind-static openssl-libs-static gzip upx

On dub.json

"dflags": ["--nodefaultlib", "-static"],
"subConfigurations": {
	"requests": "staticssl"
}

Build and reduce size

dub --build=release # build as usual
strip -s your_exe # strip executable
gzexe your_exe # or upx -9 your_exe 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment