Repository navigation
Description
Introduction
At the moment, a Zig target triple (without versions) generally has an obvious 1:1 mapping to a GNU target triple, with only a few exceptions. In this issue, I propose that we completely break with the GNU style of target triple and, in particular, make the choice of libc and ABI two distinct components of the triple. This will enable Zig target triples (then quadruples) to communicate information that they can't today and handle a much wider range of ABI options.
Background & Motivation
Zig target triples, AFAICT, have the goal of completely replacing the -march, -mcpu, -mtune, -mabi, and -mmacosx-version-min options with a single, unified -target option to cover them all. -mcpu hasn't been integrated in the triple yet, but that work has been accepted in #4584 (and this proposal builds on that one). The only option that remains after that is -mabi which is notably missing from zig build-obj and friends, presumably on the assumption that the third component of the triple ought to cover it.
I've spent the past few weeks doing what I think is a fairly exhaustive survey of the ISA and ABI landscape. I put the cutoff point roughly around the mid-1970s; anything prior to that is for all intents and purposes super dead and unlikely to change any of my conclusions here. Having read through ISA manuals and ABI documentation for basically every architecture that I could find a manual for, my conclusion is that there is far more nuance to ABI choice than the current style of target triple allows. This isn't theoretical either; I'll demonstrate some real cases where the current approach falls short in ways that actually matter, and I'll show why the current approach can't scale in the long term.
I'll go over just a few architectures here; there are others that would also illustrate the point well (e.g. SuperH and m68k), but I hope the following are sufficient.
RISC-V
RISC-V is the hot new ISA on the block, so it's probably the most pertinent example here. It currently defines the following ABIs:
ilp32(full soft float)ilp32f(softf64andf128; hardf32)ilp32d(softf128; hardf32andf64)ilp32e(full soft float; reduced register set)lp64(full soft float)lp64f(softf64andf128; hardf32)lp64d(softf128; hardf32andf64)lp64q(full hard float)
zig build-obj and friends simply have no way to select between these ABIs at the moment. We would have to add ABI tags for all of them, and we can already see that adding those for each ABI (plus glibc variants, plus musl variants) is going to get way out of hand. Additionally, I believe there are more ABIs to come; I've heard talk of ilp32ef, for example, and RV128 ABIs will presumably materialize at some point.
Also worth noting here is that our current strategy of adopting gnueabi and gnueabihf (and musl variants) to differentiate hard float vs soft float starts to break down once unusual float ABIs (32-bit and 128-bit) enter the picture.
(Incidentally, these ABIs also show why the current std.Target.FloatAbi definition is not nuanced enough.)
LoongArch
LoongArch has roughly the same situation as RISC-V, minus the Q and E extensions:
ilp32s(full soft float)ilp32f(softf64; hardf32)ilp32d(full hard float)lp64s(full soft float)lp64f(softf64; hardf32)lp64d(full hard float)
An interesting thing to note here is that LoongArch is so far the only architecture I'm aware of to have done the sane thing and made the ABI actually, ya know, part of the ABI component of the target triple. So there's -gnu for ilp32d/lp64d, -gnuf32 for ilp32f/lp64f, and -gnusf for ilp32s/lp64s. Good job! (It used to be -gnuf64 instead of -gnu, but they simplified it because it's expected to be the common case.)
PowerPC
PowerPC (or Power ISA) has had a long list of ABIs over the years, being a fairly old architecture. Some never really saw practical use (e.g. the Windows NT ABI). It's a bit hard to categorize the ones that are actually relevant, but I think they can roughly be put like this:
- SVR4
- EABI
- Apple ABI
- ELF v1
- ELF v2
- AIX
(Notably, Zig's current use of the bespoke powerpc-linux-gnueabi(hf) triples is quite unfortunate because it implies an association with the PowerPC EABI, when that is not actually the case.)
In addition to these broad-strokes ABIs, there are variations based around the definition of long double. musl has done the simple thing and just declared that only long double = double is supported. Unfortunately, the rest of the world runs on one of two other definitions - either IEEE binary128 or the 128-bit "double-double" format that IBM came up with. The latter is unfortunately still very common, with binary128 only seeing limited use on newer powerpc64le distros (see #20579 for details). That last point is a real problem for Zig; zig build-obj and friends default to the "double-double" format with no way to switch to binary128 for the distros where this is the default.
But wait - there's more. Some of the above ABIs also have vector variants for efficient AltiVec usage. And of course there are also soft float variations of some of them.
And it gets much worse. You can also use a plethora of options such as -malign-natural, -malign-power, -maix-struct-return, and msvr4-struct-return to explicitly override various aspects of the aforementioned ABIs.
There's a near-incomprehensible number of possible combinations here.
MIPS
MIPS sits somewhere between RISC-V and PowerPC, with a lot of ABIs and configurability within those ABIs:
- EABI
- O32
- N32
- O64
- N64
(MIPS support in Zig currently has the same issue as PowerPC where gnueabi/gnueabihf are used to distinguish soft float and hard float, despite neither being EABI-based.)
In addition to these, there are soft float variants and single/double-precision variants. There are also the FPXX and FP64A variants. Like PowerPC, options abound for overriding various aspects of the chosen ABI.
Miscellaneous
Some extra notes that apply to various architectures on top of what I've already written above:
- ILP32 ABI variants (i.e. 32-bit pointers on a 64-bit machine) exist for at least Arm64, Itanium, and x86-64 (in addition to the aforementioned architectures). Note how they're called different things: x32 for x86-64,
gnu_ilp32(oraarch64_32as arch) for Arm64, and N32 for MIPS. - Quite a few architectures (RISC-V, Arm, SuperH, and some others I forget) have an FDPIC ABI that is meant for systems without an MMU. I believe it functions as an addition to the base ABI, but I haven't dug too deeply into it.
- It's probably obvious at this point, but just to make it explicit: GNU triples simply cannot represent most of the ABI nuance I've described so far.
- If we ever add more libcs than the ones we have now (ziglibc?), status quo will start to get ugly fast, even putting aside everything else I've brought up here.
Proposal
Hopefully I managed to convincingly get the point across that the current target triple format is not scalable enough for the task it's meant to achieve. Now I'll describe my idea for fixing this situation and future-proofing std.Target.
Most importantly, the triple should be replaced with a quadruple. Concretely, I'm proposing that it should now be of the form:
<arch>[.<cpu>[+~feats]]-<os>[.<ver>][-<api>[.<ver>][-<abi>[+~opts]]]
(Where api is basically libc.)
You must now specify: Neither API nor ABI, only API, or both API and ABI.
Some API tags that I anticipate us recognizing would be:
system: A special tag used for platforms where there is only and can only be one libc (e.g. libSystem on macOS).none: A special tag for use if you don't want a libc at all (e.g. for thefreestandingOS tag).mingw: Uses UCRT via MinGW-w64.msvcrt: Uses UCRT and VCRuntime natively (i.e. requires MSVC / Windows SDK tooling).gnuandmusl: glibc and musl respectively.wasi: wasi-libc (modified musl).
The ABI value is more complicated. In order to represent all the nuance necessary, it really needs to be treated in the same way that CPU model + features are. That is, you specify a base ABI and optionally add or subtract options, with the same + and ~ syntax used for CPU features. The available ABIs and options are determined by the selected architecture, just like CPU model and features.
If API and/or ABI are omitted, resolution works mostly as it does today. However, importantly, target resolution is augmented to pick sensible defaults for the ABI based on architecture, OS, and API choices. For example, if you specify powerpc64-linux-musl, elfv2 will be selected as the base ABI, as opposed to elfv1 for powerpc64-linux-gnu. This is because musl by definition requires elfv2. In addition to this, the base ABI also has sensible default options. In the aforementioned example, the complete resulting ABI is actually elfv2+ldbl64 because musl also mandates long double = double. If for some reason you want to override that, you could use elfv2~ldbl64 as the ABI component, but this is expected to be a rare need.
Examples
Here's roughly how each triple in zig targets | jq -r .libc[] | sort would look post-proposal:
aarch64_be-linux-gnu->aarch64_be-linux-gnu-lp64aarch64_be-linux-musl->aarch64_be-linux-musl-lp64aarch64-linux-gnu->aarch64-linux-gnu-lp64aarch64-linux-musl->aarch64-linux-musl-lp64aarch64-macos-none->aarch64-macos-system-lp64aarch64-windows-gnu->aarch64-windows-mingw-lp64(or-msvcrt-lp64+win)armeb-linux-gnueabi->armeb-linux-gnu-eabi+sfarmeb-linux-gnueabihf->armeb-linux-gnu-eabiarmeb-linux-musleabi->armeb-linux-musl-eabi+sfarmeb-linux-musleabihf->armeb-linux-musl-eabiarm-linux-gnueabi->arm-linux-gnu-eabi+sfarm-linux-gnueabihf->arm-linux-gnu-eabiarm-linux-musleabi->arm-linux-musl-eabi+sfarm-linux-musleabihf->arm-linux-musl-eabiarm-windows-gnu->arm-windows-mingw-eabi(or-msvcrt-eabi+win)csky-linux-gnueabi->csky-linux-gnu-abiv2+sfcsky-linux-gnueabihf->csky-linux-gnu-abiv2loongarch64-linux-gnu->loongarch64-linux-gnu-lp64dloongarch64-linux-musl->loongarch64-linux-musl-lp64dm68k-linux-gnu->m68k-linux-gnu-gnu(not to be confused with-sysvwhich is older and different!)m68k-linux-musl->m68k-linux-musl-gnu(likewise)mips64el-linux-gnuabi64->mips64el-linux-gnu-n64mips64el-linux-gnuabin32->mips64el-linux-gnu-n32mips64el-linux-musl->mips64el-linux-musl-n64mips64-linux-gnuabi64->mips64-linux-gnu-n64mips64-linux-gnuabin32->mips64-linux-gnu-n32mips64-linux-musl->mips64-linux-musl-n64mipsel-linux-gnueabi->mipsel-linux-gnu-o32+sfmipsel-linux-gnueabihf->mipsel-linux-gnu-o32mipsel-linux-musl->mipsel-linux-musl-o32mips-linux-gnueabi->mips-linux-gnu-o32+sf(see my notes on EABI above)mips-linux-gnueabihf->mips-linux-gnu-o32(likewise)mips-linux-musl->mips-linux-musl-o32powerpc64le-linux-gnu->powerpc64le-linux-gnu-elfv2powerpc64le-linux-musl->powerpc64le-linux-musl-elfv2+ldbl64powerpc64-linux-gnu->powerpc64-linux-gnu-elfv1powerpc64-linux-musl->powerpc64-linux-musl-elfv2+ldbl64powerpc-linux-gnueabi->powerpc-linux-gnu-svr4+sf(see my notes on EABI above)powerpc-linux-gnueabihf->powerpc-linux-gnu-svr4(likewise)powerpc-linux-musl->powerpc-linux-musl-svr4+ldbl64+secpltriscv32-linux-gnuilp32->riscv32-linux-gnu-ilp32d(yes, this one was confusingly named)riscv32-linux-musl->riscv32-linux-musl-ilp32driscv64-linux-gnu->riscv64-linux-gnu-lp64driscv64-linux-musl->riscv64-linux-musl-lp64ds390x-linux-gnu->s390x-linux-gnu-elfs390x-linux-musl->s390x-linux-musl-elfsparc64-linux-gnu->sparc64-linux-gnu-sysvsparc-linux-gnu->sparc-linux-gnu-sysvthumb-linux-gnueabi->thumb-linux-gnu-eabi+sfthumb-linux-gnueabihf->thumb-linux-gnu-eabithumb-linux-musleabi->thumb-linux-musl-eabi+sfthumb-linux-musleabihf->thumb-linux-musl-eabiwasm32-freestanding-musl->wasm32-freestanding-none-watc(WebAssembly Tool Conventions)wasm32-wasi-musl->wasm32-wasi-wasi-watc(likewise)x86_64-linux-gnu->x86_64-linux-gnu-sysvx86_64-linux-gnux32->x86_64-linux-gnu-x32x86_64-linux-musl->x86_64-linux-musl-sysvx86_64-macos-none->x86_64-macos-system-sysvx86_64-windows-gnu->x86_64-windows-mingw-sysv(or-msvcrt-win64)x86-linux-gnu->x86-linux-gnu-sysvx86-linux-musl->x86-linux-musl-sysvx86-windows-gnu->x86-windows-mingw-sysv(or-msvcrt-win32)
Note that many triples are still missing here; this is just intended to give a rough idea of how things will look. Also, some of these names would certainly be subject to change and/or bikeshedding during implementation.
Anticipated Concerns
I just want to address upfront some (reasonable!) concerns that I'm almost certain will be on people's minds after reading this:
- libc and ABI choice are linked: This is true, as any given libc only supports certain ABIs. But note that I could make the exact same argument for architecture and OS, OS and combined libc + ABI, etc. This argument would be flawed for (at least) the same reason it is here: Combinatorial explosion. Additionally, note that some architecture/OS combinations also impose restrictions on the ABI. The reality is that every component of a target triple imposes semantic restrictions on the other components, even prior to this proposal. Finally, some ABI options actually are completely independent of libc.
- This is more complicated than before: As I've hopefully demonstrated, this is only so because the status quo is unscalable and, in a case like
long doubleon PowerPC, downright unworkable. It's easy to keep things simple if you don't account for all cases. (Quotingzig zen: Edge cases matter.) Also, writing code for real hardware is necessarily more complex than e.g. a bytecode VM. I think it's actually entirely reasonable to ask that people understand the basics of their target environment, especially in cross-compilation scenarios. The behavior of picking sensible ABI defaults based on other components should help here. For native builds, things stay simple. - Deviating from GNU triples this much will add a learning curve: I simply think the benefits outweigh the costs here. Andrew has stated before that Zig wants to be able to target a much wider variety of platforms than, say, LLVM - including old ones. I think this proposal (or something equivalent, at least) is a clear prerequisite for that goal. Also, just because GNU triples have become ubiquitous, it does not follow that they are good. They are in fact not good for a long list of reasons. (Quoting
zig zenagain: Avoid local maximums.)
Activity
mnemnion commentedon Jul 20, 2024
This is a well-written proposal.
I'm going to provide what I consider the obvious push-back on it: Some triples can have multiple ABIs, but many cannot. For the ones which do, there's often an obvious default, and furthermore, it's a default which is lowest-common-denominator: code compiled for that ABI target will run, perhaps not optimally, on systems supporting one of the more advanced/enhanced ABIs.
Given that, what's the argument for including it in the now-quadruple? I look at the example list, and I'm not even 100% sure that the remaining info needs to be an ABI tag, it looks more like a list of supported CPU "extras". Mostly we're talking about presence or absence of hard and soft floats in various widths, I'd add vector instructions to that consideration. This is something which could affect source code in a way which is independent of the triple itself (example: providing the classic integer-casting fast inverse square root for soft float platforms, because it isn't actually faster on modern ISAs).
Why does this need to be a part of every Target, rather than continuing to conflate the libc with the base ABI, and provide a list of CPU features which is as independent as possible from the triple?
To be clear, I'm not persuaded either way, I just think that the issue would benefit from a focused answer to this question.
alexrp commentedon Jul 20, 2024
Can you give an example of this? I can't immediately think of a case where this is true. The ABI fundamentally affects the calling convention. In general, post-proposal, a given ABI can only be considered compatible with another ABI if the base ABI and option set both compare exactly equal. That is how an ABI works by definition.
It's not independent. If you compile a function using
f32parameters forriscv32-ilp32and then try to call it from code compiled forriscv32-ilp32f, you will get bogus results because the former passes floating point values in integer registers, while the latter passes them in floating point registers. (Well, more likely you'll get a linker error, but that's besides the point.)mlugg commentedon Jul 20, 2024
I really like this proposal -- it deals with an awkward overloading of the term "ABI" (which can be downright confusing), and provides a lot more flexibility around how ABIs are defined. I think your arguments for it are really solid.
One question that does come to mind is whether mandating the user to always specify the ABI when they want to specify the libc is reasonable. For instance, on Linux, it feels a little silly to have to clarify the
-sysvbit just because I want to use glibc rather than musl -- yes, I could technically try to use a different ABI at my own peril, but it would be completely broken, so I never reasonably would. If you take a Linux developer who happens to be aware of glibc vs musl libc, I don't think they are necessarily aware of calling conventions, particularly that the default Linux one is named after System V! So, I wonder: would it make sense to allow omitting the ABI part even when a libc is specified, and have it default to the "obvious" thing based on the architecture + OS + libc? On some targets, that might not exist, and so it would be fine to require it to be specified; but for targets likex86_64-linux,sysvis the only ABI you really ever want to use AFAIK.alexrp commentedon Jul 20, 2024
I address this exact point in the open questions. 🙂 I agree that there is merit to this. The current ordering of components in the proposal is so purely for aesthetic reasons. I'm very open to switching libc and ABI around to enable this.
mlugg commentedon Jul 20, 2024
I'm proposing it the other way around: I think changing the libc is probably desired more often than changing the ABI! That said, my dev experience is largely x86_64-centric, so perhaps I'm underestimating how common it is to need to override the ABI on other targets.
alexrp commentedon Jul 20, 2024
Oh, you're saying order as proposed but make the ABI optional, ok. Hmm. I'll think on that a bit. I definitely agree that this is the more common scenario on the mainstream platforms.
alexrp commentedon Jul 20, 2024
I think I agree with you @mlugg. Especially if we go the route of making OS/libc components imply sensible default options for the ABI component as I described in the open questions. Some examples of how this would play out:
powerpc-linux-glibcexpands topowerpc-linux-glibc-svr4svr4is the baseline ABI forpowerpconlinux.powerpc-linux-muslexpands topowerpc-linux-musl-svr4+ldbl64svr4is the baseline ABI forpowerpconlinux, and becausemuslmandatesldbl64for all PowerPC targets.powerpc64-linux-glibcexpands topowerpc64-linux-glibc-elfv1elfv1is the baseline ABI forpowerpc64onlinux.powerpc64-linux-muslandpowerpc64-linux-musl-elfv2expand topowerpc64-linux-musl-elfv2+ldbl64muslmandateselfv1for bothpowerpc64/powerpc64le, and mandatesldbl64for all PowerPC targets.powerpc64le-linux-glibcexpands topowerpc64le-linux-glibc-elfv2elfv1is the baseline ABI forpowerpc64leonlinux.powerpc64le-linux-muslexpands topowerpc64le-linux-musl-elfv2+ldbl64elfv1is the baseline ABI forpowerpc64leonlinux, and becausemuslmandatesldbl64for all PowerPC targets.riscv32-linux-glibcexpands toriscv32-linux-glibc-ilp32d(likewise for LoongArch)ilp32dis considered the "common case" default ABI in essentially all RISC-V/LoongArch tooling.riscv64-linux-muslexpands toriscv64-linux-musl-lp64d(likewise for LoongArch)lp64dis considered the "common case" default ABI in essentially all RISC-V/LoongArch tooling.arm-windows-mingwandarm-windows-mingw-eabiexpand toarm-windows-mingw-eabi+wineabiis the baseline ABI forarm, and forwindowsthe user almost certainly wantswin.arm-windows-msvcrtandarm-windows-msvcrt-eabiexpand toarm-windows-msvcrt-eabi+wineabiis the baseline ABI forarm, and becausemsvcrtmandateswin.aarch64-windows-mingwandaarch64-windows-mingw-lp64expand toaarch64-windows-mingw-lp64+winlp64is the baseline ABI foraarch64, and forwindowsthe user almost certainly wantswin.aarch64-windows-msvcrtandaarch64-windows-msvcrt-lp64expand toaarch64-windows-msvcrt-lp64+winlp64is the baseline ABI foraarch64, and becausemsvcrtmandateswin.And so on. This will involve a fair amount of logic to handle these cases, but I think it stays within the realm of manageability.
With this, I think explicitly specifying ABI will be relatively rare. The obvious cases would be toggling between
ibmldbl128andieeeldbl128forpowerpc64le(because different distros use either option), and switching float ABIs for Arm (32-bit), RISC-V, and LoongArch. Beyond that, I think it'll only happen in extremely specialized/embedded scenarios where you want full and explicit control over every option anyway.Going this route also mitigates the complexity concern because most users won't have to fiddle with ABI stuff.
alexrp commentedon Jul 21, 2024
I have updated the proposal so that you can specify neither libc nor ABI, only libc, or both libc and ABI, as discussed above. I've also added the behavior of picking sensible ABI defaults based on the other components to the core proposal.
Would love to hear feedback on the remaining open questions.
andrewrk commentedon Jul 26, 2024
related to #4584. edit: I see that @alexrp already linked this above.
alexrp commentedon Jul 26, 2024
By the way, if this does get accepted, I'm volunteering to do the work in either the 0.15.0 or 0.16.0 cycle.
glibc: Change riscv32-linux-gnuilp32 target triple to riscv32-linux-gnu.
glibc: Change riscv32-linux-gnuilp32 target triple to riscv32-linux-gnu.
andrewrk commentedon Aug 23, 2024
I finally took the time to digest this. Thanks for the excellent writeup and background research, @alexrp.
I think you've pretty clearly established that the ABI part of the target string needs to support a wider range of ABIs.
One point where I want to diverge from this proposal is that I plan to replace all libcs with zig code at some point. That includes musl, mingw, and wasi-libc, and the static bits of glibc. This will happen invisibly, with the same target string, with no breaking changes (related: #2879).
The idea of introducing a new "ziglibc" would only really affect the C headers. In other words the API. Furthermore, I'm not sure how valuable that would be as opposed to reusing e.g. musl's API. So, my counter-proposal to you is that the target string has "api" instead of "libc". It's a bit of a theoretical difference because it doesn't really affect the implications of this proposal. However, it's important to communicate that Zig is not guaranteeing that you literally are getting musl libc, mingw-w64 libc, etc., but that you are getting a compatible API.
This also solves another open issue which I was unable to find, where someone wanted to include the libc headers but not actually link against libc. This use case would be represented with providing an API in the target string, but omitting
-lc.I am marking this as accepted, along with establishing some issue close criteria:
-target x86_64-linux-muslwhich used to work before, it should either work the same, or the error message should include a hint of how to get the previous behavior.-target aarch64-macosalone and get the default API and ABI. On RISC-V, the default ABI should be determined based on CPU features.Related:
-targetand-mcpu/-march/-mtuneflags according to clang #491118 remaining items
polarathene commentedon Apr 17, 2025
glibc => GNU C Library
musl is another libc (C Library), so you want to just call it
gas an abbreviated abbreviation? (GNU)That part of the target is already the libc segment, so
gnuis relevant. Or do you wantmusllibctoo?At least I assume that's why the targets are as they are. The difference elsewhere to refer to them as glibc + musl, is similar to mixing of x86_64 / amd64 with aarch64 / arm64 (yes, I've seen some projects release with mixed arch conventions before)
Deviating from
gnutoglibcas a target doesn't help when it's just adding another variant name like arch conventions 🤷♂forrestthewoods commentedon Apr 22, 2025
Sure, if you already know what the quadruple means. Gnu means lots of things. In this particular context it implies something else. But if we're going to abandon target triples for a superior target quadruple why not make things suck less and use a term that is more clear?
glibc is clear. musl is clear. gnu is ambiguous and only well defined with context.
Alternatively I'm not convinced that choice of clib actually warrants special treatment in the target triple. In a sense it's "just" another library. A given program may link dozens of libs. Why does this particular lib get special attention? Ok well there's reasons for that. But it isn't strictly necessary. And tbh the clib API is kinda bad and I wouldn't be upset if programs simply didn't use it.
alexrp commentedon Apr 22, 2025
What do you propose for wasi-libc then? libSystem on Darwin? What about platforms where the libc doesn't really have a name, like FreeBSD and NetBSD?
You simply do not get a choice on many platforms; linking libc is sometimes the only stable way of interfacing with the kernel.
Beyond that, the proposal text explains the reasons for why the separation of libc API and ABI in the target string makes sense, chief among them being: 1) libc choice actually does affect ABI in some cases, 2) the proliferation of
Abitags would get completely out of hand on some platforms due to the possible combinations of libc and ABI, 3) the addition of even a single extra libc on Linux would already explode the number ofAbitags.forrestthewoods commentedon Apr 23, 2025
Hrm. Been thinking on it. I read your root post top-to-bottom several times. And reread the What the Hell is a Target Triple that led me to your comments and this here proposal. And read this whole thread.
I will admit that I'm not an expert on the edge cases (which matter) of triples and quadruples and apis and abis. But I do have far more experience with cross-platform build systems than I'd like! So while I admit ignorance I'm not totally ignorant.
As a preface, thanks for engaging. You didn't have to! I genuinely appreciate that.
If anything your kind responses and the comments about Eyra have convinced me that API (aka libc) should indeed not be part of the target triple/quadruple. And quite honestly I'm not sure we should be trying amalgamate all this different things into one big ugly string. Target N-ples are confusing as heck and the terms architecture, ISA, API, and ABI are all super super super overloaded. The fact that your proposed quadruple has NINE components does not bring as much enlightenment as I'd hoped.
To answer your question. wasi-libc, libSystem, FreeBSD flavor of libc, and NetBSD flavor of BSD are all literally just libraries. They may be super important critical libraries. They may even be strictly required. But they're still just libraries. FreeBSD and NetBSD may pretend the name is just libc. And perhaps the library file name is identical. But they're certainly unique and can be referenced separately.
So what am I proposing here exactly? I'm not sure. More thought is required. But I'm not entirely sure why there is any target tuple and why we don't simply have distinct flags. The permutation space of compiler modes and flags is nigh infinite. Is passing
-arch x86_64 -abi sysv -os android -lib bionic_libcthat bad? There is a weird tension between "want shorthand which implies other things" and "say the thing you actually want".Most programmers (myself included!) don't know all the factors that constitute "ABI". I'd say that forcing them to learn isn't necessarily a bad thing. target_triples and GCC/Clang flags are all extremely crusty with decades of legacy baggage. What we design if it were a clean slate? I don't know, but I'm not sure it's a target_quadruple.
alexrp commentedon Apr 26, 2025
Note that an important design goal of this proposal is that the overwhelming majority of users will never have to know that. Most users will only ever use
<arch>-<os>, and occasionally<arch>-<os>-<api>. So from the UX perspective, broadly speaking, nothing really changes.From the
std.TargetAPI perspective, this proposal is actually a pretty significant improvement: We'll no longer need to remember to do checks likebuiltin.target.abi.isGnu()to cover all the GNU tags; instead, we can just dobuiltin.target.api == .gnu. Similarly, if I want to check for the ELFv2 ABI on PowerPC, I can just check that directly rather than using complicated and error-prone proxies like "are we targetingpowerpc64le? Orpowerpc64with musl? Orpowerpc64on FreeBSD 13+? Orpowerpc64on OpenBSD/NetBSD?". If I want to check for x32 (on x86) or N32 (on MIPS), I can check that directly rather than it being tied to libc choice --gnux32/muslx32andgnuabin32/muslabin32respectively -- which really made little sense in the first place because it's also a kernel ABI. And so on.I think it kind of is, actually. Contrast with
-target x86_64-android-bionic-sysv- it's shorter, easier to type, and (to my eyes anyway) also easier to read. Your example gets even longer when interfacing with the Zig build system because of the way options are passed there:-Darch=x86_64 -Dabi=sysv -Dos=android -Dlib=bionic_libc.If I disregard ergonomics completely, I do actually agree that individual flags for the components are nicer on a technical level. But ergonomics are a big part of why target triples exist at all; they're a convenient way to communicate all the important details of a target machine.
Also, a non-critical but still important aspect to consider here is that a bunch of individual switches would not necessarily be a good option for
zig cc. It's nice that, in status quo (and with this proposal),zig build-exe -target <...>,zig build -Dtarget=<...>, andzig cc -target <...>all use the same syntax.polarathene commentedon Apr 26, 2025
@forrestthewoods Are you referring to the earlier discussion in comments above I raised about Eyra? Or something else?
forrestthewoods commentedon Apr 26, 2025
It's probably easier to read if the meaning of the target tuple has been burned into your brain. But it's harder if you aren't an expert. And it's less discoverable imho.
But ultimately it's the same thing and I'm just bike shedding syntax.
I think it's at least worth discussing what a clean slate implementation would look like. The way GCC and Clang do flags is so bad. Backwards compatibility is nice. But if we imagine a glorious future with Zig not having an LLVM backend and a new ziglibc would ideal look like? I'm extremely practical and accept we simply have to deal with significant baggage. But it's always useful to define what would be ideal and try to plot a course to ideal even if practicality demands a different destination.
Yeah that's great.
I have a moderate disdain for magic in compilers and build systems. I'm currently working on a hobby project custom build engine with the goal of enabling monorepo no-system-dependencies cross-platform polyglot building. Zig has moved mountains to make it plausible to do this. And I'm currently trying to get Zig's glibc to compile manually without using
zig cc. And it's really effing hard! The actual command line invocation I need is probably stupid simple. But there are layers and layers of abstraction that it's bloody difficult to figure out. So I do still think that specifying things explicitly is underrated.It was. The idea of supporting 10+ different libc implementations is interesting to consider. It really is just a library! Said library imposes a variety of constraints. But it's more of a regular library than people give credit imho.
alexrp commentedon Apr 26, 2025
I'm not necessarily opposed to exploring this, but I would argue that it ought to be a separate proposal given that it's a bit more radical than this one, mostly because of the
zig ccangle and the extra options that would need to be added tob.standardTargetOptions(). We will almost certainly move forward with this one in the short term - to quotezig zen: Incremental improvements.It's fundamental enough that even compiler-rt needs to know if libc is linked, and if so, which. I don't think we're ever getting around treating libc specially.
Note also that, for example, despite shipping them with Zig, we treat libc++ and libunwind significantly less 'magically' because they don't have as profound effects on the target environment, even though they're obviously still very fundamental libraries.
test: More cleanup of Windows targets in the module test matrix
test: More cleanup of Windows targets in the module test matrix
test: More cleanup of Windows targets in the module test matrix