Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fba39ff
restructuring std.Target for OS version ranges, pass 1
andrewrk Feb 24, 2020
4616af0
introduce operating system version ranges as part of the target
andrewrk Feb 25, 2020
d4f375c
stage1: remove get_self_libc_path
andrewrk Feb 25, 2020
87b9e74
update std lib to new Target API
andrewrk Feb 25, 2020
dbe4d72
separate std.Target and std.zig.CrossTarget
andrewrk Feb 26, 2020
c8669a4
improve debug info for optionals
andrewrk Feb 26, 2020
cf233ba
fix target parsing
andrewrk Feb 26, 2020
cebcacd
fix standardTargetOptions and improve init-exe to use it
andrewrk Feb 26, 2020
0912484
improve the "external executor" detection logic
andrewrk Feb 26, 2020
622b5b6
fix not setting the dynamic linker path when cross compiling
andrewrk Feb 26, 2020
34d2700
clean up CrossTarget.getExternalExecutor
andrewrk Feb 26, 2020
7927764
mips: implement Target.getStandardDynamicLinkerPath
andrewrk Feb 26, 2020
2387f48
fix incorrect builtin import code for windows
andrewrk Feb 27, 2020
6226726
fix builder.findProgram test
andrewrk Feb 27, 2020
36aa3c8
fix __stack_chk_guard emitted even when not linking libc
andrewrk Feb 27, 2020
bafa895
compiler-rt: inline at call site to workaround a bug
andrewrk Feb 27, 2020
2536e4c
WASI has no dynamic linker
andrewrk Feb 27, 2020
3c3316d
update tests to new Target API
andrewrk Feb 27, 2020
70bf887
update docgen to new Target API
andrewrk Feb 27, 2020
f89a184
don't error out for targets with unknown standard dynamic linker path
andrewrk Feb 27, 2020
662b5f7
update docs to latest Target API
andrewrk Feb 27, 2020
60f2f34
getStandardDynamicLinkerPath renamed and no allocator
andrewrk Feb 27, 2020
fd006c1
std.zig.system.NativeTargetInfo.detect: almost no Allocator
andrewrk Feb 27, 2020
3683ba8
complete the native target detection based on /usr/bin/env
andrewrk Feb 28, 2020
d45ea4d
stage1: make get_native_target go through self-hosted
andrewrk Feb 28, 2020
ef24f2d
remove special darwin os version min handling
andrewrk Feb 28, 2020
07f5211
implement native OS version detection for linux
andrewrk Feb 28, 2020
500dde3
dynamic_linker becomes a field of std.zig.CrossTarget
andrewrk Feb 28, 2020
578dc16
fix compiler crash when comptime parsing targets
andrewrk Feb 28, 2020
8691d3c
improve std.zig.system.NativeTargetInfo.detect
andrewrk Feb 28, 2020
aa13f33
fix handling of CrossTarget.cpu_model
andrewrk Feb 28, 2020
4591236
CrossTarget.cpu_model: communicate intent precisely
andrewrk Feb 28, 2020
7e3bb00
don't choose native ld path when os is non native
andrewrk Feb 28, 2020
4bc893c
update test to newer API
andrewrk Feb 29, 2020
e683eee
fix CrossTarget.isNative, setGnuLibCVersion, zigTriple
andrewrk Feb 29, 2020
1aef0be
std.Target.Os.WindowsVersion: non-exhaustive enum
andrewrk Feb 29, 2020
3cba603
fix crash when building docgen
andrewrk Feb 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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