Skip to content

Commit

Permalink
Merge pull request #4550 from ziglang/os-version-ranges
Browse files Browse the repository at this point in the history
introduce operating system version ranges as part of the target; self-host native dynamic linker detection and native glibc version detection
  • Loading branch information
andrewrk authored Feb 29, 2020
2 parents 1b41f2d + 3cba603 commit 7617610
Show file tree
Hide file tree
Showing 104 changed files with 3,338 additions and 2,123 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
}
dependOnLib(b, exe, ctx.llvm);

if (exe.target.getOs() == .linux) {
if (exe.target.getOsTag() == .linux) {
try addCxxKnownPath(b, ctx, exe, "libstdc++.a",
\\Unable to determine path to libstdc++.a
\\On Fedora, install libstdc++-static and try again.
Expand Down
83 changes: 42 additions & 41 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const builtin = @import("builtin");
const std = @import("std");
const builtin = std.builtin;
const io = std.io;
const fs = std.fs;
const process = std.process;
Expand All @@ -10,8 +10,8 @@ const testing = std.testing;

const max_doc_file_size = 10 * 1024 * 1024;

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

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

var mode = builtin.Mode.Debug;
var mode: builtin.Mode = .Debug;
var link_objects = std.ArrayList([]const u8).init(allocator);
defer link_objects.deinit();
var target_str: ?[]const u8 = null;
Expand All @@ -533,9 +533,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent);
const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end];
if (mem.eql(u8, end_tag_name, "code_release_fast")) {
mode = builtin.Mode.ReleaseFast;
mode = .ReleaseFast;
} else if (mem.eql(u8, end_tag_name, "code_release_safe")) {
mode = builtin.Mode.ReleaseSafe;
mode = .ReleaseSafe;
} else if (mem.eql(u8, end_tag_name, "code_link_object")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const obj_tok = try eatToken(tokenizer, Token.Id.TagContent);
Expand Down Expand Up @@ -1001,30 +1001,30 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var

for (toc.nodes) |node| {
switch (node) {
Node.Content => |data| {
.Content => |data| {
try out.write(data);
},
Node.Link => |info| {
.Link => |info| {
if (!toc.urls.contains(info.url)) {
return parseError(tokenizer, info.token, "url not found: {}", .{info.url});
}
try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });
},
Node.Nav => {
.Nav => {
try out.write(toc.toc);
},
Node.Builtin => |tok| {
.Builtin => |tok| {
try out.write("<pre>");
try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);
try out.write("</pre>");
},
Node.HeaderOpen => |info| {
.HeaderOpen => |info| {
try out.print(
"<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n",
.{ info.n, info.url, info.url, info.name, info.url, info.n },
);
},
Node.SeeAlso => |items| {
.SeeAlso => |items| {
try out.write("<p>See also:</p><ul>\n");
for (items) |item| {
const url = try urlize(allocator, item.name);
Expand All @@ -1035,10 +1035,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
try out.write("</ul>\n");
},
Node.Syntax => |content_tok| {
.Syntax => |content_tok| {
try tokenizeAndPrint(tokenizer, out, content_tok);
},
Node.Code => |code| {
.Code => |code| {
code_progress_index += 1;
warn("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count });

Expand Down Expand Up @@ -1075,16 +1075,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name});
switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try build_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try build_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try build_args.append("--release-small");
try out.print(" --release-small", .{});
},
Expand Down Expand Up @@ -1142,13 +1142,14 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try out.print("\n{}</code></pre>\n", .{colored_stderr});
break :code_block;
}
const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch
return parseError(tokenizer, code.source_token, "example failed to compile", .{});

if (code.target_str) |triple| {
if (mem.startsWith(u8, triple, "wasm32") or
mem.startsWith(u8, triple, "riscv64-linux") or
mem.startsWith(u8, triple, "x86_64-linux") and
(builtin.os != .linux or builtin.arch != .x86_64))
(mem.startsWith(u8, triple, "x86_64-linux") and
std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64))
{
// skip execution
try out.print("</code></pre>\n", .{});
Expand Down Expand Up @@ -1207,16 +1208,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
Expand Down Expand Up @@ -1249,16 +1250,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
Expand Down Expand Up @@ -1306,16 +1307,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
var mode_arg: []const u8 = "";
switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try test_args.append("--release-safe");
mode_arg = " --release-safe";
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try test_args.append("--release-fast");
mode_arg = " --release-fast";
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try test_args.append("--release-small");
mode_arg = " --release-small";
},
Expand Down Expand Up @@ -1386,20 +1387,20 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}

switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try build_args.append("--release-safe");
if (!code.is_inline) {
try out.print(" --release-safe", .{});
}
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try build_args.append("--release-fast");
if (!code.is_inline) {
try out.print(" --release-fast", .{});
}
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try build_args.append("--release-small");
if (!code.is_inline) {
try out.print(" --release-small", .{});
Expand Down Expand Up @@ -1461,16 +1462,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name});
switch (code.mode) {
builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => {
.Debug => {},
.ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
builtin.Mode.ReleaseFast => {
.ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
builtin.Mode.ReleaseSmall => {
.ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
Expand Down
30 changes: 15 additions & 15 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ const nan = std.math.nan(f128);
but you can switch to {#syntax#}Optimized{#endsyntax#} mode on a per-block basis:</p>
{#code_begin|obj|foo#}
{#code_release_fast#}
const builtin = @import("builtin");
const std = @import("std");
const builtin = std.builtin;
const big = @as(f64, 1 << 40);

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

test "variable alignment" {
var x: i32 = 1234;
const align_of_i32 = @alignOf(@TypeOf(x));
assert(@TypeOf(&x) == *i32);
assert(*i32 == *align(align_of_i32) i32);
if (builtin.arch == builtin.Arch.x86_64) {
if (std.Target.current.cpu.arch == .x86_64) {
assert((*i32).alignment == 4);
}
}
Expand Down Expand Up @@ -2474,7 +2475,7 @@ test "default struct initialization fields" {
</p>
{#code_begin|test#}
const std = @import("std");
const builtin = @import("builtin");
const builtin = std.builtin;
const assert = std.debug.assert;

const Full = packed struct {
Expand Down Expand Up @@ -3204,8 +3205,8 @@ test "separate scopes" {

{#header_open|switch#}
{#code_begin|test|switch#}
const assert = @import("std").debug.assert;
const builtin = @import("builtin");
const std = @import("std");
const assert = std.debug.assert;

test "switch simple" {
const a: u64 = 10;
Expand Down Expand Up @@ -3249,16 +3250,16 @@ test "switch simple" {
}

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

// Inside a function, switch statements implicitly are compile-time
// evaluated if the target expression is compile-time known.
test "switch inside function" {
switch (builtin.os) {
builtin.Os.fuchsia => {
switch (std.Target.current.os.tag) {
.fuchsia => {
// On an OS other than fuchsia, block is not even analyzed,
// so this compile error is not triggered.
// On fuchsia this compile error would be triggered.
Expand Down Expand Up @@ -7364,8 +7365,6 @@ test "main" {
the {#syntax#}export{#endsyntax#} keyword used on a function:
</p>
{#code_begin|obj#}
const builtin = @import("builtin");

comptime {
@export(internalName, .{ .name = "foo", .linkage = .Strong });
}
Expand Down Expand Up @@ -9397,7 +9396,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
</p>
{#code_begin|test|detect_test#}
const std = @import("std");
const builtin = @import("builtin");
const builtin = std.builtin;
const assert = std.debug.assert;

test "builtin.is_test" {
Expand Down Expand Up @@ -9715,7 +9714,8 @@ WebAssembly.instantiate(typedArray, {
<pre><code>$ node test.js
The result is 3</code></pre>
{#header_open|WASI#}
<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>
<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>
{#code_begin|exe|wasi#}
{#target_wasi#}
const std = @import("std");
Expand Down
Loading

0 comments on commit 7617610

Please sign in to comment.