Skip to content

Commit 7617610

Browse files
authored
Merge pull request #4550 from ziglang/os-version-ranges
introduce operating system version ranges as part of the target; self-host native dynamic linker detection and native glibc version detection
2 parents 1b41f2d + 3cba603 commit 7617610

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+3338
-2123
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
298298
}
299299
dependOnLib(b, exe, ctx.llvm);
300300

301-
if (exe.target.getOs() == .linux) {
301+
if (exe.target.getOsTag() == .linux) {
302302
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
303303
\\Unable to determine path to libstdc++.a
304304
\\On Fedora, install libstdc++-static and try again.

doc/docgen.zig

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const builtin = @import("builtin");
21
const std = @import("std");
2+
const builtin = std.builtin;
33
const io = std.io;
44
const fs = std.fs;
55
const process = std.process;
@@ -10,8 +10,8 @@ const testing = std.testing;
1010

1111
const max_doc_file_size = 10 * 1024 * 1024;
1212

13-
const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt();
14-
const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt();
13+
const exe_ext = @as(std.zig.CrossTarget, .{}).exeFileExt();
14+
const obj_ext = @as(std.zig.CrossTarget, .{}).oFileExt();
1515
const tmp_dir_name = "docgen_tmp";
1616
const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
1717

@@ -521,7 +521,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
521521
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", .{code_kind_str});
522522
}
523523

524-
var mode = builtin.Mode.Debug;
524+
var mode: builtin.Mode = .Debug;
525525
var link_objects = std.ArrayList([]const u8).init(allocator);
526526
defer link_objects.deinit();
527527
var target_str: ?[]const u8 = null;
@@ -533,9 +533,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
533533
const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent);
534534
const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end];
535535
if (mem.eql(u8, end_tag_name, "code_release_fast")) {
536-
mode = builtin.Mode.ReleaseFast;
536+
mode = .ReleaseFast;
537537
} else if (mem.eql(u8, end_tag_name, "code_release_safe")) {
538-
mode = builtin.Mode.ReleaseSafe;
538+
mode = .ReleaseSafe;
539539
} else if (mem.eql(u8, end_tag_name, "code_link_object")) {
540540
_ = try eatToken(tokenizer, Token.Id.Separator);
541541
const obj_tok = try eatToken(tokenizer, Token.Id.TagContent);
@@ -1001,30 +1001,30 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10011001

10021002
for (toc.nodes) |node| {
10031003
switch (node) {
1004-
Node.Content => |data| {
1004+
.Content => |data| {
10051005
try out.write(data);
10061006
},
1007-
Node.Link => |info| {
1007+
.Link => |info| {
10081008
if (!toc.urls.contains(info.url)) {
10091009
return parseError(tokenizer, info.token, "url not found: {}", .{info.url});
10101010
}
10111011
try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });
10121012
},
1013-
Node.Nav => {
1013+
.Nav => {
10141014
try out.write(toc.toc);
10151015
},
1016-
Node.Builtin => |tok| {
1016+
.Builtin => |tok| {
10171017
try out.write("<pre>");
10181018
try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);
10191019
try out.write("</pre>");
10201020
},
1021-
Node.HeaderOpen => |info| {
1021+
.HeaderOpen => |info| {
10221022
try out.print(
10231023
"<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n",
10241024
.{ info.n, info.url, info.url, info.name, info.url, info.n },
10251025
);
10261026
},
1027-
Node.SeeAlso => |items| {
1027+
.SeeAlso => |items| {
10281028
try out.write("<p>See also:</p><ul>\n");
10291029
for (items) |item| {
10301030
const url = try urlize(allocator, item.name);
@@ -1035,10 +1035,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10351035
}
10361036
try out.write("</ul>\n");
10371037
},
1038-
Node.Syntax => |content_tok| {
1038+
.Syntax => |content_tok| {
10391039
try tokenizeAndPrint(tokenizer, out, content_tok);
10401040
},
1041-
Node.Code => |code| {
1041+
.Code => |code| {
10421042
code_progress_index += 1;
10431043
warn("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count });
10441044

@@ -1075,16 +1075,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10751075
});
10761076
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name});
10771077
switch (code.mode) {
1078-
builtin.Mode.Debug => {},
1079-
builtin.Mode.ReleaseSafe => {
1078+
.Debug => {},
1079+
.ReleaseSafe => {
10801080
try build_args.append("--release-safe");
10811081
try out.print(" --release-safe", .{});
10821082
},
1083-
builtin.Mode.ReleaseFast => {
1083+
.ReleaseFast => {
10841084
try build_args.append("--release-fast");
10851085
try out.print(" --release-fast", .{});
10861086
},
1087-
builtin.Mode.ReleaseSmall => {
1087+
.ReleaseSmall => {
10881088
try build_args.append("--release-small");
10891089
try out.print(" --release-small", .{});
10901090
},
@@ -1142,13 +1142,14 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11421142
try out.print("\n{}</code></pre>\n", .{colored_stderr});
11431143
break :code_block;
11441144
}
1145-
const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1145+
const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch
1146+
return parseError(tokenizer, code.source_token, "example failed to compile", .{});
11461147

11471148
if (code.target_str) |triple| {
11481149
if (mem.startsWith(u8, triple, "wasm32") or
11491150
mem.startsWith(u8, triple, "riscv64-linux") or
1150-
mem.startsWith(u8, triple, "x86_64-linux") and
1151-
(builtin.os != .linux or builtin.arch != .x86_64))
1151+
(mem.startsWith(u8, triple, "x86_64-linux") and
1152+
std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64))
11521153
{
11531154
// skip execution
11541155
try out.print("</code></pre>\n", .{});
@@ -1207,16 +1208,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12071208
});
12081209
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
12091210
switch (code.mode) {
1210-
builtin.Mode.Debug => {},
1211-
builtin.Mode.ReleaseSafe => {
1211+
.Debug => {},
1212+
.ReleaseSafe => {
12121213
try test_args.append("--release-safe");
12131214
try out.print(" --release-safe", .{});
12141215
},
1215-
builtin.Mode.ReleaseFast => {
1216+
.ReleaseFast => {
12161217
try test_args.append("--release-fast");
12171218
try out.print(" --release-fast", .{});
12181219
},
1219-
builtin.Mode.ReleaseSmall => {
1220+
.ReleaseSmall => {
12201221
try test_args.append("--release-small");
12211222
try out.print(" --release-small", .{});
12221223
},
@@ -1249,16 +1250,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12491250
});
12501251
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
12511252
switch (code.mode) {
1252-
builtin.Mode.Debug => {},
1253-
builtin.Mode.ReleaseSafe => {
1253+
.Debug => {},
1254+
.ReleaseSafe => {
12541255
try test_args.append("--release-safe");
12551256
try out.print(" --release-safe", .{});
12561257
},
1257-
builtin.Mode.ReleaseFast => {
1258+
.ReleaseFast => {
12581259
try test_args.append("--release-fast");
12591260
try out.print(" --release-fast", .{});
12601261
},
1261-
builtin.Mode.ReleaseSmall => {
1262+
.ReleaseSmall => {
12621263
try test_args.append("--release-small");
12631264
try out.print(" --release-small", .{});
12641265
},
@@ -1306,16 +1307,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13061307
});
13071308
var mode_arg: []const u8 = "";
13081309
switch (code.mode) {
1309-
builtin.Mode.Debug => {},
1310-
builtin.Mode.ReleaseSafe => {
1310+
.Debug => {},
1311+
.ReleaseSafe => {
13111312
try test_args.append("--release-safe");
13121313
mode_arg = " --release-safe";
13131314
},
1314-
builtin.Mode.ReleaseFast => {
1315+
.ReleaseFast => {
13151316
try test_args.append("--release-fast");
13161317
mode_arg = " --release-fast";
13171318
},
1318-
builtin.Mode.ReleaseSmall => {
1319+
.ReleaseSmall => {
13191320
try test_args.append("--release-small");
13201321
mode_arg = " --release-small";
13211322
},
@@ -1386,20 +1387,20 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13861387
}
13871388

13881389
switch (code.mode) {
1389-
builtin.Mode.Debug => {},
1390-
builtin.Mode.ReleaseSafe => {
1390+
.Debug => {},
1391+
.ReleaseSafe => {
13911392
try build_args.append("--release-safe");
13921393
if (!code.is_inline) {
13931394
try out.print(" --release-safe", .{});
13941395
}
13951396
},
1396-
builtin.Mode.ReleaseFast => {
1397+
.ReleaseFast => {
13971398
try build_args.append("--release-fast");
13981399
if (!code.is_inline) {
13991400
try out.print(" --release-fast", .{});
14001401
}
14011402
},
1402-
builtin.Mode.ReleaseSmall => {
1403+
.ReleaseSmall => {
14031404
try build_args.append("--release-small");
14041405
if (!code.is_inline) {
14051406
try out.print(" --release-small", .{});
@@ -1461,16 +1462,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14611462
});
14621463
try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name});
14631464
switch (code.mode) {
1464-
builtin.Mode.Debug => {},
1465-
builtin.Mode.ReleaseSafe => {
1465+
.Debug => {},
1466+
.ReleaseSafe => {
14661467
try test_args.append("--release-safe");
14671468
try out.print(" --release-safe", .{});
14681469
},
1469-
builtin.Mode.ReleaseFast => {
1470+
.ReleaseFast => {
14701471
try test_args.append("--release-fast");
14711472
try out.print(" --release-fast", .{});
14721473
},
1473-
builtin.Mode.ReleaseSmall => {
1474+
.ReleaseSmall => {
14741475
try test_args.append("--release-small");
14751476
try out.print(" --release-small", .{});
14761477
},

doc/langref.html.in

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ const nan = std.math.nan(f128);
965965
but you can switch to {#syntax#}Optimized{#endsyntax#} mode on a per-block basis:</p>
966966
{#code_begin|obj|foo#}
967967
{#code_release_fast#}
968-
const builtin = @import("builtin");
968+
const std = @import("std");
969+
const builtin = std.builtin;
969970
const big = @as(f64, 1 << 40);
970971

971972
export fn foo_strict(x: f64) f64 {
@@ -2063,15 +2064,15 @@ test "pointer child type" {
20632064
alignment of the underlying type, it can be omitted from the type:
20642065
</p>
20652066
{#code_begin|test#}
2066-
const assert = @import("std").debug.assert;
2067-
const builtin = @import("builtin");
2067+
const std = @import("std");
2068+
const assert = std.debug.assert;
20682069

20692070
test "variable alignment" {
20702071
var x: i32 = 1234;
20712072
const align_of_i32 = @alignOf(@TypeOf(x));
20722073
assert(@TypeOf(&x) == *i32);
20732074
assert(*i32 == *align(align_of_i32) i32);
2074-
if (builtin.arch == builtin.Arch.x86_64) {
2075+
if (std.Target.current.cpu.arch == .x86_64) {
20752076
assert((*i32).alignment == 4);
20762077
}
20772078
}
@@ -2474,7 +2475,7 @@ test "default struct initialization fields" {
24742475
</p>
24752476
{#code_begin|test#}
24762477
const std = @import("std");
2477-
const builtin = @import("builtin");
2478+
const builtin = std.builtin;
24782479
const assert = std.debug.assert;
24792480

24802481
const Full = packed struct {
@@ -3204,8 +3205,8 @@ test "separate scopes" {
32043205

32053206
{#header_open|switch#}
32063207
{#code_begin|test|switch#}
3207-
const assert = @import("std").debug.assert;
3208-
const builtin = @import("builtin");
3208+
const std = @import("std");
3209+
const assert = std.debug.assert;
32093210

32103211
test "switch simple" {
32113212
const a: u64 = 10;
@@ -3249,16 +3250,16 @@ test "switch simple" {
32493250
}
32503251

32513252
// Switch expressions can be used outside a function:
3252-
const os_msg = switch (builtin.os) {
3253-
builtin.Os.linux => "we found a linux user",
3253+
const os_msg = switch (std.Target.current.os.tag) {
3254+
.linux => "we found a linux user",
32543255
else => "not a linux user",
32553256
};
32563257

32573258
// Inside a function, switch statements implicitly are compile-time
32583259
// evaluated if the target expression is compile-time known.
32593260
test "switch inside function" {
3260-
switch (builtin.os) {
3261-
builtin.Os.fuchsia => {
3261+
switch (std.Target.current.os.tag) {
3262+
.fuchsia => {
32623263
// On an OS other than fuchsia, block is not even analyzed,
32633264
// so this compile error is not triggered.
32643265
// On fuchsia this compile error would be triggered.
@@ -7364,8 +7365,6 @@ test "main" {
73647365
the {#syntax#}export{#endsyntax#} keyword used on a function:
73657366
</p>
73667367
{#code_begin|obj#}
7367-
const builtin = @import("builtin");
7368-
73697368
comptime {
73707369
@export(internalName, .{ .name = "foo", .linkage = .Strong });
73717370
}
@@ -9397,7 +9396,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
93979396
</p>
93989397
{#code_begin|test|detect_test#}
93999398
const std = @import("std");
9400-
const builtin = @import("builtin");
9399+
const builtin = std.builtin;
94019400
const assert = std.debug.assert;
94029401

94039402
test "builtin.is_test" {
@@ -9715,7 +9714,8 @@ WebAssembly.instantiate(typedArray, {
97159714
<pre><code>$ node test.js
97169715
The result is 3</code></pre>
97179716
{#header_open|WASI#}
9718-
<p>Zig's support for WebAssembly System Interface (WASI) is under active development. Example of using the standard library and reading command line arguments:</p>
9717+
<p>Zig's support for WebAssembly System Interface (WASI) is under active development.
9718+
Example of using the standard library and reading command line arguments:</p>
97199719
{#code_begin|exe|wasi#}
97209720
{#target_wasi#}
97219721
const std = @import("std");

0 commit comments

Comments
 (0)