authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-19 20:26:46-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-08-19 20:26:46-04:00
loge5e6eb983159df0a089e7d1c8efcea9006e253a9
tree80611a8b7faca0d150bcb66c4d8403134a339a49
parent39f43fea8d0f6aa1c69cb7c3209f57f5ce00b273
parentb75eeae5951f2dc4ff19f795ebd856c134722375
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #12368 from ziglang/stage3-default

make self-hosted the default compiler

47 files changed, 484 insertions(+), 1507 deletions(-)

CMakeLists.txt+1-1
...@@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE)...@@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE)
12endif()12endif()
1313
14if(NOT CMAKE_INSTALL_PREFIX)14if(NOT CMAKE_INSTALL_PREFIX)
15 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage1" CACHE STRING15 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage2" CACHE STRING
16 "Directory to install zig to" FORCE)16 "Directory to install zig to" FORCE)
17endif()17endif()
1818
build.zig+29-42
...@@ -15,6 +15,7 @@ const stack_size = 32 * 1024 * 1024;...@@ -15,6 +15,7 @@ const stack_size = 32 * 1024 * 1024;
1515
16pub fn build(b: *Builder) !void {16pub fn build(b: *Builder) !void {
17 b.setPreferredReleaseMode(.ReleaseFast);17 b.setPreferredReleaseMode(.ReleaseFast);
18 const test_step = b.step("test", "Run all the tests");
18 const mode = b.standardReleaseOptions();19 const mode = b.standardReleaseOptions();
19 const target = b.standardTargetOptions(.{});20 const target = b.standardTargetOptions(.{});
20 const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");21 const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
...@@ -39,8 +40,6 @@ pub fn build(b: *Builder) !void {...@@ -39,8 +40,6 @@ pub fn build(b: *Builder) !void {
39 const docs_step = b.step("docs", "Build documentation");40 const docs_step = b.step("docs", "Build documentation");
40 docs_step.dependOn(&docgen_cmd.step);41 docs_step.dependOn(&docgen_cmd.step);
4142
42 const toolchain_step = b.step("test-toolchain", "Run the tests for the toolchain");
43
44 var test_cases = b.addTest("src/test.zig");43 var test_cases = b.addTest("src/test.zig");
45 test_cases.stack_size = stack_size;44 test_cases.stack_size = stack_size;
46 test_cases.setBuildMode(mode);45 test_cases.setBuildMode(mode);
...@@ -64,10 +63,9 @@ pub fn build(b: *Builder) !void {...@@ -64,10 +63,9 @@ pub fn build(b: *Builder) !void {
6463
65 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;64 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
6665
67 const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;66 const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
68 const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
69 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;67 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
70 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);68 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
71 const llvm_has_m68k = b.option(69 const llvm_has_m68k = b.option(
72 bool,70 bool,
73 "llvm-has-m68k",71 "llvm-has-m68k",
...@@ -137,7 +135,7 @@ pub fn build(b: *Builder) !void {...@@ -137,7 +135,7 @@ pub fn build(b: *Builder) !void {
137 };135 };
138136
139 const main_file: ?[]const u8 = mf: {137 const main_file: ?[]const u8 = mf: {
140 if (!is_stage1) break :mf "src/main.zig";138 if (!have_stage1) break :mf "src/main.zig";
141 if (use_zig0) break :mf null;139 if (use_zig0) break :mf null;
142 break :mf "src/stage1.zig";140 break :mf "src/stage1.zig";
143 };141 };
...@@ -150,7 +148,7 @@ pub fn build(b: *Builder) !void {...@@ -150,7 +148,7 @@ pub fn build(b: *Builder) !void {
150 exe.setBuildMode(mode);148 exe.setBuildMode(mode);
151 exe.setTarget(target);149 exe.setTarget(target);
152 if (!skip_stage2_tests) {150 if (!skip_stage2_tests) {
153 toolchain_step.dependOn(&exe.step);151 test_step.dependOn(&exe.step);
154 }152 }
155153
156 b.default_step.dependOn(&exe.step);154 b.default_step.dependOn(&exe.step);
...@@ -248,7 +246,7 @@ pub fn build(b: *Builder) !void {...@@ -248,7 +246,7 @@ pub fn build(b: *Builder) !void {
248 }246 }
249 };247 };
250248
251 if (is_stage1) {249 if (have_stage1) {
252 const softfloat = b.addStaticLibrary("softfloat", null);250 const softfloat = b.addStaticLibrary("softfloat", null);
253 softfloat.setBuildMode(.ReleaseFast);251 softfloat.setBuildMode(.ReleaseFast);
254 softfloat.setTarget(target);252 softfloat.setTarget(target);
...@@ -360,8 +358,7 @@ pub fn build(b: *Builder) !void {...@@ -360,8 +358,7 @@ pub fn build(b: *Builder) !void {
360 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);358 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
361 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);359 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
362 exe_options.addOption(bool, "value_tracing", value_tracing);360 exe_options.addOption(bool, "value_tracing", value_tracing);
363 exe_options.addOption(bool, "is_stage1", is_stage1);361 exe_options.addOption(bool, "have_stage1", have_stage1);
364 exe_options.addOption(bool, "omit_stage2", omit_stage2);
365 if (tracy) |tracy_path| {362 if (tracy) |tracy_path| {
366 const client_cpp = fs.path.join(363 const client_cpp = fs.path.join(
367 b.allocator,364 b.allocator,
...@@ -396,8 +393,7 @@ pub fn build(b: *Builder) !void {...@@ -396,8 +393,7 @@ pub fn build(b: *Builder) !void {
396 test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);393 test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
397 test_cases_options.addOption(bool, "skip_non_native", skip_non_native);394 test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
398 test_cases_options.addOption(bool, "skip_stage1", skip_stage1);395 test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
399 test_cases_options.addOption(bool, "is_stage1", is_stage1);396 test_cases_options.addOption(bool, "have_stage1", have_stage1);
400 test_cases_options.addOption(bool, "omit_stage2", omit_stage2);
401 test_cases_options.addOption(bool, "have_llvm", enable_llvm);397 test_cases_options.addOption(bool, "have_llvm", enable_llvm);
402 test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);398 test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
403 test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);399 test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
...@@ -418,7 +414,7 @@ pub fn build(b: *Builder) !void {...@@ -418,7 +414,7 @@ pub fn build(b: *Builder) !void {
418 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");414 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
419 test_cases_step.dependOn(&test_cases.step);415 test_cases_step.dependOn(&test_cases.step);
420 if (!skip_stage2_tests) {416 if (!skip_stage2_tests) {
421 toolchain_step.dependOn(test_cases_step);417 test_step.dependOn(test_cases_step);
422 }418 }
423419
424 var chosen_modes: [4]builtin.Mode = undefined;420 var chosen_modes: [4]builtin.Mode = undefined;
...@@ -442,11 +438,11 @@ pub fn build(b: *Builder) !void {...@@ -442,11 +438,11 @@ pub fn build(b: *Builder) !void {
442 const modes = chosen_modes[0..chosen_mode_index];438 const modes = chosen_modes[0..chosen_mode_index];
443439
444 // run stage1 `zig fmt` on this build.zig file just to make sure it works440 // run stage1 `zig fmt` on this build.zig file just to make sure it works
445 toolchain_step.dependOn(&fmt_build_zig.step);441 test_step.dependOn(&fmt_build_zig.step);
446 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");442 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
447 fmt_step.dependOn(&fmt_build_zig.step);443 fmt_step.dependOn(&fmt_build_zig.step);
448444
449 toolchain_step.dependOn(tests.addPkgTests(445 test_step.dependOn(tests.addPkgTests(
450 b,446 b,
451 test_filter,447 test_filter,
452 "test/behavior.zig",448 "test/behavior.zig",
...@@ -457,11 +453,10 @@ pub fn build(b: *Builder) !void {...@@ -457,11 +453,10 @@ pub fn build(b: *Builder) !void {
457 skip_non_native,453 skip_non_native,
458 skip_libc,454 skip_libc,
459 skip_stage1,455 skip_stage1,
460 omit_stage2,456 skip_stage2_tests,
461 is_stage1,
462 ));457 ));
463458
464 toolchain_step.dependOn(tests.addPkgTests(459 test_step.dependOn(tests.addPkgTests(
465 b,460 b,
466 test_filter,461 test_filter,
467 "lib/compiler_rt.zig",462 "lib/compiler_rt.zig",
...@@ -472,11 +467,10 @@ pub fn build(b: *Builder) !void {...@@ -472,11 +467,10 @@ pub fn build(b: *Builder) !void {
472 skip_non_native,467 skip_non_native,
473 true, // skip_libc468 true, // skip_libc
474 skip_stage1,469 skip_stage1,
475 omit_stage2 or true, // TODO get these all passing470 skip_stage2_tests or true, // TODO get these all passing
476 is_stage1,
477 ));471 ));
478472
479 toolchain_step.dependOn(tests.addPkgTests(473 test_step.dependOn(tests.addPkgTests(
480 b,474 b,
481 test_filter,475 test_filter,
482 "lib/c.zig",476 "lib/c.zig",
...@@ -487,37 +481,36 @@ pub fn build(b: *Builder) !void {...@@ -487,37 +481,36 @@ pub fn build(b: *Builder) !void {
487 skip_non_native,481 skip_non_native,
488 true, // skip_libc482 true, // skip_libc
489 skip_stage1,483 skip_stage1,
490 omit_stage2 or true, // TODO get these all passing484 skip_stage2_tests or true, // TODO get these all passing
491 is_stage1,
492 ));485 ));
493486
494 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));487 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
495 toolchain_step.dependOn(tests.addStandaloneTests(488 test_step.dependOn(tests.addStandaloneTests(
496 b,489 b,
497 test_filter,490 test_filter,
498 modes,491 modes,
499 skip_non_native,492 skip_non_native,
500 enable_macos_sdk,493 enable_macos_sdk,
501 target,494 target,
502 omit_stage2,495 skip_stage2_tests,
503 b.enable_darling,496 b.enable_darling,
504 b.enable_qemu,497 b.enable_qemu,
505 b.enable_rosetta,498 b.enable_rosetta,
506 b.enable_wasmtime,499 b.enable_wasmtime,
507 b.enable_wine,500 b.enable_wine,
508 ));501 ));
509 toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, omit_stage2));502 test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests));
510 toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));503 test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
511 toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes));504 test_step.dependOn(tests.addCliTests(b, test_filter, modes));
512 toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));505 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
513 toolchain_step.dependOn(tests.addTranslateCTests(b, test_filter));506 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
514 if (!skip_run_translated_c) {507 if (!skip_run_translated_c) {
515 toolchain_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));508 test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
516 }509 }
517 // tests for this feature are disabled until we have the self-hosted compiler available510 // tests for this feature are disabled until we have the self-hosted compiler available
518 // toolchain_step.dependOn(tests.addGenHTests(b, test_filter));511 // test_step.dependOn(tests.addGenHTests(b, test_filter));
519512
520 const std_step = tests.addPkgTests(513 test_step.dependOn(tests.addPkgTests(
521 b,514 b,
522 test_filter,515 test_filter,
523 "lib/std/std.zig",516 "lib/std/std.zig",
...@@ -528,14 +521,8 @@ pub fn build(b: *Builder) !void {...@@ -528,14 +521,8 @@ pub fn build(b: *Builder) !void {
528 skip_non_native,521 skip_non_native,
529 skip_libc,522 skip_libc,
530 skip_stage1,523 skip_stage1,
531 omit_stage2 or true, // TODO get these all passing524 true, // TODO get these all passing
532 is_stage1,525 ));
533 );
534
535 const test_step = b.step("test", "Run all the tests");
536 test_step.dependOn(toolchain_step);
537 test_step.dependOn(std_step);
538 test_step.dependOn(docs_step);
539}526}
540527
541const exe_cflags = [_][]const u8{528const exe_cflags = [_][]const u8{
ci/azure/build.zig deleted-976
...@@ -1,976 +0,0 @@
1const std = @import("std");
2const builtin = std.builtin;
3const Builder = std.build.Builder;
4const BufMap = std.BufMap;
5const mem = std.mem;
6const ArrayList = std.ArrayList;
7const io = std.io;
8const fs = std.fs;
9const InstallDirectoryOptions = std.build.InstallDirectoryOptions;
10const assert = std.debug.assert;
11
12const zig_version = std.builtin.Version{ .major = 0, .minor = 10, .patch = 0 };
13
14pub fn build(b: *Builder) !void {
15 b.setPreferredReleaseMode(.ReleaseFast);
16 const mode = b.standardReleaseOptions();
17 const target = b.standardTargetOptions(.{});
18 const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
19 const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;
20
21 const docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
22 docgen_exe.single_threaded = single_threaded;
23
24 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
25 const langref_out_path = fs.path.join(
26 b.allocator,
27 &[_][]const u8{ b.cache_root, "langref.html" },
28 ) catch unreachable;
29 const docgen_cmd = docgen_exe.run();
30 docgen_cmd.addArgs(&[_][]const u8{
31 rel_zig_exe,
32 "doc" ++ fs.path.sep_str ++ "langref.html.in",
33 langref_out_path,
34 });
35 docgen_cmd.step.dependOn(&docgen_exe.step);
36
37 const docs_step = b.step("docs", "Build documentation");
38 docs_step.dependOn(&docgen_cmd.step);
39
40 const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
41 const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
42 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
43 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
44 const llvm_has_m68k = b.option(
45 bool,
46 "llvm-has-m68k",
47 "Whether LLVM has the experimental target m68k enabled",
48 ) orelse false;
49 const llvm_has_csky = b.option(
50 bool,
51 "llvm-has-csky",
52 "Whether LLVM has the experimental target csky enabled",
53 ) orelse false;
54 const llvm_has_arc = b.option(
55 bool,
56 "llvm-has-arc",
57 "Whether LLVM has the experimental target arc enabled",
58 ) orelse false;
59 const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");
60
61 b.installDirectory(InstallDirectoryOptions{
62 .source_dir = "lib",
63 .install_dir = .lib,
64 .install_subdir = "zig",
65 .exclude_extensions = &[_][]const u8{
66 // exclude files from lib/std/compress/
67 ".gz",
68 ".z.0",
69 ".z.9",
70 "rfc1951.txt",
71 "rfc1952.txt",
72 // exclude files from lib/std/compress/deflate/testdata
73 ".expect",
74 ".expect-noinput",
75 ".golden",
76 ".input",
77 "compress-e.txt",
78 "compress-gettysburg.txt",
79 "compress-pi.txt",
80 "rfc1951.txt",
81 // exclude files from lib/std/tz/
82 ".tzif",
83 // others
84 "README.md",
85 },
86 .blank_extensions = &[_][]const u8{
87 "test.zig",
88 },
89 });
90
91 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
92 const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
93 const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
94 const force_gpa = b.option(bool, "force-gpa", "Force the compiler to use GeneralPurposeAllocator") orelse false;
95 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
96 const strip = b.option(bool, "strip", "Omit debug information") orelse false;
97 const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false;
98
99 const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: {
100 if (strip) break :blk @as(u32, 0);
101 if (mode != .Debug) break :blk 0;
102 break :blk 4;
103 };
104
105 const main_file: ?[]const u8 = if (is_stage1) null else "src/main.zig";
106
107 const exe = b.addExecutable("zig", main_file);
108 exe.strip = strip;
109 exe.install();
110 exe.setBuildMode(mode);
111 exe.setTarget(target);
112
113 b.default_step.dependOn(&exe.step);
114 exe.single_threaded = single_threaded;
115
116 if (target.isWindows() and target.getAbi() == .gnu) {
117 // LTO is currently broken on mingw, this can be removed when it's fixed.
118 exe.want_lto = false;
119 }
120
121 const exe_options = b.addOptions();
122 exe.addOptions("build_options", exe_options);
123
124 exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);
125 exe_options.addOption(bool, "skip_non_native", false);
126 exe_options.addOption(bool, "have_llvm", enable_llvm);
127 exe_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
128 exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
129 exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
130 exe_options.addOption(bool, "force_gpa", force_gpa);
131
132 if (link_libc) {
133 exe.linkLibC();
134 }
135
136 const is_debug = mode == .Debug;
137 const enable_logging = b.option(bool, "log", "Enable debug logging with --debug-log") orelse is_debug;
138 const enable_link_snapshots = b.option(bool, "link-snapshot", "Whether to enable linker state snapshots") orelse false;
139
140 const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
141 const version = if (opt_version_string) |version| version else v: {
142 const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch });
143
144 var code: u8 = undefined;
145 const git_describe_untrimmed = b.execAllowFail(&[_][]const u8{
146 "git", "-C", b.build_root, "describe", "--match", "*.*.*", "--tags",
147 }, &code, .Ignore) catch {
148 break :v version_string;
149 };
150 const git_describe = mem.trim(u8, git_describe_untrimmed, " \n\r");
151
152 switch (mem.count(u8, git_describe, "-")) {
153 0 => {
154 // Tagged release version (e.g. 0.9.0).
155 if (!mem.eql(u8, git_describe, version_string)) {
156 std.debug.print("Zig version '{s}' does not match Git tag '{s}'\n", .{ version_string, git_describe });
157 std.process.exit(1);
158 }
159 break :v version_string;
160 },
161 2 => {
162 // Untagged development build (e.g. 0.9.0-dev.2025+ecf0050a9).
163 var it = mem.split(u8, git_describe, "-");
164 const tagged_ancestor = it.next() orelse unreachable;
165 const commit_height = it.next() orelse unreachable;
166 const commit_id = it.next() orelse unreachable;
167
168 const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);
169 if (zig_version.order(ancestor_ver) != .gt) {
170 std.debug.print("Zig version '{}' must be greater than tagged ancestor '{}'\n", .{ zig_version, ancestor_ver });
171 std.process.exit(1);
172 }
173
174 // Check that the commit hash is prefixed with a 'g' (a Git convention).
175 if (commit_id.len < 1 or commit_id[0] != 'g') {
176 std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
177 break :v version_string;
178 }
179
180 // The version is reformatted in accordance with the https://semver.org specification.
181 break :v b.fmt("{s}-dev.{s}+{s}", .{ version_string, commit_height, commit_id[1..] });
182 },
183 else => {
184 std.debug.print("Unexpected `git describe` output: {s}\n", .{git_describe});
185 break :v version_string;
186 },
187 }
188 };
189 exe_options.addOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
190
191 if (enable_llvm) {
192 const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
193
194 if (is_stage1) {
195 const softfloat = b.addStaticLibrary("softfloat", null);
196 softfloat.setBuildMode(.ReleaseFast);
197 softfloat.setTarget(target);
198 softfloat.addIncludeDir("deps/SoftFloat-3e-prebuilt");
199 softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
200 softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
201 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
202 softfloat.single_threaded = single_threaded;
203
204 const zig0 = b.addExecutable("zig0", null);
205 zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags);
206 zig0.addIncludeDir("zig-cache/tmp"); // for config.h
207 zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major}));
208 zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor}));
209 zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch}));
210 zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version}));
211
212 for ([_]*std.build.LibExeObjStep{ zig0, exe }) |artifact| {
213 artifact.addIncludeDir("src");
214 artifact.addIncludeDir("deps/SoftFloat-3e/source/include");
215 artifact.addIncludeDir("deps/SoftFloat-3e-prebuilt");
216
217 artifact.defineCMacro("ZIG_LINK_MODE", "Static");
218
219 artifact.addCSourceFiles(&stage1_sources, &exe_cflags);
220 artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
221
222 artifact.linkLibrary(softfloat);
223 artifact.linkLibCpp();
224 }
225
226 try addStaticLlvmOptionsToExe(zig0);
227
228 const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch());
229 const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) });
230 const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" });
231
232 const zig1_obj = zig0.run();
233 zig1_obj.addArgs(&.{
234 "src/stage1.zig",
235 "-target",
236 try target.zigTriple(b.allocator),
237 "-mcpu=baseline",
238 "--name",
239 "zig1",
240 "--zig-lib-dir",
241 b.pathFromRoot("lib"),
242 b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}),
243 "-fcompiler-rt",
244 "-lc",
245 });
246 {
247 zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" });
248 zig1_obj.addFileSourceArg(exe_options.getSource());
249 zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" });
250 }
251 switch (mode) {
252 .Debug => {},
253 .ReleaseFast => {
254 zig1_obj.addArg("-OReleaseFast");
255 zig1_obj.addArg("--strip");
256 },
257 .ReleaseSafe => {
258 zig1_obj.addArg("-OReleaseSafe");
259 zig1_obj.addArg("--strip");
260 },
261 .ReleaseSmall => {
262 zig1_obj.addArg("-OReleaseSmall");
263 zig1_obj.addArg("--strip");
264 },
265 }
266 if (single_threaded orelse false) {
267 zig1_obj.addArg("-fsingle-threaded");
268 }
269
270 exe.step.dependOn(&zig1_obj.step);
271 exe.addObjectFile(zig1_obj_path);
272
273 // This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
274 // of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
275 // is pointless.
276 exe.addPackagePath("compiler_rt", "src/empty.zig");
277 }
278 if (cmake_cfg) |cfg| {
279 // Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
280 // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
281 // the information passed on to us from cmake.
282 if (cfg.cmake_prefix_path.len > 0) {
283 b.addSearchPrefix(cfg.cmake_prefix_path);
284 }
285
286 try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
287 } else {
288 // Here we are -Denable-llvm but no cmake integration.
289 try addStaticLlvmOptionsToExe(exe);
290 }
291 }
292
293 const semver = try std.SemanticVersion.parse(version);
294 exe_options.addOption(std.SemanticVersion, "semver", semver);
295
296 exe_options.addOption(bool, "enable_logging", enable_logging);
297 exe_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
298 exe_options.addOption(bool, "enable_tracy", tracy != null);
299 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
300 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
301 exe_options.addOption(bool, "value_tracing", value_tracing);
302 exe_options.addOption(bool, "is_stage1", is_stage1);
303 exe_options.addOption(bool, "omit_stage2", omit_stage2);
304 if (tracy) |tracy_path| {
305 const client_cpp = fs.path.join(
306 b.allocator,
307 &[_][]const u8{ tracy_path, "TracyClient.cpp" },
308 ) catch unreachable;
309
310 // On mingw, we need to opt into windows 7+ to get some features required by tracy.
311 const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
312 &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
313 else
314 &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
315
316 exe.addIncludeDir(tracy_path);
317 exe.addCSourceFile(client_cpp, tracy_c_flags);
318 if (!enable_llvm) {
319 exe.linkSystemLibraryName("c++");
320 }
321 exe.linkLibC();
322
323 if (target.isWindows()) {
324 exe.linkSystemLibrary("dbghelp");
325 exe.linkSystemLibrary("ws2_32");
326 }
327 }
328}
329
330const exe_cflags = [_][]const u8{
331 "-std=c++14",
332 "-D__STDC_CONSTANT_MACROS",
333 "-D__STDC_FORMAT_MACROS",
334 "-D__STDC_LIMIT_MACROS",
335 "-D_GNU_SOURCE",
336 "-fvisibility-inlines-hidden",
337 "-fno-exceptions",
338 "-fno-rtti",
339 "-Werror=type-limits",
340 "-Wno-missing-braces",
341 "-Wno-comment",
342};
343
344fn addCmakeCfgOptionsToExe(
345 b: *Builder,
346 cfg: CMakeConfig,
347 exe: *std.build.LibExeObjStep,
348 use_zig_libcxx: bool,
349) !void {
350 exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
351 cfg.cmake_binary_dir,
352 "zigcpp",
353 b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
354 }) catch unreachable);
355 assert(cfg.lld_include_dir.len != 0);
356 exe.addIncludeDir(cfg.lld_include_dir);
357 addCMakeLibraryList(exe, cfg.clang_libraries);
358 addCMakeLibraryList(exe, cfg.lld_libraries);
359 addCMakeLibraryList(exe, cfg.llvm_libraries);
360
361 if (use_zig_libcxx) {
362 exe.linkLibCpp();
363 } else {
364 const need_cpp_includes = true;
365
366 // System -lc++ must be used because in this code path we are attempting to link
367 // against system-provided LLVM, Clang, LLD.
368 if (exe.target.getOsTag() == .linux) {
369 // First we try to static link against gcc libstdc++. If that doesn't work,
370 // we fall back to -lc++ and cross our fingers.
371 addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
372 error.RequiredLibraryNotFound => {
373 exe.linkSystemLibrary("c++");
374 },
375 else => |e| return e,
376 };
377 exe.linkSystemLibrary("unwind");
378 } else if (exe.target.isFreeBSD()) {
379 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
380 exe.linkSystemLibrary("pthread");
381 } else if (exe.target.getOsTag() == .openbsd) {
382 try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
383 try addCxxKnownPath(b, cfg, exe, "libc++abi.a", null, need_cpp_includes);
384 } else if (exe.target.isDarwin()) {
385 exe.linkSystemLibrary("c++");
386 }
387 }
388
389 if (cfg.dia_guids_lib.len != 0) {
390 exe.addObjectFile(cfg.dia_guids_lib);
391 }
392}
393
394fn addStaticLlvmOptionsToExe(
395 exe: *std.build.LibExeObjStep,
396) !void {
397 // Adds the Zig C++ sources which both stage1 and stage2 need.
398 //
399 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
400 // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
401 // unavailable when LLVM is compiled in Release mode.
402 const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
403 exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
404
405 for (clang_libs) |lib_name| {
406 exe.linkSystemLibrary(lib_name);
407 }
408
409 for (lld_libs) |lib_name| {
410 exe.linkSystemLibrary(lib_name);
411 }
412
413 for (llvm_libs) |lib_name| {
414 exe.linkSystemLibrary(lib_name);
415 }
416
417 exe.linkSystemLibrary("z");
418
419 // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
420 exe.linkSystemLibrary("c++");
421
422 if (exe.target.getOs().tag == .windows) {
423 exe.linkSystemLibrary("version");
424 exe.linkSystemLibrary("uuid");
425 exe.linkSystemLibrary("ole32");
426 }
427}
428
429fn addCxxKnownPath(
430 b: *Builder,
431 ctx: CMakeConfig,
432 exe: *std.build.LibExeObjStep,
433 objname: []const u8,
434 errtxt: ?[]const u8,
435 need_cpp_includes: bool,
436) !void {
437 const path_padded = try b.exec(&[_][]const u8{
438 ctx.cxx_compiler,
439 b.fmt("-print-file-name={s}", .{objname}),
440 });
441 const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;
442 if (mem.eql(u8, path_unpadded, objname)) {
443 if (errtxt) |msg| {
444 std.debug.print("{s}", .{msg});
445 } else {
446 std.debug.print("Unable to determine path to {s}\n", .{objname});
447 }
448 return error.RequiredLibraryNotFound;
449 }
450 exe.addObjectFile(path_unpadded);
451
452 // TODO a way to integrate with system c++ include files here
453 // cc -E -Wp,-v -xc++ /dev/null
454 if (need_cpp_includes) {
455 // I used these temporarily for testing something but we obviously need a
456 // more general purpose solution here.
457 //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0");
458 //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/x86_64-unknown-linux-gnu");
459 //exe.addIncludeDir("/nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/../../../../include/c++/9.3.0/backward");
460 }
461}
462
463fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
464 var it = mem.tokenize(u8, list, ";");
465 while (it.next()) |lib| {
466 if (mem.startsWith(u8, lib, "-l")) {
467 exe.linkSystemLibrary(lib["-l".len..]);
468 } else {
469 exe.addObjectFile(lib);
470 }
471 }
472}
473
474const CMakeConfig = struct {
475 cmake_binary_dir: []const u8,
476 cmake_prefix_path: []const u8,
477 cxx_compiler: []const u8,
478 lld_include_dir: []const u8,
479 lld_libraries: []const u8,
480 clang_libraries: []const u8,
481 llvm_libraries: []const u8,
482 dia_guids_lib: []const u8,
483};
484
485const max_config_h_bytes = 1 * 1024 * 1024;
486
487fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeConfig {
488 const config_h_text: []const u8 = if (config_h_path_option) |config_h_path| blk: {
489 break :blk fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
490 } else blk: {
491 // TODO this should stop looking for config.h once it detects we hit the
492 // zig source root directory.
493 var check_dir = fs.path.dirname(b.zig_exe).?;
494 while (true) {
495 var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
496 defer dir.close();
497
498 break :blk dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
499 error.FileNotFound => {
500 const new_check_dir = fs.path.dirname(check_dir);
501 if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
502 return null;
503 }
504 check_dir = new_check_dir.?;
505 continue;
506 },
507 else => unreachable,
508 };
509 } else unreachable; // TODO should not need `else unreachable`.
510 };
511
512 var ctx: CMakeConfig = .{
513 .cmake_binary_dir = undefined,
514 .cmake_prefix_path = undefined,
515 .cxx_compiler = undefined,
516 .lld_include_dir = undefined,
517 .lld_libraries = undefined,
518 .clang_libraries = undefined,
519 .llvm_libraries = undefined,
520 .dia_guids_lib = undefined,
521 };
522
523 const mappings = [_]struct { prefix: []const u8, field: []const u8 }{
524 .{
525 .prefix = "#define ZIG_CMAKE_BINARY_DIR ",
526 .field = "cmake_binary_dir",
527 },
528 .{
529 .prefix = "#define ZIG_CMAKE_PREFIX_PATH ",
530 .field = "cmake_prefix_path",
531 },
532 .{
533 .prefix = "#define ZIG_CXX_COMPILER ",
534 .field = "cxx_compiler",
535 },
536 .{
537 .prefix = "#define ZIG_LLD_INCLUDE_PATH ",
538 .field = "lld_include_dir",
539 },
540 .{
541 .prefix = "#define ZIG_LLD_LIBRARIES ",
542 .field = "lld_libraries",
543 },
544 .{
545 .prefix = "#define ZIG_CLANG_LIBRARIES ",
546 .field = "clang_libraries",
547 },
548 .{
549 .prefix = "#define ZIG_LLVM_LIBRARIES ",
550 .field = "llvm_libraries",
551 },
552 .{
553 .prefix = "#define ZIG_DIA_GUIDS_LIB ",
554 .field = "dia_guids_lib",
555 },
556 };
557
558 var lines_it = mem.tokenize(u8, config_h_text, "\r\n");
559 while (lines_it.next()) |line| {
560 inline for (mappings) |mapping| {
561 if (mem.startsWith(u8, line, mapping.prefix)) {
562 var it = mem.split(u8, line, "\"");
563 _ = it.next().?; // skip the stuff before the quote
564 const quoted = it.next().?; // the stuff inside the quote
565 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
566 }
567 }
568 }
569 return ctx;
570}
571
572fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
573 const duplicated = b.allocator.dupe(u8, s) catch unreachable;
574 for (duplicated) |*byte| switch (byte.*) {
575 '/' => byte.* = fs.path.sep,
576 else => {},
577 };
578 return duplicated;
579}
580
581const softfloat_sources = [_][]const u8{
582 "deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c",
583 "deps/SoftFloat-3e/source/8086/extF80M_isSignalingNaN.c",
584 "deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c",
585 "deps/SoftFloat-3e/source/8086/s_commonNaNToExtF80M.c",
586 "deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c",
587 "deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c",
588 "deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c",
589 "deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c",
590 "deps/SoftFloat-3e/source/8086/s_extF80MToCommonNaN.c",
591 "deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c",
592 "deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c",
593 "deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c",
594 "deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c",
595 "deps/SoftFloat-3e/source/8086/s_propagateNaNExtF80M.c",
596 "deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c",
597 "deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c",
598 "deps/SoftFloat-3e/source/f128M_add.c",
599 "deps/SoftFloat-3e/source/f128M_div.c",
600 "deps/SoftFloat-3e/source/f128M_eq.c",
601 "deps/SoftFloat-3e/source/f128M_eq_signaling.c",
602 "deps/SoftFloat-3e/source/f128M_le.c",
603 "deps/SoftFloat-3e/source/f128M_le_quiet.c",
604 "deps/SoftFloat-3e/source/f128M_lt.c",
605 "deps/SoftFloat-3e/source/f128M_lt_quiet.c",
606 "deps/SoftFloat-3e/source/f128M_mul.c",
607 "deps/SoftFloat-3e/source/f128M_mulAdd.c",
608 "deps/SoftFloat-3e/source/f128M_rem.c",
609 "deps/SoftFloat-3e/source/f128M_roundToInt.c",
610 "deps/SoftFloat-3e/source/f128M_sqrt.c",
611 "deps/SoftFloat-3e/source/f128M_sub.c",
612 "deps/SoftFloat-3e/source/f128M_to_f16.c",
613 "deps/SoftFloat-3e/source/f128M_to_f32.c",
614 "deps/SoftFloat-3e/source/f128M_to_f64.c",
615 "deps/SoftFloat-3e/source/f128M_to_extF80M.c",
616 "deps/SoftFloat-3e/source/f128M_to_i32.c",
617 "deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c",
618 "deps/SoftFloat-3e/source/f128M_to_i64.c",
619 "deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c",
620 "deps/SoftFloat-3e/source/f128M_to_ui32.c",
621 "deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c",
622 "deps/SoftFloat-3e/source/f128M_to_ui64.c",
623 "deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c",
624 "deps/SoftFloat-3e/source/extF80M_add.c",
625 "deps/SoftFloat-3e/source/extF80M_div.c",
626 "deps/SoftFloat-3e/source/extF80M_eq.c",
627 "deps/SoftFloat-3e/source/extF80M_le.c",
628 "deps/SoftFloat-3e/source/extF80M_lt.c",
629 "deps/SoftFloat-3e/source/extF80M_mul.c",
630 "deps/SoftFloat-3e/source/extF80M_rem.c",
631 "deps/SoftFloat-3e/source/extF80M_roundToInt.c",
632 "deps/SoftFloat-3e/source/extF80M_sqrt.c",
633 "deps/SoftFloat-3e/source/extF80M_sub.c",
634 "deps/SoftFloat-3e/source/extF80M_to_f16.c",
635 "deps/SoftFloat-3e/source/extF80M_to_f32.c",
636 "deps/SoftFloat-3e/source/extF80M_to_f64.c",
637 "deps/SoftFloat-3e/source/extF80M_to_f128M.c",
638 "deps/SoftFloat-3e/source/f16_add.c",
639 "deps/SoftFloat-3e/source/f16_div.c",
640 "deps/SoftFloat-3e/source/f16_eq.c",
641 "deps/SoftFloat-3e/source/f16_isSignalingNaN.c",
642 "deps/SoftFloat-3e/source/f16_lt.c",
643 "deps/SoftFloat-3e/source/f16_mul.c",
644 "deps/SoftFloat-3e/source/f16_mulAdd.c",
645 "deps/SoftFloat-3e/source/f16_rem.c",
646 "deps/SoftFloat-3e/source/f16_roundToInt.c",
647 "deps/SoftFloat-3e/source/f16_sqrt.c",
648 "deps/SoftFloat-3e/source/f16_sub.c",
649 "deps/SoftFloat-3e/source/f16_to_extF80M.c",
650 "deps/SoftFloat-3e/source/f16_to_f128M.c",
651 "deps/SoftFloat-3e/source/f16_to_f64.c",
652 "deps/SoftFloat-3e/source/f32_to_extF80M.c",
653 "deps/SoftFloat-3e/source/f32_to_f128M.c",
654 "deps/SoftFloat-3e/source/f64_to_extF80M.c",
655 "deps/SoftFloat-3e/source/f64_to_f128M.c",
656 "deps/SoftFloat-3e/source/f64_to_f16.c",
657 "deps/SoftFloat-3e/source/i32_to_f128M.c",
658 "deps/SoftFloat-3e/source/s_add256M.c",
659 "deps/SoftFloat-3e/source/s_addCarryM.c",
660 "deps/SoftFloat-3e/source/s_addComplCarryM.c",
661 "deps/SoftFloat-3e/source/s_addF128M.c",
662 "deps/SoftFloat-3e/source/s_addExtF80M.c",
663 "deps/SoftFloat-3e/source/s_addM.c",
664 "deps/SoftFloat-3e/source/s_addMagsF16.c",
665 "deps/SoftFloat-3e/source/s_addMagsF32.c",
666 "deps/SoftFloat-3e/source/s_addMagsF64.c",
667 "deps/SoftFloat-3e/source/s_approxRecip32_1.c",
668 "deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c",
669 "deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c",
670 "deps/SoftFloat-3e/source/s_approxRecip_1Ks.c",
671 "deps/SoftFloat-3e/source/s_compare128M.c",
672 "deps/SoftFloat-3e/source/s_compare96M.c",
673 "deps/SoftFloat-3e/source/s_compareNonnormExtF80M.c",
674 "deps/SoftFloat-3e/source/s_countLeadingZeros16.c",
675 "deps/SoftFloat-3e/source/s_countLeadingZeros32.c",
676 "deps/SoftFloat-3e/source/s_countLeadingZeros64.c",
677 "deps/SoftFloat-3e/source/s_countLeadingZeros8.c",
678 "deps/SoftFloat-3e/source/s_eq128.c",
679 "deps/SoftFloat-3e/source/s_invalidF128M.c",
680 "deps/SoftFloat-3e/source/s_invalidExtF80M.c",
681 "deps/SoftFloat-3e/source/s_isNaNF128M.c",
682 "deps/SoftFloat-3e/source/s_le128.c",
683 "deps/SoftFloat-3e/source/s_lt128.c",
684 "deps/SoftFloat-3e/source/s_mul128MTo256M.c",
685 "deps/SoftFloat-3e/source/s_mul64To128M.c",
686 "deps/SoftFloat-3e/source/s_mulAddF128M.c",
687 "deps/SoftFloat-3e/source/s_mulAddF16.c",
688 "deps/SoftFloat-3e/source/s_mulAddF32.c",
689 "deps/SoftFloat-3e/source/s_mulAddF64.c",
690 "deps/SoftFloat-3e/source/s_negXM.c",
691 "deps/SoftFloat-3e/source/s_normExtF80SigM.c",
692 "deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c",
693 "deps/SoftFloat-3e/source/s_normRoundPackMToExtF80M.c",
694 "deps/SoftFloat-3e/source/s_normRoundPackToF16.c",
695 "deps/SoftFloat-3e/source/s_normRoundPackToF32.c",
696 "deps/SoftFloat-3e/source/s_normRoundPackToF64.c",
697 "deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c",
698 "deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c",
699 "deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c",
700 "deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c",
701 "deps/SoftFloat-3e/source/s_remStepMBy32.c",
702 "deps/SoftFloat-3e/source/s_roundMToI64.c",
703 "deps/SoftFloat-3e/source/s_roundMToUI64.c",
704 "deps/SoftFloat-3e/source/s_roundPackMToExtF80M.c",
705 "deps/SoftFloat-3e/source/s_roundPackMToF128M.c",
706 "deps/SoftFloat-3e/source/s_roundPackToF16.c",
707 "deps/SoftFloat-3e/source/s_roundPackToF32.c",
708 "deps/SoftFloat-3e/source/s_roundPackToF64.c",
709 "deps/SoftFloat-3e/source/s_roundToI32.c",
710 "deps/SoftFloat-3e/source/s_roundToI64.c",
711 "deps/SoftFloat-3e/source/s_roundToUI32.c",
712 "deps/SoftFloat-3e/source/s_roundToUI64.c",
713 "deps/SoftFloat-3e/source/s_shiftLeftM.c",
714 "deps/SoftFloat-3e/source/s_shiftNormSigF128M.c",
715 "deps/SoftFloat-3e/source/s_shiftRightJam256M.c",
716 "deps/SoftFloat-3e/source/s_shiftRightJam32.c",
717 "deps/SoftFloat-3e/source/s_shiftRightJam64.c",
718 "deps/SoftFloat-3e/source/s_shiftRightJamM.c",
719 "deps/SoftFloat-3e/source/s_shiftRightM.c",
720 "deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c",
721 "deps/SoftFloat-3e/source/s_shortShiftLeftM.c",
722 "deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c",
723 "deps/SoftFloat-3e/source/s_shortShiftRightJam64.c",
724 "deps/SoftFloat-3e/source/s_shortShiftRightJamM.c",
725 "deps/SoftFloat-3e/source/s_shortShiftRightM.c",
726 "deps/SoftFloat-3e/source/s_sub1XM.c",
727 "deps/SoftFloat-3e/source/s_sub256M.c",
728 "deps/SoftFloat-3e/source/s_subM.c",
729 "deps/SoftFloat-3e/source/s_subMagsF16.c",
730 "deps/SoftFloat-3e/source/s_subMagsF32.c",
731 "deps/SoftFloat-3e/source/s_subMagsF64.c",
732 "deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c",
733 "deps/SoftFloat-3e/source/s_tryPropagateNaNExtF80M.c",
734 "deps/SoftFloat-3e/source/softfloat_state.c",
735 "deps/SoftFloat-3e/source/ui32_to_f128M.c",
736 "deps/SoftFloat-3e/source/ui64_to_f128M.c",
737 "deps/SoftFloat-3e/source/ui32_to_extF80M.c",
738 "deps/SoftFloat-3e/source/ui64_to_extF80M.c",
739};
740
741const stage1_sources = [_][]const u8{
742 "src/stage1/analyze.cpp",
743 "src/stage1/astgen.cpp",
744 "src/stage1/bigfloat.cpp",
745 "src/stage1/bigint.cpp",
746 "src/stage1/buffer.cpp",
747 "src/stage1/codegen.cpp",
748 "src/stage1/errmsg.cpp",
749 "src/stage1/error.cpp",
750 "src/stage1/heap.cpp",
751 "src/stage1/ir.cpp",
752 "src/stage1/ir_print.cpp",
753 "src/stage1/mem.cpp",
754 "src/stage1/os.cpp",
755 "src/stage1/parser.cpp",
756 "src/stage1/range_set.cpp",
757 "src/stage1/stage1.cpp",
758 "src/stage1/target.cpp",
759 "src/stage1/tokenizer.cpp",
760 "src/stage1/util.cpp",
761 "src/stage1/softfloat_ext.cpp",
762};
763const optimized_c_sources = [_][]const u8{
764 "src/stage1/parse_f128.c",
765};
766const zig_cpp_sources = [_][]const u8{
767 // These are planned to stay even when we are self-hosted.
768 "src/zig_llvm.cpp",
769 "src/zig_clang.cpp",
770 "src/zig_llvm-ar.cpp",
771 "src/zig_clang_driver.cpp",
772 "src/zig_clang_cc1_main.cpp",
773 "src/zig_clang_cc1as_main.cpp",
774 // https://github.com/ziglang/zig/issues/6363
775 "src/windows_sdk.cpp",
776};
777
778const clang_libs = [_][]const u8{
779 "clangFrontendTool",
780 "clangCodeGen",
781 "clangFrontend",
782 "clangDriver",
783 "clangSerialization",
784 "clangSema",
785 "clangStaticAnalyzerFrontend",
786 "clangStaticAnalyzerCheckers",
787 "clangStaticAnalyzerCore",
788 "clangAnalysis",
789 "clangASTMatchers",
790 "clangAST",
791 "clangParse",
792 "clangSema",
793 "clangBasic",
794 "clangEdit",
795 "clangLex",
796 "clangARCMigrate",
797 "clangRewriteFrontend",
798 "clangRewrite",
799 "clangCrossTU",
800 "clangIndex",
801 "clangToolingCore",
802};
803const lld_libs = [_][]const u8{
804 "lldMinGW",
805 "lldELF",
806 "lldCOFF",
807 "lldWasm",
808 "lldMachO",
809 "lldCommon",
810};
811// This list can be re-generated with `llvm-config --libfiles` and then
812// reformatting using your favorite text editor. Note we do not execute
813// `llvm-config` here because we are cross compiling. Also omit LLVMTableGen
814// from these libs.
815const llvm_libs = [_][]const u8{
816 "LLVMWindowsManifest",
817 "LLVMXRay",
818 "LLVMLibDriver",
819 "LLVMDlltoolDriver",
820 "LLVMCoverage",
821 "LLVMLineEditor",
822 "LLVMXCoreDisassembler",
823 "LLVMXCoreCodeGen",
824 "LLVMXCoreDesc",
825 "LLVMXCoreInfo",
826 "LLVMX86TargetMCA",
827 "LLVMX86Disassembler",
828 "LLVMX86AsmParser",
829 "LLVMX86CodeGen",
830 "LLVMX86Desc",
831 "LLVMX86Info",
832 "LLVMWebAssemblyDisassembler",
833 "LLVMWebAssemblyAsmParser",
834 "LLVMWebAssemblyCodeGen",
835 "LLVMWebAssemblyDesc",
836 "LLVMWebAssemblyUtils",
837 "LLVMWebAssemblyInfo",
838 "LLVMVEDisassembler",
839 "LLVMVEAsmParser",
840 "LLVMVECodeGen",
841 "LLVMVEDesc",
842 "LLVMVEInfo",
843 "LLVMSystemZDisassembler",
844 "LLVMSystemZAsmParser",
845 "LLVMSystemZCodeGen",
846 "LLVMSystemZDesc",
847 "LLVMSystemZInfo",
848 "LLVMSparcDisassembler",
849 "LLVMSparcAsmParser",
850 "LLVMSparcCodeGen",
851 "LLVMSparcDesc",
852 "LLVMSparcInfo",
853 "LLVMRISCVDisassembler",
854 "LLVMRISCVAsmParser",
855 "LLVMRISCVCodeGen",
856 "LLVMRISCVDesc",
857 "LLVMRISCVInfo",
858 "LLVMPowerPCDisassembler",
859 "LLVMPowerPCAsmParser",
860 "LLVMPowerPCCodeGen",
861 "LLVMPowerPCDesc",
862 "LLVMPowerPCInfo",
863 "LLVMNVPTXCodeGen",
864 "LLVMNVPTXDesc",
865 "LLVMNVPTXInfo",
866 "LLVMMSP430Disassembler",
867 "LLVMMSP430AsmParser",
868 "LLVMMSP430CodeGen",
869 "LLVMMSP430Desc",
870 "LLVMMSP430Info",
871 "LLVMMipsDisassembler",
872 "LLVMMipsAsmParser",
873 "LLVMMipsCodeGen",
874 "LLVMMipsDesc",
875 "LLVMMipsInfo",
876 "LLVMLanaiDisassembler",
877 "LLVMLanaiCodeGen",
878 "LLVMLanaiAsmParser",
879 "LLVMLanaiDesc",
880 "LLVMLanaiInfo",
881 "LLVMHexagonDisassembler",
882 "LLVMHexagonCodeGen",
883 "LLVMHexagonAsmParser",
884 "LLVMHexagonDesc",
885 "LLVMHexagonInfo",
886 "LLVMBPFDisassembler",
887 "LLVMBPFAsmParser",
888 "LLVMBPFCodeGen",
889 "LLVMBPFDesc",
890 "LLVMBPFInfo",
891 "LLVMAVRDisassembler",
892 "LLVMAVRAsmParser",
893 "LLVMAVRCodeGen",
894 "LLVMAVRDesc",
895 "LLVMAVRInfo",
896 "LLVMARMDisassembler",
897 "LLVMARMAsmParser",
898 "LLVMARMCodeGen",
899 "LLVMARMDesc",
900 "LLVMARMUtils",
901 "LLVMARMInfo",
902 "LLVMAMDGPUTargetMCA",
903 "LLVMAMDGPUDisassembler",
904 "LLVMAMDGPUAsmParser",
905 "LLVMAMDGPUCodeGen",
906 "LLVMAMDGPUDesc",
907 "LLVMAMDGPUUtils",
908 "LLVMAMDGPUInfo",
909 "LLVMAArch64Disassembler",
910 "LLVMAArch64AsmParser",
911 "LLVMAArch64CodeGen",
912 "LLVMAArch64Desc",
913 "LLVMAArch64Utils",
914 "LLVMAArch64Info",
915 "LLVMOrcJIT",
916 "LLVMMCJIT",
917 "LLVMJITLink",
918 "LLVMInterpreter",
919 "LLVMExecutionEngine",
920 "LLVMRuntimeDyld",
921 "LLVMOrcTargetProcess",
922 "LLVMOrcShared",
923 "LLVMDWP",
924 "LLVMSymbolize",
925 "LLVMDebugInfoPDB",
926 "LLVMDebugInfoGSYM",
927 "LLVMOption",
928 "LLVMObjectYAML",
929 "LLVMMCA",
930 "LLVMMCDisassembler",
931 "LLVMLTO",
932 "LLVMPasses",
933 "LLVMCFGuard",
934 "LLVMCoroutines",
935 "LLVMObjCARCOpts",
936 "LLVMipo",
937 "LLVMVectorize",
938 "LLVMLinker",
939 "LLVMInstrumentation",
940 "LLVMFrontendOpenMP",
941 "LLVMFrontendOpenACC",
942 "LLVMExtensions",
943 "LLVMDWARFLinker",
944 "LLVMGlobalISel",
945 "LLVMMIRParser",
946 "LLVMAsmPrinter",
947 "LLVMDebugInfoMSF",
948 "LLVMSelectionDAG",
949 "LLVMCodeGen",
950 "LLVMIRReader",
951 "LLVMAsmParser",
952 "LLVMInterfaceStub",
953 "LLVMFileCheck",
954 "LLVMFuzzMutate",
955 "LLVMTarget",
956 "LLVMScalarOpts",
957 "LLVMInstCombine",
958 "LLVMAggressiveInstCombine",
959 "LLVMTransformUtils",
960 "LLVMBitWriter",
961 "LLVMAnalysis",
962 "LLVMProfileData",
963 "LLVMDebugInfoDWARF",
964 "LLVMObject",
965 "LLVMTextAPI",
966 "LLVMMCParser",
967 "LLVMMC",
968 "LLVMDebugInfoCodeView",
969 "LLVMBitReader",
970 "LLVMCore",
971 "LLVMRemarks",
972 "LLVMBitstreamReader",
973 "LLVMBinaryFormat",
974 "LLVMSupport",
975 "LLVMDemangle",
976};
ci/azure/macos_script+19-36
...@@ -34,13 +34,11 @@ git fetch --tags...@@ -34,13 +34,11 @@ git fetch --tags
34mkdir build34mkdir build
35cd build35cd build
36cmake .. \36cmake .. \
37 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
38 -DCMAKE_PREFIX_PATH="$PREFIX" \37 -DCMAKE_PREFIX_PATH="$PREFIX" \
39 -DCMAKE_BUILD_TYPE=Release \38 -DCMAKE_BUILD_TYPE=Release \
40 -DZIG_TARGET_TRIPLE="$TARGET" \39 -DZIG_TARGET_TRIPLE="$TARGET" \
41 -DZIG_TARGET_MCPU="$MCPU" \40 -DZIG_TARGET_MCPU="$MCPU" \
42 -DZIG_STATIC=ON \41 -DZIG_STATIC=ON
43 -DZIG_OMIT_STAGE2=ON
4442
45# Now cmake will use zig as the C/C++ compiler. We reset the environment variables43# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46# so that installation and testing do not get affected by them.44# so that installation and testing do not get affected by them.
...@@ -49,45 +47,30 @@ unset CXX...@@ -49,45 +47,30 @@ unset CXX
4947
50make $JOBS install48make $JOBS install
5149
52# Here we rebuild zig but this time using the Zig binary we just now produced to50stage2/bin/zig build \
53# build zig1.o rather than relying on the one built with stage0. See51 --prefix stage3-release \
54# https://github.com/ziglang/zig/issues/6830 for more details.52 --search-prefix "$PREFIX" \
55cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"53 -Dstatic-llvm \
56make $JOBS install54 -Drelease \
55 -Dstrip \
56 -Dtarget="$TARGET" \
57 -Denable-stage1
5758
58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.59stage3-release/bin/zig build test docs \
59release/bin/zig build -p stage2 -Denable-llvm60 -Denable-macos-sdk \
6061 -Dstatic-llvm \
61stage2/bin/zig build test-behavior62 --search-prefix "$PREFIX"
62
63# TODO: upgrade these to test stage2 instead of stage1
64# TODO: upgrade these to test stage3 instead of stage2
65release/bin/zig build test-behavior -Denable-macos-sdk -Domit-stage2
66release/bin/zig build test-compiler-rt -Denable-macos-sdk
67release/bin/zig build test-std -Denable-macos-sdk
68release/bin/zig build test-universal-libc -Denable-macos-sdk
69release/bin/zig build test-compare-output -Denable-macos-sdk
70release/bin/zig build test-standalone -Denable-macos-sdk
71release/bin/zig build test-stack-traces -Denable-macos-sdk
72release/bin/zig build test-cli -Denable-macos-sdk
73release/bin/zig build test-asm-link -Denable-macos-sdk
74release/bin/zig build test-translate-c -Denable-macos-sdk
75release/bin/zig build test-run-translated-c -Denable-macos-sdk
76release/bin/zig build docs -Denable-macos-sdk
77release/bin/zig build test-fmt -Denable-macos-sdk
78release/bin/zig build test-cases -Denable-macos-sdk -Dsingle-threaded
79release/bin/zig build test-link -Denable-macos-sdk -Domit-stage2
8063
81if [ "${BUILD_REASON}" != "PullRequest" ]; then64if [ "${BUILD_REASON}" != "PullRequest" ]; then
82 mv ../LICENSE release/65 mv ../LICENSE stage3-release/
83 mv ../zig-cache/langref.html release/66 mv ../zig-cache/langref.html stage3-release/
84 mv release/bin/zig release/67 mv stage3-release/bin/zig stage3-release/
85 rmdir release/bin68 rmdir stage3-release/bin
8669
87 VERSION=$(release/zig version)70 VERSION=$(stage3-release/zig version)
88 DIRNAME="zig-macos-$ARCH-$VERSION"71 DIRNAME="zig-macos-$ARCH-$VERSION"
89 TARBALL="$DIRNAME.tar.xz"72 TARBALL="$DIRNAME.tar.xz"
90 mv release "$DIRNAME"73 mv stage3-release "$DIRNAME"
91 tar cfJ "$TARBALL" "$DIRNAME"74 tar cfJ "$TARBALL" "$DIRNAME"
9275
93 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"76 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
ci/azure/pipelines.yml+21-60
...@@ -27,7 +27,7 @@ jobs:...@@ -27,7 +27,7 @@ jobs:
27 vmImage: 'windows-2019'27 vmImage: 'windows-2019'
28 variables:28 variables:
29 TARGET: 'x86_64-windows-gnu'29 TARGET: 'x86_64-windows-gnu'
30 ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3524+74673b7f6'30 ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.3653+7152a58c1'
31 ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'31 ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'
32 steps:32 steps:
33 - pwsh: |33 - pwsh: |
...@@ -37,8 +37,8 @@ jobs:...@@ -37,8 +37,8 @@ jobs:
37 displayName: 'Install ZIG/LLVM/CLANG/LLD'37 displayName: 'Install ZIG/LLVM/CLANG/LLD'
3838
39 - pwsh: |39 - pwsh: |
40 Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"40 Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
41 Set-Variable -Name ZIGINSTALLDIR -Value "${ZIGBUILDDIR}\dist"41 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
42 Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"42 Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"
4343
44 function CheckLastExitCode {44 function CheckLastExitCode {
...@@ -56,40 +56,22 @@ jobs:...@@ -56,40 +56,22 @@ jobs:
56 git fetch --unshallow # `git describe` won't work on a shallow repo56 git fetch --unshallow # `git describe` won't work on a shallow repo
57 }57 }
5858
59 # The dev kit zip file that we have here is old, and may be incompatible with59 & "$ZIGPREFIXPATH\bin\zig.exe" build `
60 # the build.zig script of master branch. So we keep an old version of build.zig
61 # here in the CI directory.
62 mv build.zig build.zig.master
63 mv ci/azure/build.zig build.zig
64
65 mkdir $ZIGBUILDDIR
66 cd $ZIGBUILDDIR
67
68 & "${ZIGPREFIXPATH}/bin/zig.exe" build `
69 --prefix "$ZIGINSTALLDIR" `60 --prefix "$ZIGINSTALLDIR" `
70 --search-prefix "$ZIGPREFIXPATH" `61 --search-prefix "$ZIGPREFIXPATH" `
71 -Dstage1 `62 --zig-lib-dir "$ZIGLIBDIR" `
72 <# stage2 is omitted until we resolve https://github.com/ziglang/zig/issues/6485 #> `63 -Denable-stage1 `
73 -Domit-stage2 `
74 -Dstatic-llvm `64 -Dstatic-llvm `
75 -Drelease `65 -Drelease `
76 -Dstrip `66 -Dstrip `
77 -Duse-zig-libcxx `67 -Duse-zig-libcxx `
78 -Dtarget=$(TARGET)68 -Dtarget=$(TARGET)
79 CheckLastExitCode69 CheckLastExitCode
80
81 cd -
82
83 # Now that we have built an up-to-date zig.exe, we restore the original
84 # build script from master branch.
85 rm build.zig
86 mv build.zig.master build.zig
87
88 name: build70 name: build
89 displayName: 'Build'71 displayName: 'Build'
9072
91 - pwsh: |73 - pwsh: |
92 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist"74 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
9375
94 function CheckLastExitCode {76 function CheckLastExitCode {
95 if (!$?) {77 if (!$?) {
...@@ -98,41 +80,21 @@ jobs:...@@ -98,41 +80,21 @@ jobs:
98 return 080 return 0
99 }81 }
10082
101 # Sadly, stage2 is omitted from this build to save memory on the CI server. Once self-hosted is83 & "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
102 # built with itself and does not gobble as much memory, we can enable these tests.84 --search-prefix "$ZIGPREFIXPATH" `
103 #& "$ZIGINSTALLDIR\bin\zig.exe" test "..\test\behavior.zig" -fno-stage1 -fLLVM -I "..\test" 2>&185 -Dstatic-llvm `
104 #CheckLastExitCode86 -Dskip-non-native `
10587 -Dskip-stage2-tests
106 & "$ZIGINSTALLDIR\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests -Domit-stage2 2>&1
107 CheckLastExitCode
108 & "$ZIGINSTALLDIR\bin\zig.exe" build test-std -Dskip-non-native 2>&1
109 CheckLastExitCode88 CheckLastExitCode
110 name: test89 name: test
111 displayName: 'Test'90 displayName: 'Test'
11291
113 - pwsh: |
114 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist"
115
116 function CheckLastExitCode {
117 if (!$?) {
118 exit 1
119 }
120 return 0
121 }
122
123 & "$ZIGINSTALLDIR\bin\zig.exe" build docs
124 CheckLastExitCode
125 timeoutInMinutes: 60
126 name: doc
127 displayName: 'Documentation'
128
129 - task: DownloadSecureFile@192 - task: DownloadSecureFile@1
130 inputs:93 inputs:
131 name: aws_credentials94 name: aws_credentials
132 secureFile: aws_credentials95 secureFile: aws_credentials
13396
134 - pwsh: |97 - pwsh: |
135 Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"
136 $Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH"98 $Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH"
13799
138 # Workaround Azure networking issue100 # Workaround Azure networking issue
...@@ -140,21 +102,20 @@ jobs:...@@ -140,21 +102,20 @@ jobs:
140 $Env:AWS_EC2_METADATA_DISABLED = "true"102 $Env:AWS_EC2_METADATA_DISABLED = "true"
141 $Env:AWS_REGION = "us-west-2"103 $Env:AWS_REGION = "us-west-2"
142104
143 cd "$ZIGBUILDDIR"105 mv LICENSE stage3-release/
144 mv ../LICENSE dist/106 mv zig-cache/langref.html stage3-release/
145 mv ../zig-cache/langref.html dist/107 mv stage3-release/bin/zig.exe stage3-release/
146 mv dist/bin/zig.exe dist/108 rmdir stage3-release/bin
147 rmdir dist/bin
148109
149 # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig110 # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
150 mv dist/lib/zig dist/lib2111 mv stage3-release/lib/zig stage3-release/lib2
151 rmdir dist/lib112 rmdir stage3-release/lib
152 mv dist/lib2 dist/lib113 mv stage3-release/lib2 stage3-release/lib
153114
154 Set-Variable -Name VERSION -Value $(./dist/zig.exe version)115 Set-Variable -Name VERSION -Value $(./stage3-release/zig.exe version)
155 Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION"116 Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION"
156 Set-Variable -Name TARBALL -Value "$DIRNAME.zip"117 Set-Variable -Name TARBALL -Value "$DIRNAME.zip"
157 mv dist "$DIRNAME"118 mv stage3-release "$DIRNAME"
158 7z a "$TARBALL" "$DIRNAME"119 7z a "$TARBALL" "$DIRNAME"
159120
160 aws s3 cp `121 aws s3 cp `
ci/drone/drone.yml+21-21
...@@ -13,65 +13,65 @@ steps:...@@ -13,65 +13,65 @@ steps:
13 commands:13 commands:
14 - ./ci/drone/linux_script_build14 - ./ci/drone/linux_script_build
1515
16- name: test-116- name: behavior
17 depends_on:17 depends_on:
18 - build18 - build
19 image: ziglang/static-base:llvm14-aarch64-319 image: ziglang/static-base:llvm14-aarch64-3
20 commands:20 commands:
21 - ./ci/drone/linux_script_test 121 - ./ci/drone/test_linux_behavior
2222
23- name: test-223- name: std_Debug
24 depends_on:24 depends_on:
25 - build25 - build
26 image: ziglang/static-base:llvm14-aarch64-326 image: ziglang/static-base:llvm14-aarch64-3
27 commands:27 commands:
28 - ./ci/drone/linux_script_test 228 - ./ci/drone/test_linux_std_Debug
2929
30- name: test-330- name: std_ReleaseSafe
31 depends_on:31 depends_on:
32 - build32 - build
33 image: ziglang/static-base:llvm14-aarch64-333 image: ziglang/static-base:llvm14-aarch64-3
34 commands:34 commands:
35 - ./ci/drone/linux_script_test 335 - ./ci/drone/test_linux_std_ReleaseSafe
3636
37- name: test-437- name: std_ReleaseFast
38 depends_on:38 depends_on:
39 - build39 - build
40 image: ziglang/static-base:llvm14-aarch64-340 image: ziglang/static-base:llvm14-aarch64-3
41 commands:41 commands:
42 - ./ci/drone/linux_script_test 442 - ./ci/drone/test_linux_std_ReleaseFast
4343
44- name: test-544- name: std_ReleaseSmall
45 depends_on:45 depends_on:
46 - build46 - build
47 image: ziglang/static-base:llvm14-aarch64-347 image: ziglang/static-base:llvm14-aarch64-3
48 commands:48 commands:
49 - ./ci/drone/linux_script_test 549 - ./ci/drone/test_linux_std_ReleaseSmall
5050
51- name: test-651- name: misc
52 depends_on:52 depends_on:
53 - build53 - build
54 image: ziglang/static-base:llvm14-aarch64-354 image: ziglang/static-base:llvm14-aarch64-3
55 commands:55 commands:
56 - ./ci/drone/linux_script_test 656 - ./ci/drone/test_linux_misc
5757
58- name: test-758- name: cases
59 depends_on:59 depends_on:
60 - build60 - build
61 image: ziglang/static-base:llvm14-aarch64-361 image: ziglang/static-base:llvm14-aarch64-3
62 commands:62 commands:
63 - ./ci/drone/linux_script_test 763 - ./ci/drone/test_linux_cases
6464
65- name: finalize65- name: finalize
66 depends_on:66 depends_on:
67 - build67 - build
68 - test-168 - behavior
69 - test-269 - std_Debug
70 - test-370 - std_ReleaseSafe
71 - test-471 - std_ReleaseFast
72 - test-572 - std_ReleaseSmall
73 - test-673 - misc
74 - test-774 - cases
75 image: ziglang/static-base:llvm14-aarch64-375 image: ziglang/static-base:llvm14-aarch64-3
76 environment:76 environment:
77 SRHT_OAUTH_TOKEN:77 SRHT_OAUTH_TOKEN:
ci/drone/linux_script_build+8-6
...@@ -42,7 +42,6 @@ git fetch --tags...@@ -42,7 +42,6 @@ git fetch --tags
42mkdir build42mkdir build
43cd build43cd build
44cmake .. \44cmake .. \
45 -DCMAKE_INSTALL_PREFIX="$DISTDIR" \
46 -DCMAKE_PREFIX_PATH="$PREFIX" \45 -DCMAKE_PREFIX_PATH="$PREFIX" \
47 -DCMAKE_BUILD_TYPE=Release \46 -DCMAKE_BUILD_TYPE=Release \
48 -DCMAKE_AR="$PREFIX/bin/ar" \47 -DCMAKE_AR="$PREFIX/bin/ar" \
...@@ -58,8 +57,11 @@ unset CC...@@ -58,8 +57,11 @@ unset CC
58unset CXX57unset CXX
59samu install58samu install
6059
61# Here we rebuild Zig but this time using the Zig binary we just now produced to60stage2/bin/zig build \
62# build zig1.o rather than relying on the one built with stage0. See61 --prefix "$DISTDIR" \
63# https://github.com/ziglang/zig/issues/6830 for more details.62 --search-prefix "$PREFIX" \
64cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"63 -Dstatic-llvm \
65samu install64 -Drelease \
65 -Dstrip \
66 -Dtarget="$TARGET" \
67 -Denable-stage1
ci/drone/linux_script_test deleted-51
...@@ -1,51 +0,0 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5BUILD_FLAGS="-Dskip-non-native"
6
7case "$1" in
8 1)
9 ./build/zig build $BUILD_FLAGS test-behavior
10 ./build/zig build $BUILD_FLAGS test-compiler-rt
11 ./build/zig build $BUILD_FLAGS test-fmt
12 ./build/zig build $BUILD_FLAGS docs
13 ;;
14 2)
15 # Debug
16 ./build/zig build $BUILD_FLAGS test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small
17 ;;
18 3)
19 # ReleaseSafe
20 ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
21 ;;
22 4)
23 # ReleaseFast
24 ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
25 ;;
26 5)
27 # ReleaseSmall
28 ./build/zig build $BUILD_FLAGS test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast
29 ;;
30 6)
31 ./build/zig build $BUILD_FLAGS test-universal-libc
32 ./build/zig build $BUILD_FLAGS test-compare-output
33 ./build/zig build $BUILD_FLAGS test-standalone -Dskip-release-safe
34 ./build/zig build $BUILD_FLAGS test-stack-traces
35 ./build/zig build $BUILD_FLAGS test-cli
36 ./build/zig build $BUILD_FLAGS test-asm-link
37 ./build/zig build $BUILD_FLAGS test-translate-c
38 ;;
39 7)
40 ./build/zig build $BUILD_FLAGS # test building self-hosted without LLVM
41 ./build/zig build $BUILD_FLAGS test-cases
42 ;;
43 '')
44 echo "error: expecting test group argument"
45 exit 1
46 ;;
47 *)
48 echo "error: unknown test group: $1"
49 exit 1
50 ;;
51esac
ci/drone/test_linux_behavior created+8
...@@ -0,0 +1,8 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-behavior -Dskip-non-native
6./build/zig build test-compiler-rt -Dskip-non-native
7./build/zig build test-fmt
8./build/zig build docs
ci/drone/test_linux_cases created+6
...@@ -0,0 +1,6 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build -Dskip-non-native # test building self-hosted without LLVM
6./build/zig build -Dskip-non-native test-cases
ci/drone/test_linux_misc created+11
...@@ -0,0 +1,11 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-universal-libc -Dskip-non-native
6./build/zig build test-compare-output -Dskip-non-native
7./build/zig build test-standalone -Dskip-non-native -Dskip-release-safe
8./build/zig build test-stack-traces -Dskip-non-native
9./build/zig build test-cli -Dskip-non-native
10./build/zig build test-asm-link -Dskip-non-native
11./build/zig build test-translate-c -Dskip-non-native
ci/drone/test_linux_std_Debug created+5
...@@ -0,0 +1,5 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-std -Dskip-release-safe -Dskip-release-fast -Dskip-release-small -Dskip-non-native
ci/drone/test_linux_std_ReleaseFast created+5
...@@ -0,0 +1,5 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
ci/drone/test_linux_std_ReleaseSafe created+5
...@@ -0,0 +1,5 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-std -Dskip-debug -Dskip-release-fast -Dskip-release-small -Dskip-non-native -Dskip-single-threaded
ci/drone/test_linux_std_ReleaseSmall created+5
...@@ -0,0 +1,5 @@
1#!/bin/sh
2
3. ./ci/drone/linux_script_base
4
5./build/zig build test-std -Dskip-debug -Dskip-release-safe -Dskip-release-fast -Dskip-non-native
ci/srht/freebsd_script+33-18
...@@ -7,7 +7,9 @@ sudo pkg update -fq...@@ -7,7 +7,9 @@ sudo pkg update -fq
7sudo pkg install -y cmake py39-s3cmd wget curl jq samurai7sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
88
9ZIGDIR="$(pwd)"9ZIGDIR="$(pwd)"
10CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.10.0-dev.2931+bdf3fa12f"10TARGET="x86_64-freebsd-gnu"
11MCPU="baseline"
12CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.3524+74673b7f6"
11PREFIX="$HOME/$CACHE_BASENAME"13PREFIX="$HOME/$CACHE_BASENAME"
1214
13cd $HOME15cd $HOME
...@@ -30,33 +32,46 @@ export TERM=dumb...@@ -30,33 +32,46 @@ export TERM=dumb
30mkdir build32mkdir build
31cd build33cd build
32cmake .. \34cmake .. \
33 -DCMAKE_BUILD_TYPE=Release \35 -DCMAKE_BUILD_TYPE=Release \
34 -DCMAKE_PREFIX_PATH=$PREFIX \36 -DCMAKE_PREFIX_PATH=$PREFIX \
35 "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \37 -DZIG_TARGET_TRIPLE="$TARGET" \
36 -DZIG_STATIC=ON \38 -DZIG_TARGET_MCPU="$MCPU" \
37 -DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \39 -DZIG_STATIC=ON \
38 -GNinja40 -GNinja
39samu install41samu install
4042
41# TODO ld.lld: error: undefined symbol: main43# TODO: eliminate this workaround. Without this, zig does not end up passing
42# >>> referenced by crt1_c.c:75 (/usr/src/lib/csu/amd64/crt1_c.c:75)44# -isystem /usr/include when building libc++, resulting in #include <sys/endian.h>
43# >>> /usr/lib/crt1.o:(_start)45# "file not found" errors.
44#release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test46stage2/bin/zig libc >libc.txt
47
48ZIG_LIBC=libc.txt stage2/bin/zig build \
49 --prefix stage3-release \
50 --search-prefix "$PREFIX" \
51 -Dstatic-llvm \
52 -Drelease \
53 -Dstrip \
54 -Dtarget="$TARGET" \
55 -Denable-stage1
4556
46# Here we skip some tests to save time.57# Here we skip some tests to save time.
47release/bin/zig build test -Dskip-stage1 -Dskip-non-native58stage3-release/bin/zig build test docs \
59 -Dstatic-llvm \
60 --search-prefix "$PREFIX" \
61 -Dskip-stage1 \
62 -Dskip-non-native
4863
49if [ -f ~/.s3cfg ]; then64if [ -f ~/.s3cfg ]; then
50 mv ../LICENSE release/65 mv ../LICENSE stage3-release/
51 mv ../zig-cache/langref.html release/66 mv ../zig-cache/langref.html stage3-release/
52 mv release/bin/zig release/67 mv stage3-release/bin/zig stage3-release/
53 rmdir release/bin68 rmdir stage3-release/bin
5469
55 GITBRANCH=$(basename $GITHUB_REF)70 GITBRANCH=$(basename $GITHUB_REF)
56 VERSION=$(release/zig version)71 VERSION=$(stage3-release/zig version)
57 DIRNAME="zig-freebsd-x86_64-$VERSION"72 DIRNAME="zig-freebsd-x86_64-$VERSION"
58 TARBALL="$DIRNAME.tar.xz"73 TARBALL="$DIRNAME.tar.xz"
59 mv release "$DIRNAME"74 mv stage3-release "$DIRNAME"
60 tar cfJ "$TARBALL" "$DIRNAME"75 tar cfJ "$TARBALL" "$DIRNAME"
6176
62 s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/77 s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
ci/zinc/drone.yml+11-5
...@@ -9,20 +9,26 @@ workspace:...@@ -9,20 +9,26 @@ workspace:
9 path: /workspace9 path: /workspace
1010
11steps:11steps:
12- name: test12- name: test_stage3_debug
13 image: ci/debian-amd64:11.1-613 image: ci/debian-amd64:11.1-7
14 commands:14 commands:
15 - ./ci/zinc/linux_test.sh15 - ./ci/zinc/linux_test_stage3_debug.sh
16
17- name: test_stage3_release
18 image: ci/debian-amd64:11.1-7
19 commands:
20 - ./ci/zinc/linux_test_stage3_release.sh
1621
17- name: package22- name: package
18 depends_on:23 depends_on:
19 - test24 - test_stage3_debug
25 - test_stage3_release
20 when:26 when:
21 branch:27 branch:
22 - master28 - master
23 event:29 event:
24 - push30 - push
25 image: ci/debian-amd64:11.1-631 image: ci/debian-amd64:11.1-7
26 environment:32 environment:
27 AWS_ACCESS_KEY_ID:33 AWS_ACCESS_KEY_ID:
28 from_secret: AWS_ACCESS_KEY_ID34 from_secret: AWS_ACCESS_KEY_ID
ci/zinc/linux_base.sh+4
...@@ -25,3 +25,7 @@ DEBUG_STAGING="$WORKSPACE/_debug/staging"...@@ -25,3 +25,7 @@ DEBUG_STAGING="$WORKSPACE/_debug/staging"
25RELEASE_STAGING="$WORKSPACE/_release/staging"25RELEASE_STAGING="$WORKSPACE/_release/staging"
2626
27export PATH=$DEPS_LOCAL/bin:$PATH27export PATH=$DEPS_LOCAL/bin:$PATH
28
29# Make the `zig version` number consistent.
30# This will affect the cmake commands that follow.
31git config core.abbrev 9
ci/zinc/linux_package.sh-3
...@@ -2,9 +2,6 @@...@@ -2,9 +2,6 @@
22
3. ./ci/zinc/linux_base.sh3. ./ci/zinc/linux_base.sh
44
5cp LICENSE $RELEASE_STAGING/
6cp zig-cache/langref.html $RELEASE_STAGING/docs/
7
8# Remove the unnecessary bin dir in $prefix/bin/zig5# Remove the unnecessary bin dir in $prefix/bin/zig
9mv $RELEASE_STAGING/bin/zig $RELEASE_STAGING/6mv $RELEASE_STAGING/bin/zig $RELEASE_STAGING/
10rmdir $RELEASE_STAGING/bin7rmdir $RELEASE_STAGING/bin
ci/zinc/linux_test.sh deleted-93
...@@ -1,93 +0,0 @@
1#!/bin/sh
2
3. ./ci/zinc/linux_base.sh
4
5OLD_ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
8
9# Make the `zig version` number consistent.
10# This will affect the cmake command below.
11git config core.abbrev 9
12
13echo "building debug zig with zig version $($OLD_ZIG version)"
14
15export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
16export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
17
18mkdir _debug
19cd _debug
20cmake .. \
21 -DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \
22 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
23 -DCMAKE_BUILD_TYPE=Debug \
24 -DZIG_TARGET_TRIPLE="$TARGET" \
25 -DZIG_TARGET_MCPU="$MCPU" \
26 -DZIG_STATIC=ON \
27 -GNinja
28
29# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
30# so that installation and testing do not get affected by them.
31unset CC
32unset CXX
33
34ninja install
35
36STAGE1_ZIG="$DEBUG_STAGING/bin/zig"
37
38# Here we rebuild zig but this time using the Zig binary we just now produced to
39# build zig1.o rather than relying on the one built with stage0. See
40# https://github.com/ziglang/zig/issues/6830 for more details.
41cmake .. -DZIG_EXECUTABLE="$STAGE1_ZIG"
42ninja install
43
44cd $WORKSPACE
45
46echo "Looking for non-conforming code formatting..."
47echo "Formatting errors can be fixed by running 'zig fmt' on the files printed here."
48$STAGE1_ZIG fmt --check . --exclude test/cases/
49
50$STAGE1_ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
51stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
52stage3/bin/zig build # test building self-hosted without LLVM
53stage3/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm
54
55stage3/bin/zig build test-compiler-rt -fqemu -fwasmtime -Denable-llvm
56stage3/bin/zig build test-behavior -fqemu -fwasmtime -Denable-llvm
57stage3/bin/zig build test-std -fqemu -fwasmtime -Denable-llvm
58stage3/bin/zig build test-universal-libc -fqemu -fwasmtime -Denable-llvm
59stage3/bin/zig build test-compare-output -fqemu -fwasmtime -Denable-llvm
60stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm
61stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm
62stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
63stage3/bin/zig build test-run-translated-c -fqemu -fwasmtime -Denable-llvm
64stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
65stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
66stage3/bin/zig build test-cases -fqemu -fwasmtime -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
67stage3/bin/zig build test-link -fqemu -fwasmtime -Denable-llvm
68
69$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
70$STAGE1_ZIG build docs -fqemu -fwasmtime
71
72# Produce the experimental std lib documentation.
73mkdir -p "$RELEASE_STAGING/docs/std"
74stage3/bin/zig test lib/std/std.zig \
75 --zig-lib-dir lib \
76 -femit-docs=$RELEASE_STAGING/docs/std \
77 -fno-emit-bin
78
79# Look for HTML errors.
80tidy --drop-empty-elements no -qe zig-cache/langref.html
81
82# Build release zig.
83stage3/bin/zig build \
84 --prefix "$RELEASE_STAGING" \
85 --search-prefix "$DEPS_LOCAL" \
86 -Dstatic-llvm \
87 -Drelease \
88 -Dstrip \
89 -Dtarget="$TARGET" \
90 -Dstage1
91
92# Explicit exit helps show last command duration.
93exit
ci/zinc/linux_test_stage3_debug.sh created+61
...@@ -0,0 +1,61 @@
1#!/bin/sh
2
3. ./ci/zinc/linux_base.sh
4
5OLD_ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
8
9echo "building stage3-debug with zig version $($OLD_ZIG version)"
10
11# Override the cache directories so that we don't clobber with the release
12# testing script which is running concurrently and in the same directory.
13# Normally we want processes to cooperate, but in this case we want them isolated.
14export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-cache-local-debug"
15export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-cache-global-debug"
16
17export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
18export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
19
20mkdir build-debug
21cd build-debug
22cmake .. \
23 -DCMAKE_INSTALL_PREFIX="$DEBUG_STAGING" \
24 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
25 -DCMAKE_BUILD_TYPE=Debug \
26 -DZIG_TARGET_TRIPLE="$TARGET" \
27 -DZIG_TARGET_MCPU="$MCPU" \
28 -DZIG_STATIC=ON \
29 -GNinja
30
31# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
32# so that installation and testing do not get affected by them.
33unset CC
34unset CXX
35
36ninja install
37
38cd $WORKSPACE
39
40"$DEBUG_STAGING/bin/zig" build -p stage3 -Denable-stage1 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
41
42# simultaneously test building self-hosted without LLVM and with 32-bit arm
43stage3/bin/zig build -Dtarget=arm-linux-musleabihf
44
45echo "Looking for non-conforming code formatting..."
46stage3/bin/zig fmt --check . \
47 --exclude test/cases/ \
48 --exclude build-debug \
49 --exclude build-release \
50 --exclude "$ZIG_LOCAL_CACHE_DIR" \
51 --exclude "$ZIG_GLOBAL_CACHE_DIR"
52
53stage3/bin/zig build test \
54 -fqemu \
55 -fwasmtime \
56 -Dstatic-llvm \
57 -Dtarget=native-native-musl \
58 --search-prefix "$DEPS_LOCAL"
59
60# Explicit exit helps show last command duration.
61exit
ci/zinc/linux_test_stage3_release.sh created+78
...@@ -0,0 +1,78 @@
1#!/bin/sh
2
3. ./ci/zinc/linux_base.sh
4
5OLD_ZIG="$DEPS_LOCAL/bin/zig"
6TARGET="${ARCH}-linux-musl"
7MCPU="baseline"
8
9echo "building stage3-release with zig version $($OLD_ZIG version)"
10
11export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
12export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
13
14mkdir build-release
15cd build-release
16STAGE2_PREFIX="$(pwd)/stage2"
17cmake .. \
18 -DCMAKE_INSTALL_PREFIX="$STAGE2_PREFIX" \
19 -DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
20 -DCMAKE_BUILD_TYPE=Release \
21 -DZIG_TARGET_TRIPLE="$TARGET" \
22 -DZIG_TARGET_MCPU="$MCPU" \
23 -DZIG_STATIC=ON \
24 -GNinja
25
26# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
27# so that installation and testing do not get affected by them.
28unset CC
29unset CXX
30
31ninja install
32
33# Here we rebuild zig but this time using the Zig binary we just now produced to
34# build zig1.o rather than relying on the one built with stage0. See
35# https://github.com/ziglang/zig/issues/6830 for more details.
36cmake .. -DZIG_EXECUTABLE="$STAGE2_PREFIX/bin/zig"
37ninja install
38
39# This is the binary we will distribute. We intentionally test this one in this
40# script. If any test failures occur, hopefully they also occur in the debug
41# version of this script for easier troubleshooting. This prevents distribution
42# of a Zig binary that passes tests in debug mode but has a miscompilation in
43# release mode.
44"$STAGE2_PREFIX/bin/zig" build \
45 --prefix "$RELEASE_STAGING" \
46 --search-prefix "$DEPS_LOCAL" \
47 -Dstatic-llvm \
48 -Drelease \
49 -Dstrip \
50 -Dtarget="$TARGET" \
51 -Denable-stage1
52
53cd $WORKSPACE
54
55ZIG="$RELEASE_STAGING/bin/zig"
56
57$ZIG build test docs \
58 -fqemu \
59 -fwasmtime \
60 -Dstatic-llvm \
61 -Dtarget=native-native-musl \
62 --search-prefix "$DEPS_LOCAL"
63
64# Produce the experimental std lib documentation.
65mkdir -p "$RELEASE_STAGING/docs/std"
66$ZIG test lib/std/std.zig \
67 --zig-lib-dir lib \
68 -femit-docs=$RELEASE_STAGING/docs/std \
69 -fno-emit-bin
70
71cp LICENSE $RELEASE_STAGING/
72cp zig-cache/langref.html $RELEASE_STAGING/docs/
73
74# Look for HTML errors.
75tidy --drop-empty-elements no -qe $RELEASE_STAGING/docs/langref.html
76
77# Explicit exit helps show last command duration.
78exit
doc/docgen.zig+31
...@@ -285,6 +285,7 @@ const Code = struct {...@@ -285,6 +285,7 @@ const Code = struct {
285 link_objects: []const []const u8,285 link_objects: []const []const u8,
286 target_str: ?[]const u8,286 target_str: ?[]const u8,
287 link_libc: bool,287 link_libc: bool,
288 backend_stage1: bool,
288 link_mode: ?std.builtin.LinkMode,289 link_mode: ?std.builtin.LinkMode,
289 disable_cache: bool,290 disable_cache: bool,
290 verbose_cimport: bool,291 verbose_cimport: bool,
...@@ -554,6 +555,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {...@@ -554,6 +555,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
554 var link_mode: ?std.builtin.LinkMode = null;555 var link_mode: ?std.builtin.LinkMode = null;
555 var disable_cache = false;556 var disable_cache = false;
556 var verbose_cimport = false;557 var verbose_cimport = false;
558 var backend_stage1 = false;
557559
558 const source_token = while (true) {560 const source_token = while (true) {
559 const content_tok = try eatToken(tokenizer, Token.Id.Content);561 const content_tok = try eatToken(tokenizer, Token.Id.Content);
...@@ -586,6 +588,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {...@@ -586,6 +588,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
586 link_libc = true;588 link_libc = true;
587 } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {589 } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
588 link_mode = .Dynamic;590 link_mode = .Dynamic;
591 } else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
592 backend_stage1 = true;
589 } else if (mem.eql(u8, end_tag_name, "code_end")) {593 } else if (mem.eql(u8, end_tag_name, "code_end")) {
590 _ = try eatToken(tokenizer, Token.Id.BracketClose);594 _ = try eatToken(tokenizer, Token.Id.BracketClose);
591 break content_tok;595 break content_tok;
...@@ -609,6 +613,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {...@@ -609,6 +613,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
609 .link_objects = link_objects.toOwnedSlice(),613 .link_objects = link_objects.toOwnedSlice(),
610 .target_str = target_str,614 .target_str = target_str,
611 .link_libc = link_libc,615 .link_libc = link_libc,
616 .backend_stage1 = backend_stage1,
612 .link_mode = link_mode,617 .link_mode = link_mode,
613 .disable_cache = disable_cache,618 .disable_cache = disable_cache,
614 .verbose_cimport = verbose_cimport,619 .verbose_cimport = verbose_cimport,
...@@ -1187,6 +1192,9 @@ fn printShell(out: anytype, shell_content: []const u8) !void {...@@ -1187,6 +1192,9 @@ fn printShell(out: anytype, shell_content: []const u8) !void {
1187 try out.writeAll("</samp></pre></figure>");1192 try out.writeAll("</samp></pre></figure>");
1188}1193}
11891194
1195// Override this to skip to later tests
1196const debug_start_line = 0;
1197
1190fn genHtml(1198fn genHtml(
1191 allocator: Allocator,1199 allocator: Allocator,
1192 tokenizer: *Tokenizer,1200 tokenizer: *Tokenizer,
...@@ -1266,6 +1274,13 @@ fn genHtml(...@@ -1266,6 +1274,13 @@ fn genHtml(
1266 continue;1274 continue;
1267 }1275 }
12681276
1277 if (debug_start_line > 0) {
1278 const loc = tokenizer.getTokenLocation(code.source_token);
1279 if (debug_start_line > loc.line) {
1280 continue;
1281 }
1282 }
1283
1269 const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];1284 const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
1270 const trimmed_raw_source = mem.trim(u8, raw_source, " \n");1285 const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
1271 const tmp_source_file_name = try fs.path.join(1286 const tmp_source_file_name = try fs.path.join(
...@@ -1311,6 +1326,10 @@ fn genHtml(...@@ -1311,6 +1326,10 @@ fn genHtml(
1311 try build_args.append("-lc");1326 try build_args.append("-lc");
1312 try shell_out.print("-lc ", .{});1327 try shell_out.print("-lc ", .{});
1313 }1328 }
1329 if (code.backend_stage1) {
1330 try build_args.append("-fstage1");
1331 try shell_out.print("-fstage1", .{});
1332 }
1314 const target = try std.zig.CrossTarget.parse(.{1333 const target = try std.zig.CrossTarget.parse(.{
1315 .arch_os_abi = code.target_str orelse "native",1334 .arch_os_abi = code.target_str orelse "native",
1316 });1335 });
...@@ -1443,6 +1462,10 @@ fn genHtml(...@@ -1443,6 +1462,10 @@ fn genHtml(
1443 try test_args.append("-lc");1462 try test_args.append("-lc");
1444 try shell_out.print("-lc ", .{});1463 try shell_out.print("-lc ", .{});
1445 }1464 }
1465 if (code.backend_stage1) {
1466 try test_args.append("-fstage1");
1467 try shell_out.print("-fstage1", .{});
1468 }
1446 if (code.target_str) |triple| {1469 if (code.target_str) |triple| {
1447 try test_args.appendSlice(&[_][]const u8{ "-target", triple });1470 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
1448 try shell_out.print("-target {s} ", .{triple});1471 try shell_out.print("-target {s} ", .{triple});
...@@ -1490,6 +1513,14 @@ fn genHtml(...@@ -1490,6 +1513,14 @@ fn genHtml(
1490 try shell_out.print("-O {s} ", .{@tagName(code.mode)});1513 try shell_out.print("-O {s} ", .{@tagName(code.mode)});
1491 },1514 },
1492 }1515 }
1516 if (code.link_libc) {
1517 try test_args.append("-lc");
1518 try shell_out.print("-lc ", .{});
1519 }
1520 if (code.backend_stage1) {
1521 try test_args.append("-fstage1");
1522 try shell_out.print("-fstage1", .{});
1523 }
1493 const result = try ChildProcess.exec(.{1524 const result = try ChildProcess.exec(.{
1494 .allocator = allocator,1525 .allocator = allocator,
1495 .argv = test_args.items,1526 .argv = test_args.items,
doc/langref.html.in+69-109
...@@ -1188,6 +1188,7 @@ test "this will be skipped" {...@@ -1188,6 +1188,7 @@ test "this will be skipped" {
1188 (The evented IO mode is enabled using the <kbd>--test-evented-io</kbd> command line parameter.)1188 (The evented IO mode is enabled using the <kbd>--test-evented-io</kbd> command line parameter.)
1189 </p>1189 </p>
1190 {#code_begin|test|async_skip#}1190 {#code_begin|test|async_skip#}
1191 {#backend_stage1#}
1191const std = @import("std");1192const std = @import("std");
11921193
1193test "async skip test" {1194test "async skip test" {
...@@ -2768,7 +2769,7 @@ test "comptime @intToPtr" {...@@ -2768,7 +2769,7 @@ test "comptime @intToPtr" {
2768 }2769 }
2769}2770}
2770 {#code_end#}2771 {#code_end#}
2771 {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers|Pointers to Zero Bit Types#}2772 {#see_also|Optional Pointers|@intToPtr|@ptrToInt|C Pointers#}
2772 {#header_open|volatile#}2773 {#header_open|volatile#}
2773 <p>Loads and stores are assumed to not have side effects. If a given load or store2774 <p>Loads and stores are assumed to not have side effects. If a given load or store
2774 should have side effects, such as Memory Mapped Input/Output (MMIO), use {#syntax#}volatile{#endsyntax#}.2775 should have side effects, such as Memory Mapped Input/Output (MMIO), use {#syntax#}volatile{#endsyntax#}.
...@@ -2862,19 +2863,22 @@ var foo: u8 align(4) = 100;...@@ -2862,19 +2863,22 @@ var foo: u8 align(4) = 100;
2862test "global variable alignment" {2863test "global variable alignment" {
2863 try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);2864 try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
2864 try expect(@TypeOf(&foo) == *align(4) u8);2865 try expect(@TypeOf(&foo) == *align(4) u8);
2865 const as_pointer_to_array: *[1]u8 = &foo;2866 const as_pointer_to_array: *align(4) [1]u8 = &foo;
2866 const as_slice: []u8 = as_pointer_to_array;2867 const as_slice: []align(4) u8 = as_pointer_to_array;
2867 try expect(@TypeOf(as_slice) == []align(4) u8);2868 const as_unaligned_slice: []u8 = as_slice;
2869 try expect(as_unaligned_slice[0] == 100);
2868}2870}
28692871
2870fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }2872fn derp() align(@sizeOf(usize) * 2) i32 {
2873 return 1234;
2874}
2871fn noop1() align(1) void {}2875fn noop1() align(1) void {}
2872fn noop4() align(4) void {}2876fn noop4() align(4) void {}
28732877
2874test "function alignment" {2878test "function alignment" {
2875 try expect(derp() == 1234);2879 try expect(derp() == 1234);
2876 try expect(@TypeOf(noop1) == fn() align(1) void);2880 try expect(@TypeOf(noop1) == fn () align(1) void);
2877 try expect(@TypeOf(noop4) == fn() align(4) void);2881 try expect(@TypeOf(noop4) == fn () align(4) void);
2878 noop1();2882 noop1();
2879 noop4();2883 noop4();
2880}2884}
...@@ -3336,6 +3340,7 @@ fn doTheTest() !void {...@@ -3336,6 +3340,7 @@ fn doTheTest() !void {
3336 Zig allows the address to be taken of a non-byte-aligned field:3340 Zig allows the address to be taken of a non-byte-aligned field:
3337 </p>3341 </p>
3338 {#code_begin|test|pointer_to_non-byte_aligned_field#}3342 {#code_begin|test|pointer_to_non-byte_aligned_field#}
3343 {#backend_stage1#}
3339const std = @import("std");3344const std = @import("std");
3340const expect = std.testing.expect;3345const expect = std.testing.expect;
33413346
...@@ -3391,7 +3396,8 @@ fn bar(x: *const u3) u3 {...@@ -3391,7 +3396,8 @@ fn bar(x: *const u3) u3 {
3391 <p>3396 <p>
3392 Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:3397 Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:
3393 </p>3398 </p>
3394 {#code_begin|test|pointer_to_non-bit_aligned_field#}3399 {#code_begin|test|packed_struct_field_addrs#}
3400 {#backend_stage1#}
3395const std = @import("std");3401const std = @import("std");
3396const expect = std.testing.expect;3402const expect = std.testing.expect;
33973403
...@@ -3407,7 +3413,7 @@ var bit_field = BitField{...@@ -3407,7 +3413,7 @@ var bit_field = BitField{
3407 .c = 3,3413 .c = 3,
3408};3414};
34093415
3410test "pointer to non-bit-aligned field" {3416test "pointers of sub-byte-aligned fields share addresses" {
3411 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));3417 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
3412 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));3418 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
3413}3419}
...@@ -3438,20 +3444,22 @@ test "pointer to non-bit-aligned field" {...@@ -3438,20 +3444,22 @@ test "pointer to non-bit-aligned field" {
3438}3444}
3439 {#code_end#}3445 {#code_end#}
3440 <p>3446 <p>
3441 Packed structs have 1-byte alignment. However if you have an overaligned pointer to a packed struct,3447 Packed structs have the same alignment as their backing integer, however, overaligned
3442 Zig should correctly understand the alignment of fields. However there is3448 pointers to packed structs can override this:
3443 <a href="https://github.com/ziglang/zig/issues/1994">a bug</a>:
3444 </p>3449 </p>
3445 {#code_begin|test_err|expected type '*u32', found '*align(1) u32'#}3450 {#code_begin|test|overaligned_packed_struct#}
3451const std = @import("std");
3452const expect = std.testing.expect;
3453
3446const S = packed struct {3454const S = packed struct {
3447 a: u32,3455 a: u32,
3448 b: u32,3456 b: u32,
3449};3457};
3450test "overaligned pointer to packed struct" {3458test "overaligned pointer to packed struct" {
3451 var foo: S align(4) = undefined;3459 var foo: S align(4) = .{ .a = 1, .b = 2 };
3452 const ptr: *align(4) S = &foo;3460 const ptr: *align(4) S = &foo;
3453 const ptr_to_b: *u32 = &ptr.b;3461 const ptr_to_b: *u32 = &ptr.b;
3454 _ = ptr_to_b;3462 try expect(ptr_to_b.* == 2);
3455}3463}
3456 {#code_end#}3464 {#code_end#}
3457 <p>When this bug is fixed, the above test in the documentation will unexpectedly pass, which will3465 <p>When this bug is fixed, the above test in the documentation will unexpectedly pass, which will
...@@ -3698,7 +3706,7 @@ test "@tagName" {...@@ -3698,7 +3706,7 @@ test "@tagName" {
3698 <p>3706 <p>
3699 By default, enums are not guaranteed to be compatible with the C ABI:3707 By default, enums are not guaranteed to be compatible with the C ABI:
3700 </p>3708 </p>
3701 {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'C'#}3709 {#code_begin|obj_err|parameter of type 'test.Foo' not allowed in function with calling convention 'C'#}
3702const Foo = enum { a, b, c };3710const Foo = enum { a, b, c };
3703export fn entry(foo: Foo) void { _ = foo; }3711export fn entry(foo: Foo) void { _ = foo; }
3704 {#code_end#}3712 {#code_end#}
...@@ -4004,7 +4012,7 @@ fn makeNumber() Number {...@@ -4004,7 +4012,7 @@ fn makeNumber() Number {
4004 This is typically used for type safety when interacting with C code that does not expose struct details.4012 This is typically used for type safety when interacting with C code that does not expose struct details.
4005 Example:4013 Example:
4006 </p>4014 </p>
4007 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}4015 {#code_begin|test_err|expected type '*test.Derp', found '*test.Wat'#}
4008const Derp = opaque {};4016const Derp = opaque {};
4009const Wat = opaque {};4017const Wat = opaque {};
40104018
...@@ -4203,7 +4211,7 @@ test "switch on tagged union" {...@@ -4203,7 +4211,7 @@ test "switch on tagged union" {
4203 When a {#syntax#}switch{#endsyntax#} expression does not have an {#syntax#}else{#endsyntax#} clause,4211 When a {#syntax#}switch{#endsyntax#} expression does not have an {#syntax#}else{#endsyntax#} clause,
4204 it must exhaustively list all the possible values. Failure to do so is a compile error:4212 it must exhaustively list all the possible values. Failure to do so is a compile error:
4205 </p>4213 </p>
4206 {#code_begin|test_err|not handled in switch#}4214 {#code_begin|test_err|unhandled enumeration value#}
4207const Color = enum {4215const Color = enum {
4208 auto,4216 auto,
4209 off,4217 off,
...@@ -5026,17 +5034,9 @@ test "function" {...@@ -5026,17 +5034,9 @@ test "function" {
5026 try expect(do_op(sub2, 5, 6) == -1);5034 try expect(do_op(sub2, 5, 6) == -1);
5027}5035}
5028 {#code_end#}5036 {#code_end#}
5029 <p>Function values are like pointers:</p>5037 <p>There is a difference between a function <em>body</em> and a function <em>pointer</em>.
5030 {#code_begin|obj#}5038 Function bodies are {#link|comptime#}-only types while function {#link|Pointers#} may be
5031const assert = @import("std").debug.assert;5039 runtime-known.</p>
5032
5033comptime {
5034 assert(@TypeOf(foo) == fn()void);
5035 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
5036}
5037
5038fn foo() void { }
5039 {#code_end#}
5040 {#header_open|Pass-by-value Parameters#}5040 {#header_open|Pass-by-value Parameters#}
5041 <p>5041 <p>
5042 Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters5042 Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters
...@@ -6123,10 +6123,11 @@ test "float widening" {...@@ -6123,10 +6123,11 @@ test "float widening" {
6123 two choices about the coercion.6123 two choices about the coercion.
6124 </p>6124 </p>
6125 <ul>6125 <ul>
6126 <li> Cast {#syntax#}54.0{#endsyntax#} to {#syntax#}comptime_int{#endsyntax#} resulting in {#syntax#}@as(comptime_int, 10){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10){#endsyntax#}</li>6126 <li>Cast {#syntax#}54.0{#endsyntax#} to {#syntax#}comptime_int{#endsyntax#} resulting in {#syntax#}@as(comptime_int, 10){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10){#endsyntax#}</li>
6127 <li> Cast {#syntax#}5{#endsyntax#} to {#syntax#}comptime_float{#endsyntax#} resulting in {#syntax#}@as(comptime_float, 10.8){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10.8){#endsyntax#}</li>6127 <li>Cast {#syntax#}5{#endsyntax#} to {#syntax#}comptime_float{#endsyntax#} resulting in {#syntax#}@as(comptime_float, 10.8){#endsyntax#}, which is casted to {#syntax#}@as(f32, 10.8){#endsyntax#}</li>
6128 </ul>6128 </ul>
6129 {#code_begin|test_err#}6129 {#code_begin|test_err#}
6130 {#backend_stage1#}
6130// Compile time coercion of float to int6131// Compile time coercion of float to int
6131test "implicit cast to comptime_int" {6132test "implicit cast to comptime_int" {
6132 var f: f32 = 54.0 / 5;6133 var f: f32 = 54.0 / 5;
...@@ -6302,19 +6303,6 @@ test "coercion between unions and enums" {...@@ -6302,19 +6303,6 @@ test "coercion between unions and enums" {
6302 {#code_end#}6303 {#code_end#}
6303 {#see_also|union|enum#}6304 {#see_also|union|enum#}
6304 {#header_close#}6305 {#header_close#}
6305 {#header_open|Type Coercion: Zero Bit Types#}
6306 <p>{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
6307 regardless of const.</p>
6308 <p>TODO document the reasoning for this</p>
6309 <p>TODO document whether vice versa should work and why</p>
6310 {#code_begin|test|coerce_zero_bit_types#}
6311test "coercion of zero bit types" {
6312 var x: void = {};
6313 var y: *void = x;
6314 _ = y;
6315}
6316 {#code_end#}
6317 {#header_close#}
6318 {#header_open|Type Coercion: undefined#}6306 {#header_open|Type Coercion: undefined#}
6319 <p>{#link|undefined#} can be cast to any type.</p>6307 <p>{#link|undefined#} can be cast to any type.</p>
6320 {#header_close#}6308 {#header_close#}
...@@ -6467,7 +6455,6 @@ test "peer type resolution: *const T and ?*T" {...@@ -6467,7 +6455,6 @@ test "peer type resolution: *const T and ?*T" {
6467 <li>An {#link|enum#} with only 1 tag.</li>6455 <li>An {#link|enum#} with only 1 tag.</li>
6468 <li>A {#link|struct#} with all fields being zero bit types.</li>6456 <li>A {#link|struct#} with all fields being zero bit types.</li>
6469 <li>A {#link|union#} with only 1 field which is a zero bit type.</li>6457 <li>A {#link|union#} with only 1 field which is a zero bit type.</li>
6470 <li>{#link|Pointers to Zero Bit Types#} are themselves zero bit types.</li>
6471 </ul>6458 </ul>
6472 <p>6459 <p>
6473 These types can only ever have one possible value, and thus6460 These types can only ever have one possible value, and thus
...@@ -6527,7 +6514,7 @@ test "turn HashMap into a set with void" {...@@ -6527,7 +6514,7 @@ test "turn HashMap into a set with void" {
6527 <p>6514 <p>
6528 Expressions of type {#syntax#}void{#endsyntax#} are the only ones whose value can be ignored. For example:6515 Expressions of type {#syntax#}void{#endsyntax#} are the only ones whose value can be ignored. For example:
6529 </p>6516 </p>
6530 {#code_begin|test_err|expression value is ignored#}6517 {#code_begin|test_err|ignored#}
6531test "ignoring expression value" {6518test "ignoring expression value" {
6532 foo();6519 foo();
6533}6520}
...@@ -6553,37 +6540,6 @@ fn foo() i32 {...@@ -6553,37 +6540,6 @@ fn foo() i32 {
6553}6540}
6554 {#code_end#}6541 {#code_end#}
6555 {#header_close#}6542 {#header_close#}
6556
6557 {#header_open|Pointers to Zero Bit Types#}
6558 <p>Pointers to zero bit types also have zero bits. They always compare equal to each other:</p>
6559 {#code_begin|test|pointers_to_zero_bits#}
6560const std = @import("std");
6561const expect = std.testing.expect;
6562
6563test "pointer to empty struct" {
6564 const Empty = struct {};
6565 var a = Empty{};
6566 var b = Empty{};
6567 var ptr_a = &a;
6568 var ptr_b = &b;
6569 comptime try expect(ptr_a == ptr_b);
6570}
6571 {#code_end#}
6572 <p>The type being pointed to can only ever be one value; therefore loads and stores are
6573 never generated. {#link|ptrToInt#} and {#link|intToPtr#} are not allowed:</p>
6574 {#code_begin|test_err#}
6575const Empty = struct {};
6576
6577test "@ptrToInt for pointer to zero bit type" {
6578 var a = Empty{};
6579 _ = @ptrToInt(&a);
6580}
6581
6582test "@intToPtr for pointer to zero bit type" {
6583 _ = @intToPtr(*Empty, 0x1);
6584}
6585 {#code_end#}
6586 {#header_close#}
6587 {#header_close#}6543 {#header_close#}
65886544
6589 {#header_open|Result Location Semantics#}6545 {#header_open|Result Location Semantics#}
...@@ -6666,7 +6622,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {...@@ -6666,7 +6622,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
6666 <p>6622 <p>
6667 For example, if we were to introduce another function to the above snippet:6623 For example, if we were to introduce another function to the above snippet:
6668 </p>6624 </p>
6669 {#code_begin|test_err|values of type 'type' must be comptime known#}6625 {#code_begin|test_err|unable to resolve comptime value#}
6670fn max(comptime T: type, a: T, b: T) T {6626fn max(comptime T: type, a: T, b: T) T {
6671 return if (a > b) a else b;6627 return if (a > b) a else b;
6672}6628}
...@@ -6692,7 +6648,7 @@ fn foo(condition: bool) void {...@@ -6692,7 +6648,7 @@ fn foo(condition: bool) void {
6692 <p>6648 <p>
6693 For example:6649 For example:
6694 </p>6650 </p>
6695 {#code_begin|test_err|operator not allowed for type 'bool'#}6651 {#code_begin|test_err|operator > not allowed for type 'bool'#}
6696fn max(comptime T: type, a: T, b: T) T {6652fn max(comptime T: type, a: T, b: T) T {
6697 return if (a > b) a else b;6653 return if (a > b) a else b;
6698}6654}
...@@ -6837,7 +6793,7 @@ fn performFn(start_value: i32) i32 {...@@ -6837,7 +6793,7 @@ fn performFn(start_value: i32) i32 {
6837 use a {#syntax#}comptime{#endsyntax#} expression to guarantee that the expression will be evaluated at compile-time.6793 use a {#syntax#}comptime{#endsyntax#} expression to guarantee that the expression will be evaluated at compile-time.
6838 If this cannot be accomplished, the compiler will emit an error. For example:6794 If this cannot be accomplished, the compiler will emit an error. For example:
6839 </p>6795 </p>
6840 {#code_begin|test_err|unable to evaluate constant expression#}6796 {#code_begin|test_err|comptime call of extern function#}
6841extern fn exit() noreturn;6797extern fn exit() noreturn;
68426798
6843test "foo" {6799test "foo" {
...@@ -6889,7 +6845,7 @@ test "fibonacci" {...@@ -6889,7 +6845,7 @@ test "fibonacci" {
6889 <p>6845 <p>
6890 Imagine if we had forgotten the base case of the recursive function and tried to run the tests:6846 Imagine if we had forgotten the base case of the recursive function and tried to run the tests:
6891 </p>6847 </p>
6892 {#code_begin|test_err|operation caused overflow#}6848 {#code_begin|test_err|overflow of integer type#}
6893const expect = @import("std").testing.expect;6849const expect = @import("std").testing.expect;
68946850
6895fn fibonacci(index: u32) u32 {6851fn fibonacci(index: u32) u32 {
...@@ -6913,7 +6869,8 @@ test "fibonacci" {...@@ -6913,7 +6869,8 @@ test "fibonacci" {
6913 But what would have happened if we used a signed integer?6869 But what would have happened if we used a signed integer?
6914 </p>6870 </p>
6915 {#code_begin|test_err|evaluation exceeded 1000 backwards branches#}6871 {#code_begin|test_err|evaluation exceeded 1000 backwards branches#}
6916const expect = @import("std").testing.expect;6872 {#backend_stage1#}
6873const assert = @import("std").debug.assert;
69176874
6918fn fibonacci(index: i32) i32 {6875fn fibonacci(index: i32) i32 {
6919 //if (index < 2) return index;6876 //if (index < 2) return index;
...@@ -6922,7 +6879,7 @@ fn fibonacci(index: i32) i32 {...@@ -6922,7 +6879,7 @@ fn fibonacci(index: i32) i32 {
69226879
6923test "fibonacci" {6880test "fibonacci" {
6924 comptime {6881 comptime {
6925 try expect(fibonacci(7) == 13);6882 try assert(fibonacci(7) == 13);
6926 }6883 }
6927}6884}
6928 {#code_end#}6885 {#code_end#}
...@@ -6935,8 +6892,8 @@ test "fibonacci" {...@@ -6935,8 +6892,8 @@ test "fibonacci" {
6935 <p>6892 <p>
6936 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?6893 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
6937 </p>6894 </p>
6938 {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#}6895 {#code_begin|test_err|reached unreachable#}
6939const expect = @import("std").testing.expect;6896const assert = @import("std").debug.assert;
69406897
6941fn fibonacci(index: i32) i32 {6898fn fibonacci(index: i32) i32 {
6942 if (index < 2) return index;6899 if (index < 2) return index;
...@@ -6945,16 +6902,10 @@ fn fibonacci(index: i32) i32 {...@@ -6945,16 +6902,10 @@ fn fibonacci(index: i32) i32 {
69456902
6946test "fibonacci" {6903test "fibonacci" {
6947 comptime {6904 comptime {
6948 try expect(fibonacci(7) == 99999);6905 try assert(fibonacci(7) == 99999);
6949 }6906 }
6950}6907}
6951 {#code_end#}6908 {#code_end#}
6952 <p>
6953 What happened is Zig started interpreting the {#syntax#}expect{#endsyntax#} function with the
6954 parameter {#syntax#}ok{#endsyntax#} set to {#syntax#}false{#endsyntax#}. When the interpreter hit
6955 {#syntax#}@panic{#endsyntax#} it emitted a compile error because a panic during compile
6956 causes a compile error if it is detected at compile-time.
6957 </p>
69586909
6959 <p>6910 <p>
6960 At container level (outside of any function), all expressions are implicitly6911 At container level (outside of any function), all expressions are implicitly
...@@ -7280,6 +7231,7 @@ pub fn main() void {...@@ -7280,6 +7231,7 @@ pub fn main() void {
7280 </p>7231 </p>
7281 {#code_begin|exe#}7232 {#code_begin|exe#}
7282 {#target_linux_x86_64#}7233 {#target_linux_x86_64#}
7234 {#backend_stage1#}
7283pub fn main() noreturn {7235pub fn main() noreturn {
7284 const msg = "hello world\n";7236 const msg = "hello world\n";
7285 _ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len);7237 _ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len);
...@@ -7497,6 +7449,7 @@ test "global assembly" {...@@ -7497,6 +7449,7 @@ test "global assembly" {
7497 or resumer (in the case of subsequent suspensions).7449 or resumer (in the case of subsequent suspensions).
7498 </p>7450 </p>
7499 {#code_begin|test|suspend_no_resume#}7451 {#code_begin|test|suspend_no_resume#}
7452 {#backend_stage1#}
7500const std = @import("std");7453const std = @import("std");
7501const expect = std.testing.expect;7454const expect = std.testing.expect;
75027455
...@@ -7524,6 +7477,7 @@ fn func() void {...@@ -7524,6 +7477,7 @@ fn func() void {
7524 {#link|@frame#} provides access to the async function frame pointer.7477 {#link|@frame#} provides access to the async function frame pointer.
7525 </p>7478 </p>
7526 {#code_begin|test|async_suspend_block#}7479 {#code_begin|test|async_suspend_block#}
7480 {#backend_stage1#}
7527const std = @import("std");7481const std = @import("std");
7528const expect = std.testing.expect;7482const expect = std.testing.expect;
75297483
...@@ -7562,6 +7516,7 @@ fn testSuspendBlock() void {...@@ -7562,6 +7516,7 @@ fn testSuspendBlock() void {
7562 never returns to its resumer and continues executing.7516 never returns to its resumer and continues executing.
7563 </p>7517 </p>
7564 {#code_begin|test|resume_from_suspend#}7518 {#code_begin|test|resume_from_suspend#}
7519 {#backend_stage1#}
7565const std = @import("std");7520const std = @import("std");
7566const expect = std.testing.expect;7521const expect = std.testing.expect;
75677522
...@@ -7598,6 +7553,7 @@ fn testResumeFromSuspend(my_result: *i32) void {...@@ -7598,6 +7553,7 @@ fn testResumeFromSuspend(my_result: *i32) void {
7598 and the return value of the async function would be lost.7553 and the return value of the async function would be lost.
7599 </p>7554 </p>
7600 {#code_begin|test|async_await#}7555 {#code_begin|test|async_await#}
7556 {#backend_stage1#}
7601const std = @import("std");7557const std = @import("std");
7602const expect = std.testing.expect;7558const expect = std.testing.expect;
76037559
...@@ -7642,6 +7598,7 @@ fn func() void {...@@ -7642,6 +7598,7 @@ fn func() void {
7642 return value directly from the target function's frame.7598 return value directly from the target function's frame.
7643 </p>7599 </p>
7644 {#code_begin|test|async_await_sequence#}7600 {#code_begin|test|async_await_sequence#}
7601 {#backend_stage1#}
7645const std = @import("std");7602const std = @import("std");
7646const expect = std.testing.expect;7603const expect = std.testing.expect;
76477604
...@@ -7695,6 +7652,7 @@ fn seq(c: u8) void {...@@ -7695,6 +7652,7 @@ fn seq(c: u8) void {
7695 {#syntax#}async{#endsyntax#}/{#syntax#}await{#endsyntax#} usage:7652 {#syntax#}async{#endsyntax#}/{#syntax#}await{#endsyntax#} usage:
7696 </p>7653 </p>
7697 {#code_begin|exe|async#}7654 {#code_begin|exe|async#}
7655 {#backend_stage1#}
7698const std = @import("std");7656const std = @import("std");
7699const Allocator = std.mem.Allocator;7657const Allocator = std.mem.Allocator;
77007658
...@@ -7773,6 +7731,7 @@ fn readFile(allocator: Allocator, filename: []const u8) ![]u8 {...@@ -7773,6 +7731,7 @@ fn readFile(allocator: Allocator, filename: []const u8) ![]u8 {
7773 observe the same behavior, with one tiny difference:7731 observe the same behavior, with one tiny difference:
7774 </p>7732 </p>
7775 {#code_begin|exe|blocking#}7733 {#code_begin|exe|blocking#}
7734 {#backend_stage1#}
7776const std = @import("std");7735const std = @import("std");
7777const Allocator = std.mem.Allocator;7736const Allocator = std.mem.Allocator;
77787737
...@@ -7910,6 +7869,7 @@ comptime {...@@ -7910,6 +7869,7 @@ comptime {
7910 {#syntax#}await{#endsyntax#} will copy the result from {#syntax#}result_ptr{#endsyntax#}.7869 {#syntax#}await{#endsyntax#} will copy the result from {#syntax#}result_ptr{#endsyntax#}.
7911 </p>7870 </p>
7912 {#code_begin|test|async_struct_field_fn_pointer#}7871 {#code_begin|test|async_struct_field_fn_pointer#}
7872 {#backend_stage1#}
7913const std = @import("std");7873const std = @import("std");
7914const expect = std.testing.expect;7874const expect = std.testing.expect;
79157875
...@@ -8677,6 +8637,7 @@ test "decl access by string" {...@@ -8677,6 +8637,7 @@ test "decl access by string" {
8677 allows one to, for example, heap-allocate an async function frame:8637 allows one to, for example, heap-allocate an async function frame:
8678 </p>8638 </p>
8679 {#code_begin|test|heap_allocated_frame#}8639 {#code_begin|test|heap_allocated_frame#}
8640 {#backend_stage1#}
8680const std = @import("std");8641const std = @import("std");
86818642
8682test "heap allocated frame" {8643test "heap allocated frame" {
...@@ -9423,12 +9384,6 @@ const std = @import("std");...@@ -9423,12 +9384,6 @@ const std = @import("std");
9423const expect = std.testing.expect;9384const expect = std.testing.expect;
94249385
9425test "vector @reduce" {9386test "vector @reduce" {
9426 // This test regressed with LLVM 14:
9427 // https://github.com/llvm/llvm-project/issues/55522
9428 // We'll skip this test unless the self-hosted compiler is being used.
9429 // After LLVM 15 is released we can delete this line.
9430 if (@import("builtin").zig_backend == .stage1) return;
9431
9432 const value = @Vector(4, i32){ 1, -1, 1, -1 };9387 const value = @Vector(4, i32){ 1, -1, 1, -1 };
9433 const result = value > @splat(4, @as(i32, 0));9388 const result = value > @splat(4, @as(i32, 0));
9434 // result is { true, false, true, false };9389 // result is { true, false, true, false };
...@@ -9938,7 +9893,7 @@ pub fn main() void {...@@ -9938,7 +9893,7 @@ pub fn main() void {
9938 {#header_close#}9893 {#header_close#}
9939 {#header_open|Index out of Bounds#}9894 {#header_open|Index out of Bounds#}
9940 <p>At compile-time:</p>9895 <p>At compile-time:</p>
9941 {#code_begin|test_err|index 5 outside array of size 5#}9896 {#code_begin|test_err|index 5 outside array of length 5#}
9942comptime {9897comptime {
9943 const array: [5]u8 = "hello".*;9898 const array: [5]u8 = "hello".*;
9944 const garbage = array[5];9899 const garbage = array[5];
...@@ -9959,9 +9914,9 @@ fn foo(x: []const u8) u8 {...@@ -9959,9 +9914,9 @@ fn foo(x: []const u8) u8 {
9959 {#header_close#}9914 {#header_close#}
9960 {#header_open|Cast Negative Number to Unsigned Integer#}9915 {#header_open|Cast Negative Number to Unsigned Integer#}
9961 <p>At compile-time:</p>9916 <p>At compile-time:</p>
9962 {#code_begin|test_err|attempt to cast negative value to unsigned integer#}9917 {#code_begin|test_err|type 'u32' cannot represent integer value '-1'#}
9963comptime {9918comptime {
9964 const value: i32 = -1;9919 var value: i32 = -1;
9965 const unsigned = @intCast(u32, value);9920 const unsigned = @intCast(u32, value);
9966 _ = unsigned;9921 _ = unsigned;
9967}9922}
...@@ -9982,7 +9937,7 @@ pub fn main() void {...@@ -9982,7 +9937,7 @@ pub fn main() void {
9982 {#header_close#}9937 {#header_close#}
9983 {#header_open|Cast Truncates Data#}9938 {#header_open|Cast Truncates Data#}
9984 <p>At compile-time:</p>9939 <p>At compile-time:</p>
9985 {#code_begin|test_err|cast from 'u16' to 'u8' truncates bits#}9940 {#code_begin|test_err|type 'u8' cannot represent integer value '300'#}
9986comptime {9941comptime {
9987 const spartan_count: u16 = 300;9942 const spartan_count: u16 = 300;
9988 const byte = @intCast(u8, spartan_count);9943 const byte = @intCast(u8, spartan_count);
...@@ -10017,7 +9972,7 @@ pub fn main() void {...@@ -10017,7 +9972,7 @@ pub fn main() void {
10017 <li>{#link|@divExact#} (division)</li>9972 <li>{#link|@divExact#} (division)</li>
10018 </ul>9973 </ul>
10019 <p>Example with addition at compile-time:</p>9974 <p>Example with addition at compile-time:</p>
10020 {#code_begin|test_err|operation caused overflow#}9975 {#code_begin|test_err|overflow of integer type 'u8' with value '256'#}
10021comptime {9976comptime {
10022 var byte: u8 = 255;9977 var byte: u8 = 255;
10023 byte += 1;9978 byte += 1;
...@@ -10118,6 +10073,7 @@ test "wraparound addition and subtraction" {...@@ -10118,6 +10073,7 @@ test "wraparound addition and subtraction" {
10118 {#header_open|Exact Left Shift Overflow#}10073 {#header_open|Exact Left Shift Overflow#}
10119 <p>At compile-time:</p>10074 <p>At compile-time:</p>
10120 {#code_begin|test_err|operation caused overflow#}10075 {#code_begin|test_err|operation caused overflow#}
10076 {#backend_stage1#}
10121comptime {10077comptime {
10122 const x = @shlExact(@as(u8, 0b01010101), 2);10078 const x = @shlExact(@as(u8, 0b01010101), 2);
10123 _ = x;10079 _ = x;
...@@ -10137,6 +10093,7 @@ pub fn main() void {...@@ -10137,6 +10093,7 @@ pub fn main() void {
10137 {#header_open|Exact Right Shift Overflow#}10093 {#header_open|Exact Right Shift Overflow#}
10138 <p>At compile-time:</p>10094 <p>At compile-time:</p>
10139 {#code_begin|test_err|exact shift shifted out 1 bits#}10095 {#code_begin|test_err|exact shift shifted out 1 bits#}
10096 {#backend_stage1#}
10140comptime {10097comptime {
10141 const x = @shrExact(@as(u8, 0b10101010), 2);10098 const x = @shrExact(@as(u8, 0b10101010), 2);
10142 _ = x;10099 _ = x;
...@@ -10200,6 +10157,7 @@ pub fn main() void {...@@ -10200,6 +10157,7 @@ pub fn main() void {
10200 {#header_open|Exact Division Remainder#}10157 {#header_open|Exact Division Remainder#}
10201 <p>At compile-time:</p>10158 <p>At compile-time:</p>
10202 {#code_begin|test_err|exact division had a remainder#}10159 {#code_begin|test_err|exact division had a remainder#}
10160 {#backend_stage1#}
10203comptime {10161comptime {
10204 const a: u32 = 10;10162 const a: u32 = 10;
10205 const b: u32 = 3;10163 const b: u32 = 3;
...@@ -10302,7 +10260,7 @@ fn getNumberOrFail() !i32 {...@@ -10302,7 +10260,7 @@ fn getNumberOrFail() !i32 {
10302 {#header_close#}10260 {#header_close#}
10303 {#header_open|Invalid Error Code#}10261 {#header_open|Invalid Error Code#}
10304 <p>At compile-time:</p>10262 <p>At compile-time:</p>
10305 {#code_begin|test_err|integer value 11 represents no error#}10263 {#code_begin|test_err|integer value '11' represents no error#}
10306comptime {10264comptime {
10307 const err = error.AnError;10265 const err = error.AnError;
10308 const number = @errorToInt(err) + 10;10266 const number = @errorToInt(err) + 10;
...@@ -10324,7 +10282,7 @@ pub fn main() void {...@@ -10324,7 +10282,7 @@ pub fn main() void {
10324 {#header_close#}10282 {#header_close#}
10325 {#header_open|Invalid Enum Cast#}10283 {#header_open|Invalid Enum Cast#}
10326 <p>At compile-time:</p>10284 <p>At compile-time:</p>
10327 {#code_begin|test_err|has no tag matching integer value 3#}10285 {#code_begin|test_err|enum 'test.Foo' has no tag with value '3'#}
10328const Foo = enum {10286const Foo = enum {
10329 a,10287 a,
10330 b,10288 b,
...@@ -10356,7 +10314,7 @@ pub fn main() void {...@@ -10356,7 +10314,7 @@ pub fn main() void {
1035610314
10357 {#header_open|Invalid Error Set Cast#}10315 {#header_open|Invalid Error Set Cast#}
10358 <p>At compile-time:</p>10316 <p>At compile-time:</p>
10359 {#code_begin|test_err|error.B not a member of error set 'Set2'#}10317 {#code_begin|test_err|'error.B' not a member of error set 'error{A,C}'#}
10360const Set1 = error{10318const Set1 = error{
10361 A,10319 A,
10362 B,10320 B,
...@@ -10417,7 +10375,7 @@ fn foo(bytes: []u8) u32 {...@@ -10417,7 +10375,7 @@ fn foo(bytes: []u8) u32 {
10417 {#header_close#}10375 {#header_close#}
10418 {#header_open|Wrong Union Field Access#}10376 {#header_open|Wrong Union Field Access#}
10419 <p>At compile-time:</p>10377 <p>At compile-time:</p>
10420 {#code_begin|test_err|accessing union field 'float' while field 'int' is set#}10378 {#code_begin|test_err|access of union field 'float' while field 'int' is active#}
10421comptime {10379comptime {
10422 var f = Foo{ .int = 42 };10380 var f = Foo{ .int = 42 };
10423 f.float = 12.34;10381 f.float = 12.34;
...@@ -10509,6 +10467,7 @@ fn bar(f: *Foo) void {...@@ -10509,6 +10467,7 @@ fn bar(f: *Foo) void {
10509 </p>10467 </p>
10510 <p>At compile-time:</p>10468 <p>At compile-time:</p>
10511 {#code_begin|test_err|null pointer casted to type#}10469 {#code_begin|test_err|null pointer casted to type#}
10470 {#backend_stage1#}
10512comptime {10471comptime {
10513 const opt_ptr: ?*i32 = null;10472 const opt_ptr: ?*i32 = null;
10514 const ptr = @ptrCast(*i32, opt_ptr);10473 const ptr = @ptrCast(*i32, opt_ptr);
...@@ -10551,7 +10510,8 @@ const expect = std.testing.expect;...@@ -10551,7 +10510,8 @@ const expect = std.testing.expect;
1055110510
10552test "using an allocator" {10511test "using an allocator" {
10553 var buffer: [100]u8 = undefined;10512 var buffer: [100]u8 = undefined;
10554 const allocator = std.heap.FixedBufferAllocator.init(&buffer).allocator();10513 var fba = std.heap.FixedBufferAllocator.init(&buffer);
10514 const allocator = fba.allocator();
10555 const result = try concat(allocator, "foo", "bar");10515 const result = try concat(allocator, "foo", "bar");
10556 try expect(std.mem.eql(u8, "foobar", result));10516 try expect(std.mem.eql(u8, "foobar", result));
10557}10517}
...@@ -10647,7 +10607,7 @@ pub fn main() !void {...@@ -10647,7 +10607,7 @@ pub fn main() !void {
10647 <p>String literals such as {#syntax#}"foo"{#endsyntax#} are in the global constant data section.10607 <p>String literals such as {#syntax#}"foo"{#endsyntax#} are in the global constant data section.
10648 This is why it is an error to pass a string literal to a mutable slice, like this:10608 This is why it is an error to pass a string literal to a mutable slice, like this:
10649 </p>10609 </p>
10650 {#code_begin|test_err|cannot cast pointer to array literal to slice type '[]u8'#}10610 {#code_begin|test_err|expected type '[]u8', found '*const [5:0]u8'#}
10651fn foo(s: []u8) void {10611fn foo(s: []u8) void {
10652 _ = s;10612 _ = s;
10653}10613}
lib/std/builtin.zig+1-1
...@@ -866,7 +866,7 @@ pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {...@@ -866,7 +866,7 @@ pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
866866
867pub fn panicOutOfBounds(index: usize, len: usize) noreturn {867pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
868 @setCold(true);868 @setCold(true);
869 std.debug.panic("attempt to index out of bound: index {d}, len {d}", .{ index, len });869 std.debug.panic("index out of bounds: index {d}, len {d}", .{ index, len });
870}870}
871871
872pub noinline fn returnError(st: *StackTrace) void {872pub noinline fn returnError(st: *StackTrace) void {
lib/std/coff.zig+1-1
...@@ -383,7 +383,7 @@ const OptionalHeader = struct {...@@ -383,7 +383,7 @@ const OptionalHeader = struct {
383 image_base: u64,383 image_base: u64,
384};384};
385385
386const DebugDirectoryEntry = packed struct {386const DebugDirectoryEntry = extern struct {
387 characteristiccs: u32,387 characteristiccs: u32,
388 time_date_stamp: u32,388 time_date_stamp: u32,
389 major_version: u16,389 major_version: u16,
lib/std/os/linux/bpf.zig+1-1
...@@ -458,7 +458,7 @@ pub const Insn = packed struct {...@@ -458,7 +458,7 @@ pub const Insn = packed struct {
458 else458 else
459 ImmOrReg{ .imm = src };459 ImmOrReg{ .imm = src };
460460
461 const src_type = switch (imm_or_reg) {461 const src_type: u8 = switch (imm_or_reg) {
462 .imm => K,462 .imm => K,
463 .reg => X,463 .reg => X,
464 };464 };
lib/std/os/windows.zig+1-1
...@@ -1802,7 +1802,7 @@ pub const PathSpace = struct {...@@ -1802,7 +1802,7 @@ pub const PathSpace = struct {
1802 data: [PATH_MAX_WIDE:0]u16,1802 data: [PATH_MAX_WIDE:0]u16,
1803 len: usize,1803 len: usize,
18041804
1805 pub fn span(self: PathSpace) [:0]const u16 {1805 pub fn span(self: *const PathSpace) [:0]const u16 {
1806 return self.data[0..self.len :0];1806 return self.data[0..self.len :0];
1807 }1807 }
1808};1808};
src/Compilation.zig+8-48
...@@ -1040,24 +1040,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1040,24 +1040,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1040 const comp = try arena.create(Compilation);1040 const comp = try arena.create(Compilation);
1041 const root_name = try arena.dupeZ(u8, options.root_name);1041 const root_name = try arena.dupeZ(u8, options.root_name);
10421042
1043 const use_stage1 = options.use_stage1 orelse blk: {1043 const use_stage1 = options.use_stage1 orelse false;
1044 // Even though we may have no Zig code to compile (depending on `options.main_pkg`),
1045 // we may need to use stage1 for building compiler-rt and other dependencies.
1046
1047 if (build_options.omit_stage2)
1048 break :blk true;
1049 if (options.use_llvm) |use_llvm| {
1050 if (!use_llvm) {
1051 break :blk false;
1052 }
1053 }
1054
1055 // If LLVM does not support the target, then we can't use it.
1056 if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
1057 break :blk false;
1058
1059 break :blk build_options.is_stage1;
1060 };
10611044
1062 const cache_mode = if (use_stage1 and !options.disable_lld_caching)1045 const cache_mode = if (use_stage1 and !options.disable_lld_caching)
1063 CacheMode.whole1046 CacheMode.whole
...@@ -1248,7 +1231,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1248,7 +1231,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1248 break :blk lm;1231 break :blk lm;
1249 } else default_link_mode;1232 } else default_link_mode;
12501233
1251 const dll_export_fns = if (options.dll_export_fns) |explicit| explicit else is_dyn_lib or options.rdynamic;1234 const dll_export_fns = options.dll_export_fns orelse (is_dyn_lib or options.rdynamic);
12521235
1253 const libc_dirs = try detectLibCIncludeDirs(1236 const libc_dirs = try detectLibCIncludeDirs(
1254 arena,1237 arena,
...@@ -2213,8 +2196,7 @@ pub fn update(comp: *Compilation) !void {...@@ -2213,8 +2196,7 @@ pub fn update(comp: *Compilation) !void {
2213 comp.c_object_work_queue.writeItemAssumeCapacity(key);2196 comp.c_object_work_queue.writeItemAssumeCapacity(key);
2214 }2197 }
22152198
2216 const use_stage1 = build_options.omit_stage2 or2199 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
2217 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
2218 if (comp.bin_file.options.module) |module| {2200 if (comp.bin_file.options.module) |module| {
2219 module.compile_log_text.shrinkAndFree(module.gpa, 0);2201 module.compile_log_text.shrinkAndFree(module.gpa, 0);
2220 module.generation += 1;2202 module.generation += 1;
...@@ -2390,8 +2372,7 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -2390,8 +2372,7 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
2390 };2372 };
2391 comp.link_error_flags = comp.bin_file.errorFlags();2373 comp.link_error_flags = comp.bin_file.errorFlags();
23922374
2393 const use_stage1 = build_options.omit_stage2 or2375 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
2394 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
2395 if (!use_stage1) {2376 if (!use_stage1) {
2396 if (comp.bin_file.options.module) |module| {2377 if (comp.bin_file.options.module) |module| {
2397 try link.File.C.flushEmitH(module);2378 try link.File.C.flushEmitH(module);
...@@ -2849,7 +2830,7 @@ pub fn performAllTheWork(...@@ -2849,7 +2830,7 @@ pub fn performAllTheWork(
2849 comp.work_queue_wait_group.reset();2830 comp.work_queue_wait_group.reset();
2850 defer comp.work_queue_wait_group.wait();2831 defer comp.work_queue_wait_group.wait();
28512832
2852 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;2833 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
28532834
2854 {2835 {
2855 const astgen_frame = tracy.namedFrame("astgen");2836 const astgen_frame = tracy.namedFrame("astgen");
...@@ -2952,9 +2933,6 @@ pub fn performAllTheWork(...@@ -2952,9 +2933,6 @@ pub fn performAllTheWork(
2952fn processOneJob(comp: *Compilation, job: Job) !void {2933fn processOneJob(comp: *Compilation, job: Job) !void {
2953 switch (job) {2934 switch (job) {
2954 .codegen_decl => |decl_index| {2935 .codegen_decl => |decl_index| {
2955 if (build_options.omit_stage2)
2956 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2957
2958 const module = comp.bin_file.options.module.?;2936 const module = comp.bin_file.options.module.?;
2959 const decl = module.declPtr(decl_index);2937 const decl = module.declPtr(decl_index);
29602938
...@@ -2989,9 +2967,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -2989,9 +2967,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
2989 }2967 }
2990 },2968 },
2991 .codegen_func => |func| {2969 .codegen_func => |func| {
2992 if (build_options.omit_stage2)
2993 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2994
2995 const named_frame = tracy.namedFrame("codegen_func");2970 const named_frame = tracy.namedFrame("codegen_func");
2996 defer named_frame.end();2971 defer named_frame.end();
29972972
...@@ -3002,9 +2977,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3002,9 +2977,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3002 };2977 };
3003 },2978 },
3004 .emit_h_decl => |decl_index| {2979 .emit_h_decl => |decl_index| {
3005 if (build_options.omit_stage2)
3006 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
3007
3008 const module = comp.bin_file.options.module.?;2980 const module = comp.bin_file.options.module.?;
3009 const decl = module.declPtr(decl_index);2981 const decl = module.declPtr(decl_index);
30102982
...@@ -3063,9 +3035,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3063,9 +3035,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3063 }3035 }
3064 },3036 },
3065 .analyze_decl => |decl_index| {3037 .analyze_decl => |decl_index| {
3066 if (build_options.omit_stage2)
3067 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
3068
3069 const module = comp.bin_file.options.module.?;3038 const module = comp.bin_file.options.module.?;
3070 module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {3039 module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {
3071 error.OutOfMemory => return error.OutOfMemory,3040 error.OutOfMemory => return error.OutOfMemory,
...@@ -3073,9 +3042,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3073,9 +3042,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3073 };3042 };
3074 },3043 },
3075 .update_embed_file => |embed_file| {3044 .update_embed_file => |embed_file| {
3076 if (build_options.omit_stage2)
3077 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
3078
3079 const named_frame = tracy.namedFrame("update_embed_file");3045 const named_frame = tracy.namedFrame("update_embed_file");
3080 defer named_frame.end();3046 defer named_frame.end();
30813047
...@@ -3086,9 +3052,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3086,9 +3052,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3086 };3052 };
3087 },3053 },
3088 .update_line_number => |decl_index| {3054 .update_line_number => |decl_index| {
3089 if (build_options.omit_stage2)
3090 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
3091
3092 const named_frame = tracy.namedFrame("update_line_number");3055 const named_frame = tracy.namedFrame("update_line_number");
3093 defer named_frame.end();3056 defer named_frame.end();
30943057
...@@ -3107,9 +3070,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3107,9 +3070,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3107 };3070 };
3108 },3071 },
3109 .analyze_pkg => |pkg| {3072 .analyze_pkg => |pkg| {
3110 if (build_options.omit_stage2)
3111 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
3112
3113 const named_frame = tracy.namedFrame("analyze_pkg");3073 const named_frame = tracy.namedFrame("analyze_pkg");
3114 defer named_frame.end();3074 defer named_frame.end();
31153075
...@@ -3455,7 +3415,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {...@@ -3455,7 +3415,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
3455 var man = comp.obtainCObjectCacheManifest();3415 var man = comp.obtainCObjectCacheManifest();
3456 defer man.deinit();3416 defer man.deinit();
34573417
3458 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;3418 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
34593419
3460 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects3420 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
3461 man.hash.add(use_stage1);3421 man.hash.add(use_stage1);
...@@ -4770,7 +4730,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca...@@ -4770,7 +4730,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
47704730
4771 const target = comp.getTarget();4731 const target = comp.getTarget();
4772 const generic_arch_name = target.cpu.arch.genericName();4732 const generic_arch_name = target.cpu.arch.genericName();
4773 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;4733 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
47744734
4775 const zig_backend: std.builtin.CompilerBackend = blk: {4735 const zig_backend: std.builtin.CompilerBackend = blk: {
4776 if (use_stage1) break :blk .stage1;4736 if (use_stage1) break :blk .stage1;
...@@ -5057,7 +5017,7 @@ fn buildOutputFromZig(...@@ -5057,7 +5017,7 @@ fn buildOutputFromZig(
5057 .link_mode = .Static,5017 .link_mode = .Static,
5058 .function_sections = true,5018 .function_sections = true,
5059 .no_builtin = true,5019 .no_builtin = true,
5060 .use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1,5020 .use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1,
5061 .want_sanitize_c = false,5021 .want_sanitize_c = false,
5062 .want_stack_check = false,5022 .want_stack_check = false,
5063 .want_stack_protector = 0,5023 .want_stack_protector = 0,
src/Module.zig+4
...@@ -6529,3 +6529,7 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u...@@ -6529,3 +6529,7 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u
65296529
6530 mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);6530 mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);
6531}6531}
6532
6533pub fn wantDllExports(mod: Module) bool {
6534 return mod.comp.bin_file.options.dll_export_fns and mod.getTarget().os.tag == .windows;
6535}
src/Sema.zig-7
...@@ -27358,9 +27358,6 @@ pub fn resolveTypeLayout(...@@ -27358,9 +27358,6 @@ pub fn resolveTypeLayout(
27358 src: LazySrcLoc,27358 src: LazySrcLoc,
27359 ty: Type,27359 ty: Type,
27360) CompileError!void {27360) CompileError!void {
27361 if (build_options.omit_stage2)
27362 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
27363
27364 switch (ty.zigTypeTag()) {27361 switch (ty.zigTypeTag()) {
27365 .Struct => return sema.resolveStructLayout(block, src, ty),27362 .Struct => return sema.resolveStructLayout(block, src, ty),
27366 .Union => return sema.resolveUnionLayout(block, src, ty),27363 .Union => return sema.resolveUnionLayout(block, src, ty),
...@@ -27699,8 +27696,6 @@ fn resolveUnionFully(...@@ -27699,8 +27696,6 @@ fn resolveUnionFully(
27699}27696}
2770027697
27701pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {27698pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
27702 if (build_options.omit_stage2)
27703 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
27704 switch (ty.tag()) {27699 switch (ty.tag()) {
27705 .@"struct" => {27700 .@"struct" => {
27706 const struct_obj = ty.castTag(.@"struct").?.data;27701 const struct_obj = ty.castTag(.@"struct").?.data;
...@@ -29323,8 +29318,6 @@ fn typePtrOrOptionalPtrTy(...@@ -29323,8 +29318,6 @@ fn typePtrOrOptionalPtrTy(
29323/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen29318/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
29324/// elsewhere in value.zig29319/// elsewhere in value.zig
29325pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {29320pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
29326 if (build_options.omit_stage2)
29327 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
29328 return switch (ty.tag()) {29321 return switch (ty.tag()) {
29329 .u1,29322 .u1,
29330 .u8,29323 .u8,
src/codegen/llvm.zig+3
...@@ -1103,6 +1103,7 @@ pub const Object = struct {...@@ -1103,6 +1103,7 @@ pub const Object = struct {
1103 }1103 }
1104 llvm_global.setUnnamedAddr(.False);1104 llvm_global.setUnnamedAddr(.False);
1105 llvm_global.setLinkage(.External);1105 llvm_global.setLinkage(.External);
1106 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
1106 if (self.di_map.get(decl)) |di_node| {1107 if (self.di_map.get(decl)) |di_node| {
1107 if (try decl.isFunction()) {1108 if (try decl.isFunction()) {
1108 const di_func = @ptrCast(*llvm.DISubprogram, di_node);1109 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
...@@ -1128,6 +1129,7 @@ pub const Object = struct {...@@ -1128,6 +1129,7 @@ pub const Object = struct {
1128 const exp_name = exports[0].options.name;1129 const exp_name = exports[0].options.name;
1129 llvm_global.setValueName2(exp_name.ptr, exp_name.len);1130 llvm_global.setValueName2(exp_name.ptr, exp_name.len);
1130 llvm_global.setUnnamedAddr(.False);1131 llvm_global.setUnnamedAddr(.False);
1132 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
1131 if (self.di_map.get(decl)) |di_node| {1133 if (self.di_map.get(decl)) |di_node| {
1132 if (try decl.isFunction()) {1134 if (try decl.isFunction()) {
1133 const di_func = @ptrCast(*llvm.DISubprogram, di_node);1135 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
...@@ -1187,6 +1189,7 @@ pub const Object = struct {...@@ -1187,6 +1189,7 @@ pub const Object = struct {
1187 defer module.gpa.free(fqn);1189 defer module.gpa.free(fqn);
1188 llvm_global.setValueName2(fqn.ptr, fqn.len);1190 llvm_global.setValueName2(fqn.ptr, fqn.len);
1189 llvm_global.setLinkage(.Internal);1191 llvm_global.setLinkage(.Internal);
1192 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
1190 llvm_global.setUnnamedAddr(.True);1193 llvm_global.setUnnamedAddr(.True);
1191 if (decl.val.castTag(.variable)) |variable| {1194 if (decl.val.castTag(.variable)) |variable| {
1192 const single_threaded = module.comp.bin_file.options.single_threaded;1195 const single_threaded = module.comp.bin_file.options.single_threaded;
src/codegen/llvm/bindings.zig+9
...@@ -223,6 +223,9 @@ pub const Value = opaque {...@@ -223,6 +223,9 @@ pub const Value = opaque {
223 pub const setInitializer = LLVMSetInitializer;223 pub const setInitializer = LLVMSetInitializer;
224 extern fn LLVMSetInitializer(GlobalVar: *const Value, ConstantVal: *const Value) void;224 extern fn LLVMSetInitializer(GlobalVar: *const Value, ConstantVal: *const Value) void;
225225
226 pub const setDLLStorageClass = LLVMSetDLLStorageClass;
227 extern fn LLVMSetDLLStorageClass(Global: *const Value, Class: DLLStorageClass) void;
228
226 pub const addCase = LLVMAddCase;229 pub const addCase = LLVMAddCase;
227 extern fn LLVMAddCase(Switch: *const Value, OnVal: *const Value, Dest: *const BasicBlock) void;230 extern fn LLVMAddCase(Switch: *const Value, OnVal: *const Value, Dest: *const BasicBlock) void;
228231
...@@ -1482,6 +1485,12 @@ pub const CallAttr = enum(c_int) {...@@ -1482,6 +1485,12 @@ pub const CallAttr = enum(c_int) {
1482 AlwaysInline,1485 AlwaysInline,
1483};1486};
14841487
1488pub const DLLStorageClass = enum(c_uint) {
1489 Default,
1490 DLLImport,
1491 DLLExport,
1492};
1493
1485pub const address_space = struct {1494pub const address_space = struct {
1486 pub const default: c_uint = 0;1495 pub const default: c_uint = 0;
14871496
src/config.zig.in+1-2
...@@ -8,6 +8,5 @@ pub const enable_logging: bool = @ZIG_ENABLE_LOGGING_BOOL@;...@@ -8,6 +8,5 @@ pub const enable_logging: bool = @ZIG_ENABLE_LOGGING_BOOL@;
8pub const enable_link_snapshots: bool = false;8pub const enable_link_snapshots: bool = false;
9pub const enable_tracy = false;9pub const enable_tracy = false;
10pub const value_tracing = false;10pub const value_tracing = false;
11pub const is_stage1 = true;11pub const have_stage1 = true;
12pub const skip_non_native = false;12pub const skip_non_native = false;
13pub const omit_stage2: bool = @ZIG_OMIT_STAGE2_BOOL@;
src/link.zig+2-2
...@@ -279,7 +279,7 @@ pub const File = struct {...@@ -279,7 +279,7 @@ pub const File = struct {
279 return &(try MachO.openPath(allocator, options)).base;279 return &(try MachO.openPath(allocator, options)).base;
280 }280 }
281281
282 const use_stage1 = build_options.is_stage1 and options.use_stage1;282 const use_stage1 = build_options.have_stage1 and options.use_stage1;
283 if (use_stage1 or options.emit == null) {283 if (use_stage1 or options.emit == null) {
284 return switch (options.target.ofmt) {284 return switch (options.target.ofmt) {
285 .coff => &(try Coff.createEmpty(allocator, options)).base,285 .coff => &(try Coff.createEmpty(allocator, options)).base,
...@@ -817,7 +817,7 @@ pub const File = struct {...@@ -817,7 +817,7 @@ pub const File = struct {
817 // If there is no Zig code to compile, then we should skip flushing the output file817 // If there is no Zig code to compile, then we should skip flushing the output file
818 // because it will not be part of the linker line anyway.818 // because it will not be part of the linker line anyway.
819 const module_obj_path: ?[]const u8 = if (base.options.module) |module| blk: {819 const module_obj_path: ?[]const u8 = if (base.options.module) |module| blk: {
820 const use_stage1 = build_options.is_stage1 and base.options.use_stage1;820 const use_stage1 = build_options.have_stage1 and base.options.use_stage1;
821 if (use_stage1) {821 if (use_stage1) {
822 const obj_basename = try std.zig.binNameAlloc(arena, .{822 const obj_basename = try std.zig.binNameAlloc(arena, .{
823 .root_name = base.options.root_name,823 .root_name = base.options.root_name,
src/link/Coff.zig+2-2
...@@ -411,7 +411,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {...@@ -411,7 +411,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
411 };411 };
412412
413 const use_llvm = build_options.have_llvm and options.use_llvm;413 const use_llvm = build_options.have_llvm and options.use_llvm;
414 const use_stage1 = build_options.is_stage1 and options.use_stage1;414 const use_stage1 = build_options.have_stage1 and options.use_stage1;
415 if (use_llvm and !use_stage1) {415 if (use_llvm and !use_stage1) {
416 self.llvm_object = try LlvmObject.create(gpa, options);416 self.llvm_object = try LlvmObject.create(gpa, options);
417 }417 }
...@@ -949,7 +949,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -949,7 +949,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
949 // If there is no Zig code to compile, then we should skip flushing the output file because it949 // If there is no Zig code to compile, then we should skip flushing the output file because it
950 // will not be part of the linker line anyway.950 // will not be part of the linker line anyway.
951 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {951 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
952 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;952 const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
953 if (use_stage1) {953 if (use_stage1) {
954 const obj_basename = try std.zig.binNameAlloc(arena, .{954 const obj_basename = try std.zig.binNameAlloc(arena, .{
955 .root_name = self.base.options.root_name,955 .root_name = self.base.options.root_name,
src/link/Elf.zig+1-1
...@@ -328,7 +328,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {...@@ -328,7 +328,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
328 .page_size = page_size,328 .page_size = page_size,
329 };329 };
330 const use_llvm = build_options.have_llvm and options.use_llvm;330 const use_llvm = build_options.have_llvm and options.use_llvm;
331 const use_stage1 = build_options.is_stage1 and options.use_stage1;331 const use_stage1 = build_options.have_stage1 and options.use_stage1;
332 if (use_llvm and !use_stage1) {332 if (use_llvm and !use_stage1) {
333 self.llvm_object = try LlvmObject.create(gpa, options);333 self.llvm_object = try LlvmObject.create(gpa, options);
334 }334 }
src/link/MachO.zig+2-2
...@@ -272,7 +272,7 @@ pub const Export = struct {...@@ -272,7 +272,7 @@ pub const Export = struct {
272pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {272pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {
273 assert(options.target.ofmt == .macho);273 assert(options.target.ofmt == .macho);
274274
275 const use_stage1 = build_options.is_stage1 and options.use_stage1;275 const use_stage1 = build_options.have_stage1 and options.use_stage1;
276 if (use_stage1 or options.emit == null) {276 if (use_stage1 or options.emit == null) {
277 return createEmpty(allocator, options);277 return createEmpty(allocator, options);
278 }278 }
...@@ -363,7 +363,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {...@@ -363,7 +363,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
363 const cpu_arch = options.target.cpu.arch;363 const cpu_arch = options.target.cpu.arch;
364 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;364 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
365 const use_llvm = build_options.have_llvm and options.use_llvm;365 const use_llvm = build_options.have_llvm and options.use_llvm;
366 const use_stage1 = build_options.is_stage1 and options.use_stage1;366 const use_stage1 = build_options.have_stage1 and options.use_stage1;
367367
368 const self = try gpa.create(MachO);368 const self = try gpa.create(MachO);
369 errdefer gpa.destroy(self);369 errdefer gpa.destroy(self);
src/link/Wasm.zig+3-3
...@@ -356,7 +356,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {...@@ -356,7 +356,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
356 }356 }
357357
358 const use_llvm = build_options.have_llvm and options.use_llvm;358 const use_llvm = build_options.have_llvm and options.use_llvm;
359 const use_stage1 = build_options.is_stage1 and options.use_stage1;359 const use_stage1 = build_options.have_stage1 and options.use_stage1;
360 if (use_llvm and !use_stage1) {360 if (use_llvm and !use_stage1) {
361 self.llvm_object = try LlvmObject.create(gpa, options);361 self.llvm_object = try LlvmObject.create(gpa, options);
362 }362 }
...@@ -2593,7 +2593,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -2593,7 +2593,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
2593 // If there is no Zig code to compile, then we should skip flushing the output file because it2593 // If there is no Zig code to compile, then we should skip flushing the output file because it
2594 // will not be part of the linker line anyway.2594 // will not be part of the linker line anyway.
2595 const module_obj_path: ?[]const u8 = if (self.base.options.module) |mod| blk: {2595 const module_obj_path: ?[]const u8 = if (self.base.options.module) |mod| blk: {
2596 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;2596 const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
2597 if (use_stage1) {2597 if (use_stage1) {
2598 const obj_basename = try std.zig.binNameAlloc(arena, .{2598 const obj_basename = try std.zig.binNameAlloc(arena, .{
2599 .root_name = self.base.options.root_name,2599 .root_name = self.base.options.root_name,
...@@ -2803,7 +2803,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -2803,7 +2803,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
2803 if (self.base.options.module) |mod| {2803 if (self.base.options.module) |mod| {
2804 // when we use stage1, we use the exports that stage1 provided us.2804 // when we use stage1, we use the exports that stage1 provided us.
2805 // For stage2, we can directly retrieve them from the module.2805 // For stage2, we can directly retrieve them from the module.
2806 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;2806 const use_stage1 = build_options.have_stage1 and self.base.options.use_stage1;
2807 if (use_stage1) {2807 if (use_stage1) {
2808 for (comp.export_symbol_names.items) |symbol_name| {2808 for (comp.export_symbol_names.items) |symbol_name| {
2809 try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));2809 try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
src/main.zig+1-1
...@@ -2989,7 +2989,7 @@ fn buildOutputType(...@@ -2989,7 +2989,7 @@ fn buildOutputType(
2989 return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));2989 return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));
2990 }2990 }
2991 if (arg_mode == .translate_c) {2991 if (arg_mode == .translate_c) {
2992 const stage1_mode = use_stage1 orelse build_options.is_stage1;2992 const stage1_mode = use_stage1 orelse false;
2993 return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);2993 return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);
2994 }2994 }
29952995
src/stage1.zig+1-1
...@@ -18,7 +18,7 @@ const target_util = @import("target.zig");...@@ -18,7 +18,7 @@ const target_util = @import("target.zig");
1818
19comptime {19comptime {
20 assert(builtin.link_libc);20 assert(builtin.link_libc);
21 assert(build_options.is_stage1);21 assert(build_options.have_stage1);
22 assert(build_options.have_llvm);22 assert(build_options.have_llvm);
23 if (!builtin.is_test) {23 if (!builtin.is_test) {
24 @export(main, .{ .name = "main" });24 @export(main, .{ .name = "main" });
src/test.zig+1-1
...@@ -25,7 +25,7 @@ const skip_stage1 = builtin.zig_backend != .stage1 or build_options.skip_stage1;...@@ -25,7 +25,7 @@ const skip_stage1 = builtin.zig_backend != .stage1 or build_options.skip_stage1;
25const hr = "=" ** 80;25const hr = "=" ** 80;
2626
27test {27test {
28 if (build_options.is_stage1) {28 if (build_options.have_stage1) {
29 @import("stage1.zig").os_init();29 @import("stage1.zig").os_init();
30 }30 }
3131
test/cases/safety/empty slice with sentinel out of bounds.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to index out of bound: index 1, len 0")) {5 if (std.mem.eql(u8, message, "index out of bounds: index 1, len 0")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/out of bounds slice access.zig +3-3
...@@ -2,20 +2,20 @@ const std = @import("std");...@@ -2,20 +2,20 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to index out of bound: index 4, len 4")) {5 if (std.mem.eql(u8, message, "index out of bounds: index 4, len 4")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
9}9}
10pub fn main() !void {10pub fn main() !void {
11 const a = [_]i32{1, 2, 3, 4};11 const a = [_]i32{ 1, 2, 3, 4 };
12 baz(bar(&a));12 baz(bar(&a));
13 return error.TestFailed;13 return error.TestFailed;
14}14}
15fn bar(a: []const i32) i32 {15fn bar(a: []const i32) i32 {
16 return a[4];16 return a[4];
17}17}
18fn baz(_: i32) void { }18fn baz(_: i32) void {}
19// run19// run
20// backend=llvm20// backend=llvm
21// target=native21// target=native
test/cases/safety/slice with sentinel out of bounds - runtime len.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to index out of bound: index 5, len 4")) {5 if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/cases/safety/slice with sentinel out of bounds.zig +1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = stack_trace;4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "attempt to index out of bound: index 5, len 4")) {5 if (std.mem.eql(u8, message, "index out of bounds: index 5, len 4")) {
6 std.process.exit(0);6 std.process.exit(0);
7 }7 }
8 std.process.exit(1);8 std.process.exit(1);
test/tests.zig+5-6
...@@ -605,7 +605,6 @@ pub fn addPkgTests(...@@ -605,7 +605,6 @@ pub fn addPkgTests(
605 skip_libc: bool,605 skip_libc: bool,
606 skip_stage1: bool,606 skip_stage1: bool,
607 skip_stage2: bool,607 skip_stage2: bool,
608 is_stage1: bool,
609) *build.Step {608) *build.Step {
610 const step = b.step(b.fmt("test-{s}", .{name}), desc);609 const step = b.step(b.fmt("test-{s}", .{name}), desc);
611610
...@@ -634,7 +633,7 @@ pub fn addPkgTests(...@@ -634,7 +633,7 @@ pub fn addPkgTests(
634 if (test_target.backend) |backend| switch (backend) {633 if (test_target.backend) |backend| switch (backend) {
635 .stage1 => if (skip_stage1) continue,634 .stage1 => if (skip_stage1) continue,
636 else => if (skip_stage2) continue,635 else => if (skip_stage2) continue,
637 } else if (is_stage1 and skip_stage1) continue;636 } else if (skip_stage2) continue;
638637
639 const want_this_mode = for (modes) |m| {638 const want_this_mode = for (modes) |m| {
640 if (m == test_target.mode) break true;639 if (m == test_target.mode) break true;
...@@ -924,7 +923,7 @@ pub const StackTracesContext = struct {...@@ -924,7 +923,7 @@ pub const StackTracesContext = struct {
924 pos = marks[i] + delim.len;923 pos = marks[i] + delim.len;
925 }924 }
926 // locate source basename925 // locate source basename
927 pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {926 pos = mem.lastIndexOfAny(u8, line[0..marks[0]], "\\/") orelse {
928 // unexpected pattern: emit raw line and cont927 // unexpected pattern: emit raw line and cont
929 try buf.appendSlice(line);928 try buf.appendSlice(line);
930 try buf.appendSlice("\n");929 try buf.appendSlice("\n");
...@@ -936,9 +935,9 @@ pub const StackTracesContext = struct {...@@ -936,9 +935,9 @@ pub const StackTracesContext = struct {
936 try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);935 try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
937 try buf.appendSlice(" [address]");936 try buf.appendSlice(" [address]");
938 if (self.mode == .Debug) {937 if (self.mode == .Debug) {
939 if (mem.lastIndexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {938 // On certain platforms (windows) or possibly depending on how we choose to link main
940 // On certain platforms (windows) or possibly depending on how we choose to link main939 // the object file extension may be present so we simply strip any extension.
941 // the object file extension may be present so we simply strip any extension.940 if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
942 try buf.appendSlice(line[marks[3] .. marks[4] + idot]);941 try buf.appendSlice(line[marks[3] .. marks[4] + idot]);
943 try buf.appendSlice(line[marks[5]..]);942 try buf.appendSlice(line[marks[5]..]);
944 } else {943 } else {