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)
1212endif()
1313
1414if(NOT CMAKE_INSTALL_PREFIX)
15 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage1" CACHE STRING
15 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage2" CACHE STRING
1616 "Directory to install zig to" FORCE)
1717endif()
1818
build.zig+29-42
......@@ -15,6 +15,7 @@ const stack_size = 32 * 1024 * 1024;
1515
1616pub fn build(b: *Builder) !void {
1717 b.setPreferredReleaseMode(.ReleaseFast);
18 const test_step = b.step("test", "Run all the tests");
1819 const mode = b.standardReleaseOptions();
1920 const target = b.standardTargetOptions(.{});
2021 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 {
3940 const docs_step = b.step("docs", "Build documentation");
4041 docs_step.dependOn(&docgen_cmd.step);
4142
42 const toolchain_step = b.step("test-toolchain", "Run the tests for the toolchain");
43
4443 var test_cases = b.addTest("src/test.zig");
4544 test_cases.stack_size = stack_size;
4645 test_cases.setBuildMode(mode);
......@@ -64,10 +63,9 @@ pub fn build(b: *Builder) !void {
6463
6564 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;
68 const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
66 const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
6967 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);
7169 const llvm_has_m68k = b.option(
7270 bool,
7371 "llvm-has-m68k",
......@@ -137,7 +135,7 @@ pub fn build(b: *Builder) !void {
137135 };
138136
139137 const main_file: ?[]const u8 = mf: {
140 if (!is_stage1) break :mf "src/main.zig";
138 if (!have_stage1) break :mf "src/main.zig";
141139 if (use_zig0) break :mf null;
142140 break :mf "src/stage1.zig";
143141 };
......@@ -150,7 +148,7 @@ pub fn build(b: *Builder) !void {
150148 exe.setBuildMode(mode);
151149 exe.setTarget(target);
152150 if (!skip_stage2_tests) {
153 toolchain_step.dependOn(&exe.step);
151 test_step.dependOn(&exe.step);
154152 }
155153
156154 b.default_step.dependOn(&exe.step);
......@@ -248,7 +246,7 @@ pub fn build(b: *Builder) !void {
248246 }
249247 };
250248
251 if (is_stage1) {
249 if (have_stage1) {
252250 const softfloat = b.addStaticLibrary("softfloat", null);
253251 softfloat.setBuildMode(.ReleaseFast);
254252 softfloat.setTarget(target);
......@@ -360,8 +358,7 @@ pub fn build(b: *Builder) !void {
360358 exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
361359 exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
362360 exe_options.addOption(bool, "value_tracing", value_tracing);
363 exe_options.addOption(bool, "is_stage1", is_stage1);
364 exe_options.addOption(bool, "omit_stage2", omit_stage2);
361 exe_options.addOption(bool, "have_stage1", have_stage1);
365362 if (tracy) |tracy_path| {
366363 const client_cpp = fs.path.join(
367364 b.allocator,
......@@ -396,8 +393,7 @@ pub fn build(b: *Builder) !void {
396393 test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
397394 test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
398395 test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
399 test_cases_options.addOption(bool, "is_stage1", is_stage1);
400 test_cases_options.addOption(bool, "omit_stage2", omit_stage2);
396 test_cases_options.addOption(bool, "have_stage1", have_stage1);
401397 test_cases_options.addOption(bool, "have_llvm", enable_llvm);
402398 test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
403399 test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
......@@ -418,7 +414,7 @@ pub fn build(b: *Builder) !void {
418414 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
419415 test_cases_step.dependOn(&test_cases.step);
420416 if (!skip_stage2_tests) {
421 toolchain_step.dependOn(test_cases_step);
417 test_step.dependOn(test_cases_step);
422418 }
423419
424420 var chosen_modes: [4]builtin.Mode = undefined;
......@@ -442,11 +438,11 @@ pub fn build(b: *Builder) !void {
442438 const modes = chosen_modes[0..chosen_mode_index];
443439
444440 // 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);
446442 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
447443 fmt_step.dependOn(&fmt_build_zig.step);
448444
449 toolchain_step.dependOn(tests.addPkgTests(
445 test_step.dependOn(tests.addPkgTests(
450446 b,
451447 test_filter,
452448 "test/behavior.zig",
......@@ -457,11 +453,10 @@ pub fn build(b: *Builder) !void {
457453 skip_non_native,
458454 skip_libc,
459455 skip_stage1,
460 omit_stage2,
461 is_stage1,
456 skip_stage2_tests,
462457 ));
463458
464 toolchain_step.dependOn(tests.addPkgTests(
459 test_step.dependOn(tests.addPkgTests(
465460 b,
466461 test_filter,
467462 "lib/compiler_rt.zig",
......@@ -472,11 +467,10 @@ pub fn build(b: *Builder) !void {
472467 skip_non_native,
473468 true, // skip_libc
474469 skip_stage1,
475 omit_stage2 or true, // TODO get these all passing
476 is_stage1,
470 skip_stage2_tests or true, // TODO get these all passing
477471 ));
478472
479 toolchain_step.dependOn(tests.addPkgTests(
473 test_step.dependOn(tests.addPkgTests(
480474 b,
481475 test_filter,
482476 "lib/c.zig",
......@@ -487,37 +481,36 @@ pub fn build(b: *Builder) !void {
487481 skip_non_native,
488482 true, // skip_libc
489483 skip_stage1,
490 omit_stage2 or true, // TODO get these all passing
491 is_stage1,
484 skip_stage2_tests or true, // TODO get these all passing
492485 ));
493486
494 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
495 toolchain_step.dependOn(tests.addStandaloneTests(
487 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
488 test_step.dependOn(tests.addStandaloneTests(
496489 b,
497490 test_filter,
498491 modes,
499492 skip_non_native,
500493 enable_macos_sdk,
501494 target,
502 omit_stage2,
495 skip_stage2_tests,
503496 b.enable_darling,
504497 b.enable_qemu,
505498 b.enable_rosetta,
506499 b.enable_wasmtime,
507500 b.enable_wine,
508501 ));
509 toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, omit_stage2));
510 toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
511 toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes));
512 toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
513 toolchain_step.dependOn(tests.addTranslateCTests(b, test_filter));
502 test_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, skip_stage2_tests));
503 test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
504 test_step.dependOn(tests.addCliTests(b, test_filter, modes));
505 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
506 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
514507 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));
516509 }
517510 // 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(
521514 b,
522515 test_filter,
523516 "lib/std/std.zig",
......@@ -528,14 +521,8 @@ pub fn build(b: *Builder) !void {
528521 skip_non_native,
529522 skip_libc,
530523 skip_stage1,
531 omit_stage2 or true, // TODO get these all passing
532 is_stage1,
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);
524 true, // TODO get these all passing
525 ));
539526}
540527
541528const 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
3434mkdir build
3535cd build
3636cmake .. \
37 -DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
3837 -DCMAKE_PREFIX_PATH="$PREFIX" \
3938 -DCMAKE_BUILD_TYPE=Release \
4039 -DZIG_TARGET_TRIPLE="$TARGET" \
4140 -DZIG_TARGET_MCPU="$MCPU" \
42 -DZIG_STATIC=ON \
43 -DZIG_OMIT_STAGE2=ON
41 -DZIG_STATIC=ON
4442
4543# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
4644# so that installation and testing do not get affected by them.
......@@ -49,45 +47,30 @@ unset CXX
4947
5048make $JOBS install
5149
52# Here we rebuild zig but this time using the Zig binary we just now produced to
53# build zig1.o rather than relying on the one built with stage0. See
54# https://github.com/ziglang/zig/issues/6830 for more details.
55cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
56make $JOBS install
50stage2/bin/zig build \
51 --prefix stage3-release \
52 --search-prefix "$PREFIX" \
53 -Dstatic-llvm \
54 -Drelease \
55 -Dstrip \
56 -Dtarget="$TARGET" \
57 -Denable-stage1
5758
58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
59release/bin/zig build -p stage2 -Denable-llvm
60
61stage2/bin/zig build test-behavior
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
59stage3-release/bin/zig build test docs \
60 -Denable-macos-sdk \
61 -Dstatic-llvm \
62 --search-prefix "$PREFIX"
8063
8164if [ "${BUILD_REASON}" != "PullRequest" ]; then
82 mv ../LICENSE release/
83 mv ../zig-cache/langref.html release/
84 mv release/bin/zig release/
85 rmdir release/bin
65 mv ../LICENSE stage3-release/
66 mv ../zig-cache/langref.html stage3-release/
67 mv stage3-release/bin/zig stage3-release/
68 rmdir stage3-release/bin
8669
87 VERSION=$(release/zig version)
70 VERSION=$(stage3-release/zig version)
8871 DIRNAME="zig-macos-$ARCH-$VERSION"
8972 TARBALL="$DIRNAME.tar.xz"
90 mv release "$DIRNAME"
73 mv stage3-release "$DIRNAME"
9174 tar cfJ "$TARBALL" "$DIRNAME"
9275
9376 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
ci/azure/pipelines.yml+21-60
......@@ -27,7 +27,7 @@ jobs:
2727 vmImage: 'windows-2019'
2828 variables:
2929 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'
3131 ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'
3232 steps:
3333 - pwsh: |
......@@ -37,8 +37,8 @@ jobs:
3737 displayName: 'Install ZIG/LLVM/CLANG/LLD'
3838
3939 - pwsh: |
40 Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"
41 Set-Variable -Name ZIGINSTALLDIR -Value "${ZIGBUILDDIR}\dist"
40 Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
41 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
4242 Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"
4343
4444 function CheckLastExitCode {
......@@ -56,40 +56,22 @@ jobs:
5656 git fetch --unshallow # `git describe` won't work on a shallow repo
5757 }
5858
59 # The dev kit zip file that we have here is old, and may be incompatible with
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 `
59 & "$ZIGPREFIXPATH\bin\zig.exe" build `
6960 --prefix "$ZIGINSTALLDIR" `
7061 --search-prefix "$ZIGPREFIXPATH" `
71 -Dstage1 `
72 <# stage2 is omitted until we resolve https://github.com/ziglang/zig/issues/6485 #> `
73 -Domit-stage2 `
62 --zig-lib-dir "$ZIGLIBDIR" `
63 -Denable-stage1 `
7464 -Dstatic-llvm `
7565 -Drelease `
7666 -Dstrip `
7767 -Duse-zig-libcxx `
7868 -Dtarget=$(TARGET)
7969 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
8870 name: build
8971 displayName: 'Build'
9072
9173 - pwsh: |
92 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\build\dist"
74 Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
9375
9476 function CheckLastExitCode {
9577 if (!$?) {
......@@ -98,41 +80,21 @@ jobs:
9880 return 0
9981 }
10082
101 # Sadly, stage2 is omitted from this build to save memory on the CI server. Once self-hosted is
102 # built with itself and does not gobble as much memory, we can enable these tests.
103 #& "$ZIGINSTALLDIR\bin\zig.exe" test "..\test\behavior.zig" -fno-stage1 -fLLVM -I "..\test" 2>&1
104 #CheckLastExitCode
105
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
83 & "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
84 --search-prefix "$ZIGPREFIXPATH" `
85 -Dstatic-llvm `
86 -Dskip-non-native `
87 -Dskip-stage2-tests
10988 CheckLastExitCode
11089 name: test
11190 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
12992 - task: DownloadSecureFile@1
13093 inputs:
13194 name: aws_credentials
13295 secureFile: aws_credentials
13396
13497 - pwsh: |
135 Set-Variable -Name ZIGBUILDDIR -Value "$(Get-Location)\build"
13698 $Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH"
13799
138100 # Workaround Azure networking issue
......@@ -140,21 +102,20 @@ jobs:
140102 $Env:AWS_EC2_METADATA_DISABLED = "true"
141103 $Env:AWS_REGION = "us-west-2"
142104
143 cd "$ZIGBUILDDIR"
144 mv ../LICENSE dist/
145 mv ../zig-cache/langref.html dist/
146 mv dist/bin/zig.exe dist/
147 rmdir dist/bin
105 mv LICENSE stage3-release/
106 mv zig-cache/langref.html stage3-release/
107 mv stage3-release/bin/zig.exe stage3-release/
108 rmdir stage3-release/bin
148109
149110 # Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
150 mv dist/lib/zig dist/lib2
151 rmdir dist/lib
152 mv dist/lib2 dist/lib
111 mv stage3-release/lib/zig stage3-release/lib2
112 rmdir stage3-release/lib
113 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)
155116 Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION"
156117 Set-Variable -Name TARBALL -Value "$DIRNAME.zip"
157 mv dist "$DIRNAME"
118 mv stage3-release "$DIRNAME"
158119 7z a "$TARBALL" "$DIRNAME"
159120
160121 aws s3 cp `
ci/drone/drone.yml+21-21
......@@ -13,65 +13,65 @@ steps:
1313 commands:
1414 - ./ci/drone/linux_script_build
1515
16- name: test-1
16- name: behavior
1717 depends_on:
1818 - build
1919 image: ziglang/static-base:llvm14-aarch64-3
2020 commands:
21 - ./ci/drone/linux_script_test 1
21 - ./ci/drone/test_linux_behavior
2222
23- name: test-2
23- name: std_Debug
2424 depends_on:
2525 - build
2626 image: ziglang/static-base:llvm14-aarch64-3
2727 commands:
28 - ./ci/drone/linux_script_test 2
28 - ./ci/drone/test_linux_std_Debug
2929
30- name: test-3
30- name: std_ReleaseSafe
3131 depends_on:
3232 - build
3333 image: ziglang/static-base:llvm14-aarch64-3
3434 commands:
35 - ./ci/drone/linux_script_test 3
35 - ./ci/drone/test_linux_std_ReleaseSafe
3636
37- name: test-4
37- name: std_ReleaseFast
3838 depends_on:
3939 - build
4040 image: ziglang/static-base:llvm14-aarch64-3
4141 commands:
42 - ./ci/drone/linux_script_test 4
42 - ./ci/drone/test_linux_std_ReleaseFast
4343
44- name: test-5
44- name: std_ReleaseSmall
4545 depends_on:
4646 - build
4747 image: ziglang/static-base:llvm14-aarch64-3
4848 commands:
49 - ./ci/drone/linux_script_test 5
49 - ./ci/drone/test_linux_std_ReleaseSmall
5050
51- name: test-6
51- name: misc
5252 depends_on:
5353 - build
5454 image: ziglang/static-base:llvm14-aarch64-3
5555 commands:
56 - ./ci/drone/linux_script_test 6
56 - ./ci/drone/test_linux_misc
5757
58- name: test-7
58- name: cases
5959 depends_on:
6060 - build
6161 image: ziglang/static-base:llvm14-aarch64-3
6262 commands:
63 - ./ci/drone/linux_script_test 7
63 - ./ci/drone/test_linux_cases
6464
6565- name: finalize
6666 depends_on:
6767 - build
68 - test-1
69 - test-2
70 - test-3
71 - test-4
72 - test-5
73 - test-6
74 - test-7
68 - behavior
69 - std_Debug
70 - std_ReleaseSafe
71 - std_ReleaseFast
72 - std_ReleaseSmall
73 - misc
74 - cases
7575 image: ziglang/static-base:llvm14-aarch64-3
7676 environment:
7777 SRHT_OAUTH_TOKEN:
ci/drone/linux_script_build+8-6
......@@ -42,7 +42,6 @@ git fetch --tags
4242mkdir build
4343cd build
4444cmake .. \
45 -DCMAKE_INSTALL_PREFIX="$DISTDIR" \
4645 -DCMAKE_PREFIX_PATH="$PREFIX" \
4746 -DCMAKE_BUILD_TYPE=Release \
4847 -DCMAKE_AR="$PREFIX/bin/ar" \
......@@ -58,8 +57,11 @@ unset CC
5857unset CXX
5958samu install
6059
61# Here we rebuild Zig but this time using the Zig binary we just now produced to
62# build zig1.o rather than relying on the one built with stage0. See
63# https://github.com/ziglang/zig/issues/6830 for more details.
64cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"
65samu install
60stage2/bin/zig build \
61 --prefix "$DISTDIR" \
62 --search-prefix "$PREFIX" \
63 -Dstatic-llvm \
64 -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
77sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
88
99ZIGDIR="$(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"
1113PREFIX="$HOME/$CACHE_BASENAME"
1214
1315cd $HOME
......@@ -30,33 +32,46 @@ export TERM=dumb
3032mkdir build
3133cd build
3234cmake .. \
33 -DCMAKE_BUILD_TYPE=Release \
34 -DCMAKE_PREFIX_PATH=$PREFIX \
35 "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
36 -DZIG_STATIC=ON \
37 -DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \
38 -GNinja
35 -DCMAKE_BUILD_TYPE=Release \
36 -DCMAKE_PREFIX_PATH=$PREFIX \
37 -DZIG_TARGET_TRIPLE="$TARGET" \
38 -DZIG_TARGET_MCPU="$MCPU" \
39 -DZIG_STATIC=ON \
40 -GNinja
3941samu install
4042
41# TODO ld.lld: error: undefined symbol: main
42# >>> referenced by crt1_c.c:75 (/usr/src/lib/csu/amd64/crt1_c.c:75)
43# >>> /usr/lib/crt1.o:(_start)
44#release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test
43# TODO: eliminate this workaround. Without this, zig does not end up passing
44# -isystem /usr/include when building libc++, resulting in #include <sys/endian.h>
45# "file not found" errors.
46stage2/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
4657# Here we skip some tests to save time.
47release/bin/zig build test -Dskip-stage1 -Dskip-non-native
58stage3-release/bin/zig build test docs \
59 -Dstatic-llvm \
60 --search-prefix "$PREFIX" \
61 -Dskip-stage1 \
62 -Dskip-non-native
4863
4964if [ -f ~/.s3cfg ]; then
50 mv ../LICENSE release/
51 mv ../zig-cache/langref.html release/
52 mv release/bin/zig release/
53 rmdir release/bin
65 mv ../LICENSE stage3-release/
66 mv ../zig-cache/langref.html stage3-release/
67 mv stage3-release/bin/zig stage3-release/
68 rmdir stage3-release/bin
5469
5570 GITBRANCH=$(basename $GITHUB_REF)
56 VERSION=$(release/zig version)
71 VERSION=$(stage3-release/zig version)
5772 DIRNAME="zig-freebsd-x86_64-$VERSION"
5873 TARBALL="$DIRNAME.tar.xz"
59 mv release "$DIRNAME"
74 mv stage3-release "$DIRNAME"
6075 tar cfJ "$TARBALL" "$DIRNAME"
6176
6277 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:
99 path: /workspace
1010
1111steps:
12- name: test
13 image: ci/debian-amd64:11.1-6
12- name: test_stage3_debug
13 image: ci/debian-amd64:11.1-7
1414 commands:
15 - ./ci/zinc/linux_test.sh
15 - ./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
1722- name: package
1823 depends_on:
19 - test
24 - test_stage3_debug
25 - test_stage3_release
2026 when:
2127 branch:
2228 - master
2329 event:
2430 - push
25 image: ci/debian-amd64:11.1-6
31 image: ci/debian-amd64:11.1-7
2632 environment:
2733 AWS_ACCESS_KEY_ID:
2834 from_secret: AWS_ACCESS_KEY_ID
ci/zinc/linux_base.sh+4
......@@ -25,3 +25,7 @@ DEBUG_STAGING="$WORKSPACE/_debug/staging"
2525RELEASE_STAGING="$WORKSPACE/_release/staging"
2626
2727export 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 @@
22
33. ./ci/zinc/linux_base.sh
44
5cp LICENSE $RELEASE_STAGING/
6cp zig-cache/langref.html $RELEASE_STAGING/docs/
7
85# Remove the unnecessary bin dir in $prefix/bin/zig
96mv $RELEASE_STAGING/bin/zig $RELEASE_STAGING/
107rmdir $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 {
285285 link_objects: []const []const u8,
286286 target_str: ?[]const u8,
287287 link_libc: bool,
288 backend_stage1: bool,
288289 link_mode: ?std.builtin.LinkMode,
289290 disable_cache: bool,
290291 verbose_cimport: bool,
......@@ -554,6 +555,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
554555 var link_mode: ?std.builtin.LinkMode = null;
555556 var disable_cache = false;
556557 var verbose_cimport = false;
558 var backend_stage1 = false;
557559
558560 const source_token = while (true) {
559561 const content_tok = try eatToken(tokenizer, Token.Id.Content);
......@@ -586,6 +588,8 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
586588 link_libc = true;
587589 } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
588590 link_mode = .Dynamic;
591 } else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
592 backend_stage1 = true;
589593 } else if (mem.eql(u8, end_tag_name, "code_end")) {
590594 _ = try eatToken(tokenizer, Token.Id.BracketClose);
591595 break content_tok;
......@@ -609,6 +613,7 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
609613 .link_objects = link_objects.toOwnedSlice(),
610614 .target_str = target_str,
611615 .link_libc = link_libc,
616 .backend_stage1 = backend_stage1,
612617 .link_mode = link_mode,
613618 .disable_cache = disable_cache,
614619 .verbose_cimport = verbose_cimport,
......@@ -1187,6 +1192,9 @@ fn printShell(out: anytype, shell_content: []const u8) !void {
11871192 try out.writeAll("</samp></pre></figure>");
11881193}
11891194
1195// Override this to skip to later tests
1196const debug_start_line = 0;
1197
11901198fn genHtml(
11911199 allocator: Allocator,
11921200 tokenizer: *Tokenizer,
......@@ -1266,6 +1274,13 @@ fn genHtml(
12661274 continue;
12671275 }
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
12691284 const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
12701285 const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
12711286 const tmp_source_file_name = try fs.path.join(
......@@ -1311,6 +1326,10 @@ fn genHtml(
13111326 try build_args.append("-lc");
13121327 try shell_out.print("-lc ", .{});
13131328 }
1329 if (code.backend_stage1) {
1330 try build_args.append("-fstage1");
1331 try shell_out.print("-fstage1", .{});
1332 }
13141333 const target = try std.zig.CrossTarget.parse(.{
13151334 .arch_os_abi = code.target_str orelse "native",
13161335 });
......@@ -1443,6 +1462,10 @@ fn genHtml(
14431462 try test_args.append("-lc");
14441463 try shell_out.print("-lc ", .{});
14451464 }
1465 if (code.backend_stage1) {
1466 try test_args.append("-fstage1");
1467 try shell_out.print("-fstage1", .{});
1468 }
14461469 if (code.target_str) |triple| {
14471470 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
14481471 try shell_out.print("-target {s} ", .{triple});
......@@ -1490,6 +1513,14 @@ fn genHtml(
14901513 try shell_out.print("-O {s} ", .{@tagName(code.mode)});
14911514 },
14921515 }
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 }
14931524 const result = try ChildProcess.exec(.{
14941525 .allocator = allocator,
14951526 .argv = test_args.items,
doc/langref.html.in+69-109
......@@ -1188,6 +1188,7 @@ test "this will be skipped" {
11881188 (The evented IO mode is enabled using the <kbd>--test-evented-io</kbd> command line parameter.)
11891189 </p>
11901190 {#code_begin|test|async_skip#}
1191 {#backend_stage1#}
11911192const std = @import("std");
11921193
11931194test "async skip test" {
......@@ -2768,7 +2769,7 @@ test "comptime @intToPtr" {
27682769 }
27692770}
27702771 {#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#}
27722773 {#header_open|volatile#}
27732774 <p>Loads and stores are assumed to not have side effects. If a given load or store
27742775 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;
28622863test "global variable alignment" {
28632864 try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
28642865 try expect(@TypeOf(&foo) == *align(4) u8);
2865 const as_pointer_to_array: *[1]u8 = &foo;
2866 const as_slice: []u8 = as_pointer_to_array;
2867 try expect(@TypeOf(as_slice) == []align(4) u8);
2866 const as_pointer_to_array: *align(4) [1]u8 = &foo;
2867 const as_slice: []align(4) u8 = as_pointer_to_array;
2868 const as_unaligned_slice: []u8 = as_slice;
2869 try expect(as_unaligned_slice[0] == 100);
28682870}
28692871
2870fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
2872fn derp() align(@sizeOf(usize) * 2) i32 {
2873 return 1234;
2874}
28712875fn noop1() align(1) void {}
28722876fn noop4() align(4) void {}
28732877
28742878test "function alignment" {
28752879 try expect(derp() == 1234);
2876 try expect(@TypeOf(noop1) == fn() align(1) void);
2877 try expect(@TypeOf(noop4) == fn() align(4) void);
2880 try expect(@TypeOf(noop1) == fn () align(1) void);
2881 try expect(@TypeOf(noop4) == fn () align(4) void);
28782882 noop1();
28792883 noop4();
28802884}
......@@ -3336,6 +3340,7 @@ fn doTheTest() !void {
33363340 Zig allows the address to be taken of a non-byte-aligned field:
33373341 </p>
33383342 {#code_begin|test|pointer_to_non-byte_aligned_field#}
3343 {#backend_stage1#}
33393344const std = @import("std");
33403345const expect = std.testing.expect;
33413346
......@@ -3391,7 +3396,8 @@ fn bar(x: *const u3) u3 {
33913396 <p>
33923397 Pointers to non-ABI-aligned fields share the same address as the other fields within their host integer:
33933398 </p>
3394 {#code_begin|test|pointer_to_non-bit_aligned_field#}
3399 {#code_begin|test|packed_struct_field_addrs#}
3400 {#backend_stage1#}
33953401const std = @import("std");
33963402const expect = std.testing.expect;
33973403
......@@ -3407,7 +3413,7 @@ var bit_field = BitField{
34073413 .c = 3,
34083414};
34093415
3410test "pointer to non-bit-aligned field" {
3416test "pointers of sub-byte-aligned fields share addresses" {
34113417 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b));
34123418 try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c));
34133419}
......@@ -3438,20 +3444,22 @@ test "pointer to non-bit-aligned field" {
34383444}
34393445 {#code_end#}
34403446 <p>
3441 Packed structs have 1-byte alignment. However if you have an overaligned pointer to a packed struct,
3442 Zig should correctly understand the alignment of fields. However there is
3443 <a href="https://github.com/ziglang/zig/issues/1994">a bug</a>:
3447 Packed structs have the same alignment as their backing integer, however, overaligned
3448 pointers to packed structs can override this:
34443449 </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
34463454const S = packed struct {
34473455 a: u32,
34483456 b: u32,
34493457};
34503458test "overaligned pointer to packed struct" {
3451 var foo: S align(4) = undefined;
3459 var foo: S align(4) = .{ .a = 1, .b = 2 };
34523460 const ptr: *align(4) S = &foo;
34533461 const ptr_to_b: *u32 = &ptr.b;
3454 _ = ptr_to_b;
3462 try expect(ptr_to_b.* == 2);
34553463}
34563464 {#code_end#}
34573465 <p>When this bug is fixed, the above test in the documentation will unexpectedly pass, which will
......@@ -3698,7 +3706,7 @@ test "@tagName" {
36983706 <p>
36993707 By default, enums are not guaranteed to be compatible with the C ABI:
37003708 </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'#}
37023710const Foo = enum { a, b, c };
37033711export fn entry(foo: Foo) void { _ = foo; }
37043712 {#code_end#}
......@@ -4004,7 +4012,7 @@ fn makeNumber() Number {
40044012 This is typically used for type safety when interacting with C code that does not expose struct details.
40054013 Example:
40064014 </p>
4007 {#code_begin|test_err|expected type '*Derp', found '*Wat'#}
4015 {#code_begin|test_err|expected type '*test.Derp', found '*test.Wat'#}
40084016const Derp = opaque {};
40094017const Wat = opaque {};
40104018
......@@ -4203,7 +4211,7 @@ test "switch on tagged union" {
42034211 When a {#syntax#}switch{#endsyntax#} expression does not have an {#syntax#}else{#endsyntax#} clause,
42044212 it must exhaustively list all the possible values. Failure to do so is a compile error:
42054213 </p>
4206 {#code_begin|test_err|not handled in switch#}
4214 {#code_begin|test_err|unhandled enumeration value#}
42074215const Color = enum {
42084216 auto,
42094217 off,
......@@ -5026,17 +5034,9 @@ test "function" {
50265034 try expect(do_op(sub2, 5, 6) == -1);
50275035}
50285036 {#code_end#}
5029 <p>Function values are like pointers:</p>
5030 {#code_begin|obj#}
5031const assert = @import("std").debug.assert;
5032
5033comptime {
5034 assert(@TypeOf(foo) == fn()void);
5035 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
5036}
5037
5038fn foo() void { }
5039 {#code_end#}
5037 <p>There is a difference between a function <em>body</em> and a function <em>pointer</em>.
5038 Function bodies are {#link|comptime#}-only types while function {#link|Pointers#} may be
5039 runtime-known.</p>
50405040 {#header_open|Pass-by-value Parameters#}
50415041 <p>
50425042 Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters
......@@ -6123,10 +6123,11 @@ test "float widening" {
61236123 two choices about the coercion.
61246124 </p>
61256125 <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>
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>
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>
61286128 </ul>
61296129 {#code_begin|test_err#}
6130 {#backend_stage1#}
61306131// Compile time coercion of float to int
61316132test "implicit cast to comptime_int" {
61326133 var f: f32 = 54.0 / 5;
......@@ -6302,19 +6303,6 @@ test "coercion between unions and enums" {
63026303 {#code_end#}
63036304 {#see_also|union|enum#}
63046305 {#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#}
63186306 {#header_open|Type Coercion: undefined#}
63196307 <p>{#link|undefined#} can be cast to any type.</p>
63206308 {#header_close#}
......@@ -6467,7 +6455,6 @@ test "peer type resolution: *const T and ?*T" {
64676455 <li>An {#link|enum#} with only 1 tag.</li>
64686456 <li>A {#link|struct#} with all fields being zero bit types.</li>
64696457 <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>
64716458 </ul>
64726459 <p>
64736460 These types can only ever have one possible value, and thus
......@@ -6527,7 +6514,7 @@ test "turn HashMap into a set with void" {
65276514 <p>
65286515 Expressions of type {#syntax#}void{#endsyntax#} are the only ones whose value can be ignored. For example:
65296516 </p>
6530 {#code_begin|test_err|expression value is ignored#}
6517 {#code_begin|test_err|ignored#}
65316518test "ignoring expression value" {
65326519 foo();
65336520}
......@@ -6553,37 +6540,6 @@ fn foo() i32 {
65536540}
65546541 {#code_end#}
65556542 {#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#}
65876543 {#header_close#}
65886544
65896545 {#header_open|Result Location Semantics#}
......@@ -6666,7 +6622,7 @@ fn gimmeTheBiggerInteger(a: u64, b: u64) u64 {
66666622 <p>
66676623 For example, if we were to introduce another function to the above snippet:
66686624 </p>
6669 {#code_begin|test_err|values of type 'type' must be comptime known#}
6625 {#code_begin|test_err|unable to resolve comptime value#}
66706626fn max(comptime T: type, a: T, b: T) T {
66716627 return if (a > b) a else b;
66726628}
......@@ -6692,7 +6648,7 @@ fn foo(condition: bool) void {
66926648 <p>
66936649 For example:
66946650 </p>
6695 {#code_begin|test_err|operator not allowed for type 'bool'#}
6651 {#code_begin|test_err|operator > not allowed for type 'bool'#}
66966652fn max(comptime T: type, a: T, b: T) T {
66976653 return if (a > b) a else b;
66986654}
......@@ -6837,7 +6793,7 @@ fn performFn(start_value: i32) i32 {
68376793 use a {#syntax#}comptime{#endsyntax#} expression to guarantee that the expression will be evaluated at compile-time.
68386794 If this cannot be accomplished, the compiler will emit an error. For example:
68396795 </p>
6840 {#code_begin|test_err|unable to evaluate constant expression#}
6796 {#code_begin|test_err|comptime call of extern function#}
68416797extern fn exit() noreturn;
68426798
68436799test "foo" {
......@@ -6889,7 +6845,7 @@ test "fibonacci" {
68896845 <p>
68906846 Imagine if we had forgotten the base case of the recursive function and tried to run the tests:
68916847 </p>
6892 {#code_begin|test_err|operation caused overflow#}
6848 {#code_begin|test_err|overflow of integer type#}
68936849const expect = @import("std").testing.expect;
68946850
68956851fn fibonacci(index: u32) u32 {
......@@ -6913,7 +6869,8 @@ test "fibonacci" {
69136869 But what would have happened if we used a signed integer?
69146870 </p>
69156871 {#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
69186875fn fibonacci(index: i32) i32 {
69196876 //if (index < 2) return index;
......@@ -6922,7 +6879,7 @@ fn fibonacci(index: i32) i32 {
69226879
69236880test "fibonacci" {
69246881 comptime {
6925 try expect(fibonacci(7) == 13);
6882 try assert(fibonacci(7) == 13);
69266883 }
69276884}
69286885 {#code_end#}
......@@ -6935,8 +6892,8 @@ test "fibonacci" {
69356892 <p>
69366893 What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line?
69376894 </p>
6938 {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#}
6939const expect = @import("std").testing.expect;
6895 {#code_begin|test_err|reached unreachable#}
6896const assert = @import("std").debug.assert;
69406897
69416898fn fibonacci(index: i32) i32 {
69426899 if (index < 2) return index;
......@@ -6945,16 +6902,10 @@ fn fibonacci(index: i32) i32 {
69456902
69466903test "fibonacci" {
69476904 comptime {
6948 try expect(fibonacci(7) == 99999);
6905 try assert(fibonacci(7) == 99999);
69496906 }
69506907}
69516908 {#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
69596910 <p>
69606911 At container level (outside of any function), all expressions are implicitly
......@@ -7280,6 +7231,7 @@ pub fn main() void {
72807231 </p>
72817232 {#code_begin|exe#}
72827233 {#target_linux_x86_64#}
7234 {#backend_stage1#}
72837235pub fn main() noreturn {
72847236 const msg = "hello world\n";
72857237 _ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len);
......@@ -7497,6 +7449,7 @@ test "global assembly" {
74977449 or resumer (in the case of subsequent suspensions).
74987450 </p>
74997451 {#code_begin|test|suspend_no_resume#}
7452 {#backend_stage1#}
75007453const std = @import("std");
75017454const expect = std.testing.expect;
75027455
......@@ -7524,6 +7477,7 @@ fn func() void {
75247477 {#link|@frame#} provides access to the async function frame pointer.
75257478 </p>
75267479 {#code_begin|test|async_suspend_block#}
7480 {#backend_stage1#}
75277481const std = @import("std");
75287482const expect = std.testing.expect;
75297483
......@@ -7562,6 +7516,7 @@ fn testSuspendBlock() void {
75627516 never returns to its resumer and continues executing.
75637517 </p>
75647518 {#code_begin|test|resume_from_suspend#}
7519 {#backend_stage1#}
75657520const std = @import("std");
75667521const expect = std.testing.expect;
75677522
......@@ -7598,6 +7553,7 @@ fn testResumeFromSuspend(my_result: *i32) void {
75987553 and the return value of the async function would be lost.
75997554 </p>
76007555 {#code_begin|test|async_await#}
7556 {#backend_stage1#}
76017557const std = @import("std");
76027558const expect = std.testing.expect;
76037559
......@@ -7642,6 +7598,7 @@ fn func() void {
76427598 return value directly from the target function's frame.
76437599 </p>
76447600 {#code_begin|test|async_await_sequence#}
7601 {#backend_stage1#}
76457602const std = @import("std");
76467603const expect = std.testing.expect;
76477604
......@@ -7695,6 +7652,7 @@ fn seq(c: u8) void {
76957652 {#syntax#}async{#endsyntax#}/{#syntax#}await{#endsyntax#} usage:
76967653 </p>
76977654 {#code_begin|exe|async#}
7655 {#backend_stage1#}
76987656const std = @import("std");
76997657const Allocator = std.mem.Allocator;
77007658
......@@ -7773,6 +7731,7 @@ fn readFile(allocator: Allocator, filename: []const u8) ![]u8 {
77737731 observe the same behavior, with one tiny difference:
77747732 </p>
77757733 {#code_begin|exe|blocking#}
7734 {#backend_stage1#}
77767735const std = @import("std");
77777736const Allocator = std.mem.Allocator;
77787737
......@@ -7910,6 +7869,7 @@ comptime {
79107869 {#syntax#}await{#endsyntax#} will copy the result from {#syntax#}result_ptr{#endsyntax#}.
79117870 </p>
79127871 {#code_begin|test|async_struct_field_fn_pointer#}
7872 {#backend_stage1#}
79137873const std = @import("std");
79147874const expect = std.testing.expect;
79157875
......@@ -8677,6 +8637,7 @@ test "decl access by string" {
86778637 allows one to, for example, heap-allocate an async function frame:
86788638 </p>
86798639 {#code_begin|test|heap_allocated_frame#}
8640 {#backend_stage1#}
86808641const std = @import("std");
86818642
86828643test "heap allocated frame" {
......@@ -9423,12 +9384,6 @@ const std = @import("std");
94239384const expect = std.testing.expect;
94249385
94259386test "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
94329387 const value = @Vector(4, i32){ 1, -1, 1, -1 };
94339388 const result = value > @splat(4, @as(i32, 0));
94349389 // result is { true, false, true, false };
......@@ -9938,7 +9893,7 @@ pub fn main() void {
99389893 {#header_close#}
99399894 {#header_open|Index out of Bounds#}
99409895 <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#}
99429897comptime {
99439898 const array: [5]u8 = "hello".*;
99449899 const garbage = array[5];
......@@ -9959,9 +9914,9 @@ fn foo(x: []const u8) u8 {
99599914 {#header_close#}
99609915 {#header_open|Cast Negative Number to Unsigned Integer#}
99619916 <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'#}
99639918comptime {
9964 const value: i32 = -1;
9919 var value: i32 = -1;
99659920 const unsigned = @intCast(u32, value);
99669921 _ = unsigned;
99679922}
......@@ -9982,7 +9937,7 @@ pub fn main() void {
99829937 {#header_close#}
99839938 {#header_open|Cast Truncates Data#}
99849939 <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'#}
99869941comptime {
99879942 const spartan_count: u16 = 300;
99889943 const byte = @intCast(u8, spartan_count);
......@@ -10017,7 +9972,7 @@ pub fn main() void {
100179972 <li>{#link|@divExact#} (division)</li>
100189973 </ul>
100199974 <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'#}
100219976comptime {
100229977 var byte: u8 = 255;
100239978 byte += 1;
......@@ -10118,6 +10073,7 @@ test "wraparound addition and subtraction" {
1011810073 {#header_open|Exact Left Shift Overflow#}
1011910074 <p>At compile-time:</p>
1012010075 {#code_begin|test_err|operation caused overflow#}
10076 {#backend_stage1#}
1012110077comptime {
1012210078 const x = @shlExact(@as(u8, 0b01010101), 2);
1012310079 _ = x;
......@@ -10137,6 +10093,7 @@ pub fn main() void {
1013710093 {#header_open|Exact Right Shift Overflow#}
1013810094 <p>At compile-time:</p>
1013910095 {#code_begin|test_err|exact shift shifted out 1 bits#}
10096 {#backend_stage1#}
1014010097comptime {
1014110098 const x = @shrExact(@as(u8, 0b10101010), 2);
1014210099 _ = x;
......@@ -10200,6 +10157,7 @@ pub fn main() void {
1020010157 {#header_open|Exact Division Remainder#}
1020110158 <p>At compile-time:</p>
1020210159 {#code_begin|test_err|exact division had a remainder#}
10160 {#backend_stage1#}
1020310161comptime {
1020410162 const a: u32 = 10;
1020510163 const b: u32 = 3;
......@@ -10302,7 +10260,7 @@ fn getNumberOrFail() !i32 {
1030210260 {#header_close#}
1030310261 {#header_open|Invalid Error Code#}
1030410262 <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#}
1030610264comptime {
1030710265 const err = error.AnError;
1030810266 const number = @errorToInt(err) + 10;
......@@ -10324,7 +10282,7 @@ pub fn main() void {
1032410282 {#header_close#}
1032510283 {#header_open|Invalid Enum Cast#}
1032610284 <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'#}
1032810286const Foo = enum {
1032910287 a,
1033010288 b,
......@@ -10356,7 +10314,7 @@ pub fn main() void {
1035610314
1035710315 {#header_open|Invalid Error Set Cast#}
1035810316 <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}'#}
1036010318const Set1 = error{
1036110319 A,
1036210320 B,
......@@ -10417,7 +10375,7 @@ fn foo(bytes: []u8) u32 {
1041710375 {#header_close#}
1041810376 {#header_open|Wrong Union Field Access#}
1041910377 <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#}
1042110379comptime {
1042210380 var f = Foo{ .int = 42 };
1042310381 f.float = 12.34;
......@@ -10509,6 +10467,7 @@ fn bar(f: *Foo) void {
1050910467 </p>
1051010468 <p>At compile-time:</p>
1051110469 {#code_begin|test_err|null pointer casted to type#}
10470 {#backend_stage1#}
1051210471comptime {
1051310472 const opt_ptr: ?*i32 = null;
1051410473 const ptr = @ptrCast(*i32, opt_ptr);
......@@ -10551,7 +10510,8 @@ const expect = std.testing.expect;
1055110510
1055210511test "using an allocator" {
1055310512 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();
1055510515 const result = try concat(allocator, "foo", "bar");
1055610516 try expect(std.mem.eql(u8, "foobar", result));
1055710517}
......@@ -10647,7 +10607,7 @@ pub fn main() !void {
1064710607 <p>String literals such as {#syntax#}"foo"{#endsyntax#} are in the global constant data section.
1064810608 This is why it is an error to pass a string literal to a mutable slice, like this:
1064910609 </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'#}
1065110611fn foo(s: []u8) void {
1065210612 _ = s;
1065310613}
lib/std/builtin.zig+1-1
......@@ -866,7 +866,7 @@ pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
866866
867867pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
868868 @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 });
870870}
871871
872872pub noinline fn returnError(st: *StackTrace) void {
lib/std/coff.zig+1-1
......@@ -383,7 +383,7 @@ const OptionalHeader = struct {
383383 image_base: u64,
384384};
385385
386const DebugDirectoryEntry = packed struct {
386const DebugDirectoryEntry = extern struct {
387387 characteristiccs: u32,
388388 time_date_stamp: u32,
389389 major_version: u16,
lib/std/os/linux/bpf.zig+1-1
......@@ -458,7 +458,7 @@ pub const Insn = packed struct {
458458 else
459459 ImmOrReg{ .imm = src };
460460
461 const src_type = switch (imm_or_reg) {
461 const src_type: u8 = switch (imm_or_reg) {
462462 .imm => K,
463463 .reg => X,
464464 };
lib/std/os/windows.zig+1-1
......@@ -1802,7 +1802,7 @@ pub const PathSpace = struct {
18021802 data: [PATH_MAX_WIDE:0]u16,
18031803 len: usize,
18041804
1805 pub fn span(self: PathSpace) [:0]const u16 {
1805 pub fn span(self: *const PathSpace) [:0]const u16 {
18061806 return self.data[0..self.len :0];
18071807 }
18081808};
src/Compilation.zig+8-48
......@@ -1040,24 +1040,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
10401040 const comp = try arena.create(Compilation);
10411041 const root_name = try arena.dupeZ(u8, options.root_name);
10421042
1043 const use_stage1 = options.use_stage1 orelse blk: {
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 };
1043 const use_stage1 = options.use_stage1 orelse false;
10611044
10621045 const cache_mode = if (use_stage1 and !options.disable_lld_caching)
10631046 CacheMode.whole
......@@ -1248,7 +1231,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
12481231 break :blk lm;
12491232 } 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
12531236 const libc_dirs = try detectLibCIncludeDirs(
12541237 arena,
......@@ -2213,8 +2196,7 @@ pub fn update(comp: *Compilation) !void {
22132196 comp.c_object_work_queue.writeItemAssumeCapacity(key);
22142197 }
22152198
2216 const use_stage1 = build_options.omit_stage2 or
2217 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
2199 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
22182200 if (comp.bin_file.options.module) |module| {
22192201 module.compile_log_text.shrinkAndFree(module.gpa, 0);
22202202 module.generation += 1;
......@@ -2390,8 +2372,7 @@ fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
23902372 };
23912373 comp.link_error_flags = comp.bin_file.errorFlags();
23922374
2393 const use_stage1 = build_options.omit_stage2 or
2394 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
2375 const use_stage1 = build_options.have_stage1 and comp.bin_file.options.use_stage1;
23952376 if (!use_stage1) {
23962377 if (comp.bin_file.options.module) |module| {
23972378 try link.File.C.flushEmitH(module);
......@@ -2849,7 +2830,7 @@ pub fn performAllTheWork(
28492830 comp.work_queue_wait_group.reset();
28502831 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
28542835 {
28552836 const astgen_frame = tracy.namedFrame("astgen");
......@@ -2952,9 +2933,6 @@ pub fn performAllTheWork(
29522933fn processOneJob(comp: *Compilation, job: Job) !void {
29532934 switch (job) {
29542935 .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
29582936 const module = comp.bin_file.options.module.?;
29592937 const decl = module.declPtr(decl_index);
29602938
......@@ -2989,9 +2967,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
29892967 }
29902968 },
29912969 .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
29952970 const named_frame = tracy.namedFrame("codegen_func");
29962971 defer named_frame.end();
29972972
......@@ -3002,9 +2977,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
30022977 };
30032978 },
30042979 .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
30082980 const module = comp.bin_file.options.module.?;
30092981 const decl = module.declPtr(decl_index);
30102982
......@@ -3063,9 +3035,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
30633035 }
30643036 },
30653037 .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
30693038 const module = comp.bin_file.options.module.?;
30703039 module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {
30713040 error.OutOfMemory => return error.OutOfMemory,
......@@ -3073,9 +3042,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
30733042 };
30743043 },
30753044 .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
30793045 const named_frame = tracy.namedFrame("update_embed_file");
30803046 defer named_frame.end();
30813047
......@@ -3086,9 +3052,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
30863052 };
30873053 },
30883054 .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
30923055 const named_frame = tracy.namedFrame("update_line_number");
30933056 defer named_frame.end();
30943057
......@@ -3107,9 +3070,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
31073070 };
31083071 },
31093072 .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
31133073 const named_frame = tracy.namedFrame("analyze_pkg");
31143074 defer named_frame.end();
31153075
......@@ -3455,7 +3415,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
34553415 var man = comp.obtainCObjectCacheManifest();
34563416 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
34603420 man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
34613421 man.hash.add(use_stage1);
......@@ -4770,7 +4730,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
47704730
47714731 const target = comp.getTarget();
47724732 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
47754735 const zig_backend: std.builtin.CompilerBackend = blk: {
47764736 if (use_stage1) break :blk .stage1;
......@@ -5057,7 +5017,7 @@ fn buildOutputFromZig(
50575017 .link_mode = .Static,
50585018 .function_sections = true,
50595019 .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,
50615021 .want_sanitize_c = false,
50625022 .want_stack_check = false,
50635023 .want_stack_protector = 0,
src/Module.zig+4
......@@ -6529,3 +6529,7 @@ pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u
65296529
65306530 mod.global_assembly.putAssumeCapacityNoClobber(decl_index, duped_source);
65316531}
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(
2735827358 src: LazySrcLoc,
2735927359 ty: Type,
2736027360) 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
2736427361 switch (ty.zigTypeTag()) {
2736527362 .Struct => return sema.resolveStructLayout(block, src, ty),
2736627363 .Union => return sema.resolveUnionLayout(block, src, ty),
......@@ -27699,8 +27696,6 @@ fn resolveUnionFully(
2769927696}
2770027697
2770127698pub 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");
2770427699 switch (ty.tag()) {
2770527700 .@"struct" => {
2770627701 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -29323,8 +29318,6 @@ fn typePtrOrOptionalPtrTy(
2932329318/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
2932429319/// elsewhere in value.zig
2932529320pub 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");
2932829321 return switch (ty.tag()) {
2932929322 .u1,
2933029323 .u8,
src/codegen/llvm.zig+3
......@@ -1103,6 +1103,7 @@ pub const Object = struct {
11031103 }
11041104 llvm_global.setUnnamedAddr(.False);
11051105 llvm_global.setLinkage(.External);
1106 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
11061107 if (self.di_map.get(decl)) |di_node| {
11071108 if (try decl.isFunction()) {
11081109 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
......@@ -1128,6 +1129,7 @@ pub const Object = struct {
11281129 const exp_name = exports[0].options.name;
11291130 llvm_global.setValueName2(exp_name.ptr, exp_name.len);
11301131 llvm_global.setUnnamedAddr(.False);
1132 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
11311133 if (self.di_map.get(decl)) |di_node| {
11321134 if (try decl.isFunction()) {
11331135 const di_func = @ptrCast(*llvm.DISubprogram, di_node);
......@@ -1187,6 +1189,7 @@ pub const Object = struct {
11871189 defer module.gpa.free(fqn);
11881190 llvm_global.setValueName2(fqn.ptr, fqn.len);
11891191 llvm_global.setLinkage(.Internal);
1192 if (module.wantDllExports()) llvm_global.setDLLStorageClass(.Default);
11901193 llvm_global.setUnnamedAddr(.True);
11911194 if (decl.val.castTag(.variable)) |variable| {
11921195 const single_threaded = module.comp.bin_file.options.single_threaded;
src/codegen/llvm/bindings.zig+9
......@@ -223,6 +223,9 @@ pub const Value = opaque {
223223 pub const setInitializer = LLVMSetInitializer;
224224 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
226229 pub const addCase = LLVMAddCase;
227230 extern fn LLVMAddCase(Switch: *const Value, OnVal: *const Value, Dest: *const BasicBlock) void;
228231
......@@ -1482,6 +1485,12 @@ pub const CallAttr = enum(c_int) {
14821485 AlwaysInline,
14831486};
14841487
1488pub const DLLStorageClass = enum(c_uint) {
1489 Default,
1490 DLLImport,
1491 DLLExport,
1492};
1493
14851494pub const address_space = struct {
14861495 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@;
88pub const enable_link_snapshots: bool = false;
99pub const enable_tracy = false;
1010pub const value_tracing = false;
11pub const is_stage1 = true;
11pub const have_stage1 = true;
1212pub 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 {
279279 return &(try MachO.openPath(allocator, options)).base;
280280 }
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;
283283 if (use_stage1 or options.emit == null) {
284284 return switch (options.target.ofmt) {
285285 .coff => &(try Coff.createEmpty(allocator, options)).base,
......@@ -817,7 +817,7 @@ pub const File = struct {
817817 // If there is no Zig code to compile, then we should skip flushing the output file
818818 // because it will not be part of the linker line anyway.
819819 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;
821821 if (use_stage1) {
822822 const obj_basename = try std.zig.binNameAlloc(arena, .{
823823 .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 {
411411 };
412412
413413 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;
415415 if (use_llvm and !use_stage1) {
416416 self.llvm_object = try LlvmObject.create(gpa, options);
417417 }
......@@ -949,7 +949,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
949949 // If there is no Zig code to compile, then we should skip flushing the output file because it
950950 // will not be part of the linker line anyway.
951951 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;
953953 if (use_stage1) {
954954 const obj_basename = try std.zig.binNameAlloc(arena, .{
955955 .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 {
328328 .page_size = page_size,
329329 };
330330 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;
332332 if (use_llvm and !use_stage1) {
333333 self.llvm_object = try LlvmObject.create(gpa, options);
334334 }
src/link/MachO.zig+2-2
......@@ -272,7 +272,7 @@ pub const Export = struct {
272272pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {
273273 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;
276276 if (use_stage1 or options.emit == null) {
277277 return createEmpty(allocator, options);
278278 }
......@@ -363,7 +363,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
363363 const cpu_arch = options.target.cpu.arch;
364364 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
365365 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
368368 const self = try gpa.create(MachO);
369369 errdefer gpa.destroy(self);
src/link/Wasm.zig+3-3
......@@ -356,7 +356,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
356356 }
357357
358358 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;
360360 if (use_llvm and !use_stage1) {
361361 self.llvm_object = try LlvmObject.create(gpa, options);
362362 }
......@@ -2593,7 +2593,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
25932593 // If there is no Zig code to compile, then we should skip flushing the output file because it
25942594 // will not be part of the linker line anyway.
25952595 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;
25972597 if (use_stage1) {
25982598 const obj_basename = try std.zig.binNameAlloc(arena, .{
25992599 .root_name = self.base.options.root_name,
......@@ -2803,7 +2803,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
28032803 if (self.base.options.module) |mod| {
28042804 // when we use stage1, we use the exports that stage1 provided us.
28052805 // 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;
28072807 if (use_stage1) {
28082808 for (comp.export_symbol_names.items) |symbol_name| {
28092809 try argv.append(try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}));
src/main.zig+1-1
......@@ -2989,7 +2989,7 @@ fn buildOutputType(
29892989 return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));
29902990 }
29912991 if (arg_mode == .translate_c) {
2992 const stage1_mode = use_stage1 orelse build_options.is_stage1;
2992 const stage1_mode = use_stage1 orelse false;
29932993 return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);
29942994 }
29952995
src/stage1.zig+1-1
......@@ -18,7 +18,7 @@ const target_util = @import("target.zig");
1818
1919comptime {
2020 assert(builtin.link_libc);
21 assert(build_options.is_stage1);
21 assert(build_options.have_stage1);
2222 assert(build_options.have_llvm);
2323 if (!builtin.is_test) {
2424 @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;
2525const hr = "=" ** 80;
2626
2727test {
28 if (build_options.is_stage1) {
28 if (build_options.have_stage1) {
2929 @import("stage1.zig").os_init();
3030 }
3131
test/cases/safety/empty slice with sentinel out of bounds.zig +1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
44 _ = 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")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);
test/cases/safety/out of bounds slice access.zig +3-3
......@@ -2,20 +2,20 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
44 _ = 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")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);
99}
1010pub fn main() !void {
11 const a = [_]i32{1, 2, 3, 4};
11 const a = [_]i32{ 1, 2, 3, 4 };
1212 baz(bar(&a));
1313 return error.TestFailed;
1414}
1515fn bar(a: []const i32) i32 {
1616 return a[4];
1717}
18fn baz(_: i32) void { }
18fn baz(_: i32) void {}
1919// run
2020// backend=llvm
2121// target=native
test/cases/safety/slice with sentinel out of bounds - runtime len.zig +1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
44 _ = 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")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);
test/cases/safety/slice with sentinel out of bounds.zig +1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
44 _ = 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")) {
66 std.process.exit(0);
77 }
88 std.process.exit(1);
test/tests.zig+5-6
......@@ -605,7 +605,6 @@ pub fn addPkgTests(
605605 skip_libc: bool,
606606 skip_stage1: bool,
607607 skip_stage2: bool,
608 is_stage1: bool,
609608) *build.Step {
610609 const step = b.step(b.fmt("test-{s}", .{name}), desc);
611610
......@@ -634,7 +633,7 @@ pub fn addPkgTests(
634633 if (test_target.backend) |backend| switch (backend) {
635634 .stage1 => if (skip_stage1) continue,
636635 else => if (skip_stage2) continue,
637 } else if (is_stage1 and skip_stage1) continue;
636 } else if (skip_stage2) continue;
638637
639638 const want_this_mode = for (modes) |m| {
640639 if (m == test_target.mode) break true;
......@@ -924,7 +923,7 @@ pub const StackTracesContext = struct {
924923 pos = marks[i] + delim.len;
925924 }
926925 // 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 {
928927 // unexpected pattern: emit raw line and cont
929928 try buf.appendSlice(line);
930929 try buf.appendSlice("\n");
......@@ -936,9 +935,9 @@ pub const StackTracesContext = struct {
936935 try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
937936 try buf.appendSlice(" [address]");
938937 if (self.mode == .Debug) {
939 if (mem.lastIndexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
940 // On certain platforms (windows) or possibly depending on how we choose to link main
941 // the object file extension may be present so we simply strip any extension.
938 // On certain platforms (windows) or possibly depending on how we choose to link main
939 // the object file extension may be present so we simply strip any extension.
940 if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
942941 try buf.appendSlice(line[marks[3] .. marks[4] + idot]);
943942 try buf.appendSlice(line[marks[5]..]);
944943 } else {