-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
introduce operating system version ranges as part of the target; self-host native dynamic linker detection and native glibc version detection #4550
Conversation
In this branch Zig supports a more fine-grained sense of what is native and what is
Lots of breaking changes to related std lib APIs. Usage of Target.Cross and Target.Native need to be updated to use
|
fde3a8f
to
6d008f1
Compare
|
||
pub const LinuxVersionRange = struct { | ||
range: Version.Range, | ||
glibc: Version, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this field only be present for glibc targets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, the field is only valid for glibc targets and is otherwise undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than undefined should it be an optional with null
? Or union(enum) { Musl, Glibc: Version }
35b1e75
to
4b49247
Compare
* re-introduce `std.build.Target` which is distinct from `std.Target`. `std.build.Target` wraps `std.Target` so that it can be annotated as "the native target" or an explicitly specified target. * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a struct which has the tag as well as version range information. * `std.elf` gains some more ELF header constants. * `std.Target.parse` gains the ability to parse operating system version ranges as well as glibc version. * Added `std.Target.isGnuLibC()`. * self-hosted dynamic linker detection and glibc version detection. This also adds the improved logic using `/usr/bin/env` rather than invoking the system C compiler to find the dynamic linker when zig is statically linked. Related: #2084 Note: this `/usr/bin/env` code is work-in-progress. * `-target-glibc` CLI option is removed in favor of the new `-target` syntax. Example: `-target x86_64-linux-gnu.2.27` closes #1907
and glibc_detect_native_version
Zig now supports a more fine-grained sense of what is native and what is not. Some examples: This is now allowed: -target native Different OS but native CPU, default Windows C ABI: -target native-windows This could be useful for example when running in Wine. Different CPU but native OS, native C ABI. -target x86_64-native -mcpu=skylake Different C ABI but otherwise native target: -target native-native-musl -target native-native-gnu Lots of breaking changes to related std lib APIs. Calls to getOs() will need to be changed to getOsTag(). Calls to getArch() will need to be changed to getCpuArch(). Usage of Target.Cross and Target.Native need to be updated to use CrossTarget API. `std.build.Builder.standardTargetOptions` is changed to accept its parameters as a struct with default values. It now has the ability to specify a whitelist of targets allowed, as well as the default target. Rather than two different ways of collecting the target, it's now always a string that is validated, and prints helpful diagnostics for invalid targets. This feature should now be actually useful, and contributions welcome to further improve the user experience. `std.build.LibExeObjStep.setTheTarget` is removed. `std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget parameter. `std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are handled in the CrossTarget API and can be specified with the `-target` triple. `std.builtin.Version` gains a `format` method.
* `std.Target.getStandardDynamicLinkerPath` => `std.Target.standardDynamicLinkerPath` * it now takes a pointer to fixed size array rather than an allocator * `std.zig.system.NativeTargetInfo.detect` now supports reading PT_INTERP from /usr/bin/env
Blocking on #4578 |
7c6ba97
to
578dc16
Compare
It now takes a std.zig.CrossTarget parameter, and only resolves native things, leaving explicitly overridden things alone.
Commit Details
std.zig.CrossTarget
which is distinct fromstd.Target
.std.zig.CrossTarget
wrapsstd.Target
so that it can be annotated as "the native target" or an explicitly specified target.std.Target.Os
is moved tostd.Target.Os.Tag
. The former is now a struct which has the tag as well as version range information.std.elf
gains some more ELF header constants.std.Target.parse
gains the ability to parse operating system version ranges as well as glibc version.std.Target.isGnuLibC()
./usr/bin/env
rather than invoking the system C compiler to find the dynamic linker when zig is statically linked. Related: zig fails to detect musl as the native C ABI on alpine linux #2084Note: this
/usr/bin/env
code is work-in-progress.-target-glibc
CLI option is removed in favor of the new-target
syntax. Example:-target x86_64-linux-gnu.2.27
closes #1907
What this means for Zig programmers
comptime
code will have access to exactly which version(s) of an OS are being targeted.Updated syntax for
-target
to take into account OS version ranges:Here's what it will look like to populate a
std.Target
:Code that used
Target.parse
need not be updated.Checking for the OS when doing conditional compilation:
Option 1: easy, might get deprecated in the future:
Option 2, more verbose, less likely to be deprecated in the future:
Checklist:
/usr/bin/env
ELF implementation-mmacos_version_min
and related features since it can now be automatically handled by the target OS version range featureimplement operating system version detection, which sets the min and max both to that valuedone for linux; others will become contributor friendly issues.-target native-native-gnu
and-mcpu=native
.movewill open separate proposal for this-mcpu
to be part of the target tripleBuilder.standardTargetOptions
API and allow specifying a different default target, so that e.g.native-native-gnu
could be the default for a given project on windows (as chosen by build.zig).std.zig.CrossTarget.toTarget
andstd.zig.system.NativeTargetInfo.detect
.Follow-up Items