You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was a big under-stimulated during X-mas break and decided to port tini to Zig (0.15.2).
The experience was very smooth (took me roughly 20h) to port and get all tests passing.
You can checkout my fork here and the following commit message regarding how to build it: blenessy@b34e39d
Please let me know if you are open for a PR - then I'll invest more time in changing the rest
of the files (build system, scripts, README.md, etc.).
Why?
There are other advantages over C, but this is the biggest win:
static binary size went down to 44KiB.
Why not Rust ?
Nothing wrong with it, but I prefer simpler languages (python, zig, golang).
Reacted by Pedro Tashima, Normunds Neimanis and jn64
There are other advantages over C, but this is the biggest win:
static binary size went down to 44KiB.
You know the static binary size for tini on this project is 42.8 KiB right? (0.19.0 release)
You were likely looking at the tini-static-amd64 binary that is 850KB, as it attempts to statically link glibc (which can be problematic for some binaries or glibc releases to do properly). Even when it works, it's still "fat" by comparison to musl.
Sadly, they did not publish static musl builds for other archs, so you'd need glibc (or the fat static glibc variants).
I haven't been keeping up with Zig, so not sure if the static build you produced is using musl or their own libc (I think Zig had been making progress on something like that?), but regardless your current result is not smaller than what is already published here.
If you did a port in Rust, it'd probably be lower if implemented with say eyra / rustix, effectively skipping libc. I assume Zig can do similar. For example in Rust I've produced a static "Hello World" that is only 456 bytes (outputs the text), with source code that isn't crazy low-level (eg: assembly focused), I couldn't figure out how to do that with Zig.
Build environment was Fedora 42 musl-libc-static package (musl 1.2.5)
No notable improvement when building with a checkout of the v0.19.0 release tag.
x86_64-linux-musl (via Alpine 3.24 container, musl 1.2.6) produces a static build of 60KB.
48KB with Alpine 3.11 (Dec 2019, musl 1.1.24). In Aug 2020 musl 1.2.1 changed their allocator to mallocng, which might have contributed towards the size bump.
zig cc works well for the task, it's simple to get into your local environment and is competitive on the size, no porting needed. It would also make publishing releases with musl for other arches more viable, as clearly that was a friction point with prior releases in the past?
FWIW: I did experiment with a very minimal tini like program in Zig and Rust, they both achieved roughly 1.6KB (freestanding target, no libc), while the more practical variants that'd use libc along with std ranged from 30-150KB depending on feature set, DX, and UX expectations. Not that anyone is going to really care much for such aggressive optimization to save less than 1MB 😅
Just sharing this reference for building the project, demonstrating in further detail/comparison to how zig compares to gcc/clang, notably with cross-compilation to musl from glibc hosts when targeting multiple archs without paying QEMU tax 😝
If you'd rather not download the binary, you can build Tini by running
`cmake . && make`.
On a glibc host this will produce tini dynamically linked to glibc, and tini-static with statically linked glibc (rarely a good idea with glibc and awfully fat given the program):
$ git clone --depth 1 https://github.com/krallin/tini /tmp/tini &&cd /tmp/tini
$ cmake .&& make
# 20.7KB (dynamic) vs 797KB (static):
$ du --bytes tini tini-static20728 tini796664 tini-static
That's only simple provided you've already got the toolchain / deps setup, the repo itself is providing a bunch of config via delegating to cmake + make to keep that simple.
You can get similar benefits with modern toolchains such as Zig and Rust, both of which are ridiculously simple to acquire on your build system, modern distros often package these too. Arguably their equivalent supporting configuration files are far simpler to grok too if that is ever needed.
Compile from x86_64 glibc to x86_64 musl (via musl-gcc) - 71KB (static musl)
So if we want to build for musl on such a host, we need something like musl-gcc or musl-clang installed (for convenience), then we can do the following:
$ CFLAGS='-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37' \ cmake . -DCMAKE_C_COMPILER=musl-gcc -DMINIMAL=1 \ && make
# 20KB (dynamic) vs 71KB (static):du --bytes tini tini-static20096 tini71184 tini-static
Those are stripped builds, so I'm not quite sure why they're fatter than the GH release binaries? Something differs in the build environment since 2020 I guess? 🤷♂️ (for reference, this is built with Fedora 42 with Clang 20, GCC 15.2, musl 1.2.5)
Cross-compile from x86_64 glibc to aarch64 musl (via clang) - 85KB (static musl)
That's all good, but now if you want to cross-compile for musl from say x86_64 to aarch64 on a glibc host... well that starts to veer into territory where zig cc is far more practical.
Collapsed due to verbosity
For Fedora we can install packages into a new sysroot for a different arch, we need the musl-libc-static package (alternatively you could acquire a musl sysroot for a foreign arch outside of your distro, but I'm not going there given the argument against a toolchain like zig):
dnf install -yq clang lld
# Minimal setup required for sysroot? (355 MB, depends on GCC files):
dnf --forcearch=aarch64 --installroot=/opt/sysroot/aarch64 --use-host-config install -yq musl-libc-static gcc
dnf --installroot /opt/sysroot/aarch64 clean all
# NOTE: The `=` prefix with `-isystem`/`-L` args is syntax that `clang` parses as prepending the `--sysroot` path:
$ clang -target aarch64-linux-musl -fuse-ld=lld -nostdinc \
--sysroot /opt/sysroot/aarch64/usr \
-isystem '=/aarch64-linux-musl/include' \
-L '=/aarch64-linux-musl/lib64' \
-static -Oz -std=gnu99 -Wl,-s \
-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37 -DTINI_MINIMAL=1 \
-Isrc src/tini.c -o tini-static
NOTE:
musl-clang is a shell script that does similar to the above, but as it doesn't split the compilation and linker flags separately, this project's use of -Werror will fail a build if you attempt to use with cmake like was shown previously with musl-gcc.
musl-gcc is also a wrapper script, but much simpler and invokes GCC to link musl via this:
Both musl-clang/musl-gcc have hard-coded the arch. I'm not familiar with GCC enough to know how compatible it'd be to just swap out the specs file to support linking to musl aarch64 via the /opt/sysroot/aarch64/ sysroot files.
LLD provides support to link to foreign archs, so -fuse-ld=lld is useful here.
AFAIK, this isn't much nicer to configure cmake for (at least with clang):
cmake . \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_FLAGS='-target aarch64-linux-musl --sysroot=/opt/sysroot/aarch64 -nostdinc -isystem =/usr/aarch64-linux-musl/include -DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37' \
-DCMAKE_EXE_LINKER_FLAGS='-target aarch64-linux-musl --sysroot=/opt/sysroot/aarch64 -fuse-ld=lld -L=/usr/aarch64-linux-musl/lib64' \
-DMINIMAL=1 \
&& make
# 17.7 KB (dynamic) vs 84.8KB (static)
du --bytes tini tini-static
17680 tini
84760 tini-static
$ file tini tini-static
tini: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=c460cd40da8227577ed3da9bd8082b176e708ad0, stripped
tini-static: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=f529d0bad5cbee874ebace75350816914a99d3a9, stripped
Building without cmake + make (via zig cc) - 46KB (static musl)
CMake is used to produce some dynamic build variables but you really don't need all of that in this case as it's two variables, the version and git ref (which unless you're building from the master branch instead of cloning the 0.19.0 tag from the April 2020 release, is going to be static anyway, or simple to manage directly given development pace).
You can add the file to src/ (otherwise at project root and use -I ./):
src/tiniConfig.h: (generated via cmake from this section)
The CMakeLists.txt file adds a bunch of compilation and linker flags, the bulk of which have little relevance for us to produce a static binary with musl as the libc - which when using zig cc (or Rust) with a *-musl target will default to static linking implicitly, but I suppose we can also be explicit.
So out of all that for a static build -std=gnu99 -static will be sufficient (but AFAIK should be fine without these?), you can add the others if there's some value to them to you 🤷♂️
Then there's the opt-ins to customize the build if you'd like those:
This ensure that even if you're building on a system that has old Linux Kernel
headers (< 3.4), Tini will be built with child subreaper support. This is
usually what you want if you're going to use Tini with Docker (if your host
Kernel supports Docker, it should also support child subreapers).
# 53KB (46KB if building for x86_64 arch)
zig cc -target aarch64-linux-musl \
-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37 \
-Oz -std=gnu99 -static \
src/tini.c -o tini-static
That's vastly simpler than the clang approach for cross-compiling from a x86_64 glibc host to a aarch64 musl target. No sysroot providing the musl libc for that target arch required, Zig handles that for you.
NOTE:
For the glibc *-gnu targets, you can append .2.34 as a suffix to the target to specifically dynamically link for that version of glibc, increasing it's compatibility (common problem for build environments when dynamic linking glibc). Static linking glibc is supported, but only via -target native, there's only stubs for dynamic linking and I don't think there's support for static linking a foreign arch with glibc via sysroot.
Converting that zig command to work with cmake will fail. zig cc itself needs to be wrapped since it's a subcommand to invoke, and some of the linker args (Zig forces it's own internal linker which doesn't support all the flags LLD does and ignores -fuse-ld to invoke a different linker). CMake can apparently configure the linker separately, but you can't call LLD directly with the format of the linker args the project adds, it'd have to be switched to something like musl-gcc/clang instead (clang if cross-compiling from glibc host to musl target).
I think it's great for something like Tini written in Zig to exist (and I'd
say the same for Rust for example) for those who like it, and I imagine a
higher level language can enable more features (and in this case perhaps a
smaller binary).
That said, I don't think that it really makes sense to *replace* this one
with that. Tini's a pretty minimal project and intended as such, and it
being written in C works well with that, IMO.
Forking seems the right path forward here!
On Sat, Jun 20, 2026 at 8:02 AM Brennan Kinney ***@***.***> wrote:
*polarathene* left a comment (krallin/tini#242)
<#242 (comment)>
Just sharing this reference for building the project, demonstrating in
further detail/comparison to how zig compares to gcc/clang, notably with
cross-compilation to musl from glibc hosts when targeting multiple archs
without paying QEMU tax 😝
Basic compilation - 797KB (static glibc)
The README has this build guidance
<https://github.com/krallin/tini/blob/master/README.md#building-tini>:
https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/README.md?plain=1#L260-L264
On a glibc host this will produce tini dynamically linked to glibc, and
tini-static with statically linked glibc (*rarely a good idea with glibc
and awfully fat given the program*):
$ git clone --depth 1 https://github.com/krallin/tini /tmp/tini && cd /tmp/tini
$ cmake . && make
# 20.7KB (dynamic) vs 797KB (static):
$ du --bytes tini tini-static20728 tini796664 tini-static
That's only simple provided you've already got the toolchain / deps setup,
the repo itself is providing a bunch of config
<https://github.com/krallin/tini/blob/master/CMakeLists.txt> via
delegating to cmake + make to keep that simple.
You can get similar benefits with modern toolchains such as Zig and Rust,
both of which are ridiculously simple to acquire on your build system,
modern distros often package these too. Arguably their equivalent
supporting configuration files are far simpler to grok too if that is ever
needed.
Compile from x86_64 glibc to x86_64 musl (*via musl-gcc*) - 71KB (static
musl)
So if we want to build for musl on such a host, we need something like
musl-gcc or musl-clang installed (*for convenience*), then we can do the
following:
$ CFLAGS='-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37' \ cmake . -DCMAKE_C_COMPILER=musl-gcc -DMINIMAL=1 \ && make
# 20KB (dynamic) vs 71KB (static):du --bytes tini tini-static20096 tini71184 tini-static
Those are stripped builds, so I'm not quite sure why they're fatter than
the GH release binaries? Something differs in the build environment since
2020 I guess? 🤷♂️ (*for reference, this is built with Fedora 42 with
Clang 20, GCC 15.2, musl 1.2.5*)
*EDIT:* Presumably due to changes in musl since April 2020? (*There was a
compiler fix in May 2025
<924c4bd>
to support musl 1.2.5, PR had been opened since April 2024
<#223>*)
Built on Alpine 3.11 (Dec 2019), with musl 1.1.24, this produces a 48KB
tini-static:
$ docker run --rm -it --workdir /opt/tini alpine:3.11
$ apk add git gcc musl-dev
$ /lib/ld-musl-x86_64.so.1musl libc (x86_64)Version 1.1.24
$ git clone --depth 1 https://github.com/krallin/tini .
$ echo -e '#define TINI_VERSION "0.19.0"\n#define TINI_GIT " - git.369448a"' > src/tiniConfig.h
$ gcc -Os -std=gnu99 -static -Wl,--strip-all src/tini.c -o tini-static
$ du -h tini-static48.0K tini
- Same size as results above if building with cmake . && make, or
cloning from the v0.19.0 tag and building.
- If building in a modern Alpine 3.24 (June 2026, musl 1.2.6)
container it produces a 60KB binary.
- For context mallocng was introduced with Musl 1.2.1
<https://musl.libc.org/releases.html> (Aug 2020), which may have
contributed to increase in size since.
Cross-compile from x86_64 glibc to aarch64 musl (*via clang*) - 85KB
(static musl)
That's all good, but now if you want to cross-compile for musl from say
x86_64 to aarch64 on a glibc host... well that starts to veer into
territory where zig cc is far more practical.
Collapsed due to verbosity
For Fedora we can install packages into a new sysroot for a different
arch, we need the musl-libc-static package (*alternatively you could
acquire a musl sysroot for a foreign arch outside of your distro, but I'm
not going there given the argument against a toolchain like zig*):
dnf install -yq clang lld
# Minimal setup required for sysroot? (355 MB, depends on GCC files):
dnf --forcearch=aarch64 --installroot=/opt/sysroot/aarch64 --use-host-config install -yq musl-libc-static gcc
dnf --installroot /opt/sysroot/aarch64 clean all
# NOTE: The `=` prefix with `-isystem`/`-L` args is syntax that `clang` parses as prepending the `--sysroot` path:
$ clang -target aarch64-linux-musl -fuse-ld=lld -nostdinc \
--sysroot /opt/sysroot/aarch64/usr \
-isystem '=/aarch64-linux-musl/include' \
-L '=/aarch64-linux-musl/lib64' \
-static -Oz -std=gnu99 -Wl,-s \
-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37 -DTINI_MINIMAL=1 \
-Isrc src/tini.c -o tini-static
*NOTE:*
-
musl-clang is a shell script that does similar to the above, but as it
doesn't split the compilation and linker flags separately, this project's
use of -Werror
<https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/CMakeLists.txt#L56>
will fail a build if you attempt to use with cmake like was shown
previously with musl-gcc.
-
musl-gcc is also a wrapper script, but much simpler and invokes GCC to
link musl via this:
#!/usr/bin/shexec "${REALGCC:-gcc}" "$@" -specs "/usr/x86_64-linux-musl/lib64/musl-gcc.specs"
-
Both musl-clang/musl-gcc have hard-coded the arch. I'm not familiar
with GCC enough to know how compatible it'd be to just swap out the specs
file to support linking to musl aarch64 via the /opt/sysroot/aarch64/
sysroot files.
-
LLD provides support to link to foreign archs, so -fuse-ld=lld is
useful here.
AFAIK, this isn't much nicer to configure cmake for (at least with clang):
cmake . \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_C_FLAGS='-target aarch64-linux-musl --sysroot=/opt/sysroot/aarch64 -nostdinc -isystem =/usr/aarch64-linux-musl/include -DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37' \
-DCMAKE_EXE_LINKER_FLAGS='-target aarch64-linux-musl --sysroot=/opt/sysroot/aarch64 -fuse-ld=lld -L=/usr/aarch64-linux-musl/lib64' \
-DMINIMAL=1 \
&& make
# 17.7 KB (dynamic) vs 84.8KB (static)
du --bytes tini tini-static
17680 tini
84760 tini-static
$ file tini tini-static
tini: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=c460cd40da8227577ed3da9bd8082b176e708ad0, stripped
tini-static: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=f529d0bad5cbee874ebace75350816914a99d3a9, stripped
------------------------------
Building without cmake + make (*via zig cc*) - 46KB (static musl)
CMake is used to produce some dynamic build variables but you really don't
need all of that in this case as it's two variables, the version and git
ref (*which unless you're building from the master branch instead of
cloning the 0.19.0 tag from the April 2020 release, is going to be static
anyway, or simple to manage directly given development pace*).
You can add the file to src/ (*otherwise at project root and use -I ./*):
*src/tiniConfig.h:* (*generated via cmake from this section
<https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/CMakeLists.txt#L4-L37>*
)
#define TINI_VERSION "0.19.0"#define TINI_GIT " - git.369448a"
The CMakeLists.txt file adds a bunch of compilation and linker flags, the
bulk of which have little relevance for us to produce a static binary with
musl as the libc - which when using zig cc (or Rust) with a *-musl target
will default to static linking implicitly, but I suppose we can also be
explicit.
https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/CMakeLists.txt#L56-L57https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/CMakeLists.txt#L80-L85
So out of all that for a static build -std=gnu99 -static will be
sufficient (*but AFAIK should be fine without these?*), you can add the
others if there's some value to them to you 🤷♂️
Then there's the opt-ins to customize the build if you'd like those:
https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/CMakeLists.txt#L9-L14https://github.com/krallin/tini/blob/369448a167e8b3da4ca5bca0b3307500c3371828/README.md?plain=1#L266-L273
# 53KB (46KB if building for x86_64 arch)
zig cc -target aarch64-linux-musl \
-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37 \
-Oz -std=gnu99 -static \
src/tini.c -o tini-static
That's vastly simpler than the clang approach for cross-compiling from a
x86_64 glibc host to a aarch64 musl target. No sysroot providing the musl
libc for that target arch required, Zig handles that for you.
*NOTE:*
- For the glibc *-gnu targets, you can append .2.34 as a suffix to the
target to specifically dynamically link for that version of glibc,
increasing it's compatibility (*common problem for build environments
when dynamic linking glibc*). Static linking glibc is supported, but
only via -target native, there's only stubs for dynamic linking and I
don't think there's support for static linking a foreign arch with glibc
via sysroot.
- Converting that zig command to work with cmake will fail. zig cc
itself needs to be wrapped since it's a subcommand to invoke, and some of
the linker args (*Zig forces it's own internal linker which doesn't
support all the flags LLD does and ignores -fuse-ld to invoke a different
linker*). CMake can apparently configure the linker separately, but
you can't call LLD directly with the format of the linker args the project
adds, it'd have to be switched to something like musl-gcc/clang
instead (*clang if cross-compiling from glibc host to musl target*).
—
Reply to this email directly, view it on GitHub
<#242?email_source=notifications&email_token=AANIHVQIFJL5XCIUQV5QQIT5AYSGFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGY3DMNJVHE42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-4756665599>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANIHVTMSF335IZESNG6ZOT5AYSGFAVCNFSNUABEKJSXA33TNF2G64TZHMZTCNBTGI2TOMZ3JFZXG5LFHMZTONZQGY2DONJYG2QXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AANIHVTJ7ZJ2IV7IQPILHF35AYSGFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGY3DMNJVHE42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ>
and Android
<https://github.com/notifications/mobile/android/AANIHVTGOGQEPE3JBJ3ZTT35AYSGFA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGY3DMNJVHE42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>.
Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
Activity
polarathene commentedon Jun 9, 2026
You know the static binary size for
tinion this project is 42.8 KiB right? (0.19.0release)You were likely looking at the
tini-static-amd64binary that is 850KB, as it attempts to statically link glibc (which can be problematic for some binaries or glibc releases to do properly). Even when it works, it's still "fat" by comparison to musl.Sadly, they did not publish static musl builds for other archs, so you'd need glibc (or the fat static glibc variants).
I haven't been keeping up with Zig, so not sure if the static build you produced is using musl or their own libc (I think Zig had been making progress on something like that?), but regardless your current result is not smaller than what is already published here.
If you did a port in Rust, it'd probably be lower if implemented with say
eyra/rustix, effectively skipping libc. I assume Zig can do similar. For example in Rust I've produced a static "Hello World" that is only 456 bytes (outputs the text), with source code that isn't crazy low-level (eg: assembly focused), I couldn't figure out how to do that with Zig.cpuguy83 commentedon Jun 19, 2026
Toolchains being available is far better than making a smaller binary here.
polarathene commentedon Jun 20, 2026
@cpuguy83 are you referring to availability of GCC/Clang toolchains compared to Zig or the language difference between Zig and C?
You can still use C and build with Zig via
zig cc:That produces a 53KB
tinibinary. If instead targetingx86_64-linux-muslit would be 46KB.By comparison (with standard GCC):
x86_64-linux-gnuis a 21KB (dynamic) or 797KB (static)x86_64-linux-musl(viamusl-gcc/musl-clang) static builds are 71KB / 85KB respectivelymusl-libc-staticpackage (musl1.2.5)v0.19.0release tag.x86_64-linux-musl(via Alpine 3.24 container, musl1.2.6) produces a static build of 60KB.1.1.24). In Aug 2020 musl1.2.1changed their allocator tomallocng, which might have contributed towards the size bump.zig ccworks well for the task, it's simple to get into your local environment and is competitive on the size, no porting needed. It would also make publishing releases with musl for other arches more viable, as clearly that was a friction point with prior releases in the past?FWIW: I did experiment with a very minimal tini like program in Zig and Rust, they both achieved roughly 1.6KB (freestanding target, no libc), while the more practical variants that'd use libc along with
stdranged from 30-150KB depending on feature set, DX, and UX expectations. Not that anyone is going to really care much for such aggressive optimization to save less than 1MB 😅polarathene commentedon Jun 20, 2026
Just sharing this reference for building the project, demonstrating in further detail/comparison to how
zigcompares togcc/clang, notably with cross-compilation to musl from glibc hosts when targeting multiple archs without paying QEMU tax 😝Basic compilation - 797KB (static glibc)
The README has this build guidance:
tini/README.md
Lines 260 to 264 in 369448a
On a glibc host this will produce
tinidynamically linked to glibc, andtini-staticwith statically linked glibc (rarely a good idea with glibc and awfully fat given the program):That's only simple provided you've already got the toolchain / deps setup, the repo itself is providing a bunch of config via delegating to
cmake+maketo keep that simple.You can get similar benefits with modern toolchains such as Zig and Rust, both of which are ridiculously simple to acquire on your build system, modern distros often package these too. Arguably their equivalent supporting configuration files are far simpler to grok too if that is ever needed.
Compile from
x86_64glibc tox86_64musl (viamusl-gcc) - 71KB (static musl)So if we want to build for musl on such a host, we need something like
musl-gccormusl-clanginstalled (for convenience), then we can do the following:Those are stripped builds, so I'm not quite sure why they're fatter than the GH release binaries? Something differs in the build environment since 2020 I guess? 🤷♂️ (for reference, this is built with Fedora 42 with Clang 20, GCC 15.2, musl
1.2.5)EDIT: Presumably due to changes in musl since April 2020? (There was a compiler fix in May 2025 to support musl
1.2.5, PR had been opened since April 2024)Built on Alpine 3.11 (Dec 2019), with musl
1.1.24, this produces a 48KBtini-static:cmake . && make, or cloning from thev0.19.0tag and building.mallocngwas introduced with Musl 1.2.1 (Aug 2020), which may have contributed to increase in size since.Cross-compile from
x86_64glibc toaarch64musl (viaclang) - 85KB (static musl)That's all good, but now if you want to cross-compile for
muslfrom sayx86_64toaarch64on aglibchost... well that starts to veer into territory wherezig ccis far more practical.Collapsed due to verbosity
For Fedora we can install packages into a new sysroot for a different arch, we need the
musl-libc-staticpackage (alternatively you could acquire a musl sysroot for a foreign arch outside of your distro, but I'm not going there given the argument against a toolchain like zig):NOTE:
musl-clangis a shell script that does similar to the above, but as it doesn't split the compilation and linker flags separately, this project's use of-Werrorwill fail a build if you attempt to use withcmakelike was shown previously withmusl-gcc.musl-gccis also a wrapper script, but much simpler and invokes GCC to link musl via this:Both
musl-clang/musl-gcchave hard-coded the arch. I'm not familiar with GCC enough to know how compatible it'd be to just swap out the specs file to support linking to muslaarch64via the/opt/sysroot/aarch64/sysroot files.LLD provides support to link to foreign archs, so
-fuse-ld=lldis useful here.AFAIK, this isn't much nicer to configure
cmakefor (at least withclang):Building without
cmake+make(viazig cc) - 46KB (static musl)CMake is used to produce some dynamic build variables but you really don't need all of that in this case as it's two variables, the version and git ref (which unless you're building from the
masterbranch instead of cloning the0.19.0tag from the April 2020 release, is going to be static anyway, or simple to manage directly given development pace).You can add the file to
src/(otherwise at project root and use-I ./):src/tiniConfig.h: (generated viacmakefrom this section)The
CMakeLists.txtfile adds a bunch of compilation and linker flags, the bulk of which have little relevance for us to produce a static binary with musl as the libc - which when usingzig cc(or Rust) with a*-musltarget will default to static linking implicitly, but I suppose we can also be explicit.tini/CMakeLists.txt
Lines 56 to 57 in 369448a
tini/CMakeLists.txt
Lines 80 to 85 in 369448a
So out of all that for a static build
-std=gnu99 -staticwill be sufficient (but AFAIK should be fine without these?), you can add the others if there's some value to them to you 🤷♂️Then there's the opt-ins to customize the build if you'd like those:
tini/CMakeLists.txt
Lines 9 to 14 in 369448a
tini/README.md
Lines 266 to 273 in 369448a
# 53KB (46KB if building for x86_64 arch) zig cc -target aarch64-linux-musl \ -DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37 \ -Oz -std=gnu99 -static \ src/tini.c -o tini-staticThat's vastly simpler than the
clangapproach for cross-compiling from ax86_64glibc host to aaarch64musl target. No sysroot providing the musl libc for that target arch required, Zig handles that for you.NOTE:
*-gnutargets, you can append.2.34as a suffix to the target to specifically dynamically link for that version of glibc, increasing it's compatibility (common problem for build environments when dynamic linking glibc). Static linking glibc is supported, but only via-target native, there's only stubs for dynamic linking and I don't think there's support for static linking a foreign arch with glibc via sysroot.cmakewill fail.zig ccitself needs to be wrapped since it's a subcommand to invoke, and some of the linker args (Zig forces it's own internal linker which doesn't support all the flags LLD does and ignores-fuse-ldto invoke a different linker). CMake can apparently configure the linker separately, but you can't call LLD directly with the format of the linker args the project adds, it'd have to be switched to something likemusl-gcc/clanginstead (clangif cross-compiling from glibc host to musl target).krallin commentedon Jun 20, 2026