Skip to content

Commit 6c70994

Browse files
committed
remove -fstage1 option
After this commit, the self-hosted compiler does not offer the option to use stage1 as a backend anymore.
1 parent 8c4faa5 commit 6c70994

25 files changed

+95
-461
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ set(ZIG_BUILD_ARGS
10831083
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
10841084
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
10851085
"-Denable-llvm"
1086-
"-Denable-stage1"
10871086
${ZIG_RELEASE_ARG}
10881087
${ZIG_STATIC_ARG}
10891088
${ZIG_NO_LIB_ARG}

build.zig

Lines changed: 2 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ pub fn build(b: *Builder) !void {
6969

7070
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
7171

72-
const have_stage1 = b.option(bool, "enable-stage1", "Include the stage1 compiler behind a feature flag") orelse false;
7372
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
74-
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (have_stage1 or static_llvm);
73+
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse static_llvm;
7574
const llvm_has_m68k = b.option(
7675
bool,
7776
"llvm-has-m68k",
@@ -132,7 +131,6 @@ pub fn build(b: *Builder) !void {
132131
const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse (enable_llvm or only_c);
133132
const sanitize_thread = b.option(bool, "sanitize-thread", "Enable thread-sanitization") orelse false;
134133
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
135-
const use_zig0 = b.option(bool, "zig0", "Bootstrap using zig0") orelse false;
136134
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;
137135

138136
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: {
@@ -145,11 +143,7 @@ pub fn build(b: *Builder) !void {
145143
target.ofmt = .c;
146144
}
147145

148-
const main_file: ?[]const u8 = mf: {
149-
if (!have_stage1) break :mf "src/main.zig";
150-
if (use_zig0) break :mf null;
151-
break :mf "src/stage1.zig";
152-
};
146+
const main_file: ?[]const u8 = "src/main.zig";
153147

154148
const exe = b.addExecutable("zig", main_file);
155149

@@ -263,92 +257,6 @@ pub fn build(b: *Builder) !void {
263257
}
264258
};
265259

266-
if (have_stage1) {
267-
const softfloat = b.addStaticLibrary("softfloat", null);
268-
softfloat.setBuildMode(.ReleaseFast);
269-
softfloat.setTarget(target);
270-
softfloat.addIncludePath("deps/SoftFloat-3e-prebuilt");
271-
softfloat.addIncludePath("deps/SoftFloat-3e/source/8086");
272-
softfloat.addIncludePath("deps/SoftFloat-3e/source/include");
273-
softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
274-
softfloat.single_threaded = single_threaded;
275-
276-
const zig0 = b.addExecutable("zig0", null);
277-
zig0.addCSourceFiles(&.{"src/stage1/zig0.cpp"}, &exe_cflags);
278-
zig0.addIncludePath("zig-cache/tmp"); // for config.h
279-
zig0.defineCMacro("ZIG_VERSION_MAJOR", b.fmt("{d}", .{zig_version.major}));
280-
zig0.defineCMacro("ZIG_VERSION_MINOR", b.fmt("{d}", .{zig_version.minor}));
281-
zig0.defineCMacro("ZIG_VERSION_PATCH", b.fmt("{d}", .{zig_version.patch}));
282-
zig0.defineCMacro("ZIG_VERSION_STRING", b.fmt("\"{s}\"", .{version}));
283-
284-
for ([_]*std.build.LibExeObjStep{ zig0, exe, test_cases }) |artifact| {
285-
artifact.addIncludePath("src");
286-
artifact.addIncludePath("deps/SoftFloat-3e/source/include");
287-
artifact.addIncludePath("deps/SoftFloat-3e-prebuilt");
288-
289-
artifact.defineCMacro("ZIG_LINK_MODE", "Static");
290-
291-
artifact.addCSourceFiles(&stage1_sources, &exe_cflags);
292-
artifact.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
293-
294-
artifact.linkLibrary(softfloat);
295-
artifact.linkLibCpp();
296-
}
297-
298-
try addStaticLlvmOptionsToExe(zig0);
299-
300-
const zig1_obj_ext = target.getObjectFormat().fileExt(target.getCpuArch());
301-
const zig1_obj_path = b.pathJoin(&.{ "zig-cache", "tmp", b.fmt("zig1{s}", .{zig1_obj_ext}) });
302-
const zig1_compiler_rt_path = b.pathJoin(&.{ b.pathFromRoot("lib"), "std", "special", "compiler_rt.zig" });
303-
304-
const zig1_obj = zig0.run();
305-
zig1_obj.addArgs(&.{
306-
"src/stage1.zig",
307-
"-target",
308-
try target.zigTriple(b.allocator),
309-
"-mcpu=baseline",
310-
"--name",
311-
"zig1",
312-
"--zig-lib-dir",
313-
b.pathFromRoot("lib"),
314-
b.fmt("-femit-bin={s}", .{b.pathFromRoot(zig1_obj_path)}),
315-
"-fcompiler-rt",
316-
"-lc",
317-
});
318-
{
319-
zig1_obj.addArgs(&.{ "--pkg-begin", "build_options" });
320-
zig1_obj.addFileSourceArg(exe_options.getSource());
321-
zig1_obj.addArgs(&.{ "--pkg-end", "--pkg-begin", "compiler_rt", zig1_compiler_rt_path, "--pkg-end" });
322-
}
323-
switch (mode) {
324-
.Debug => {},
325-
.ReleaseFast => {
326-
zig1_obj.addArg("-OReleaseFast");
327-
zig1_obj.addArg("-fstrip");
328-
},
329-
.ReleaseSafe => {
330-
zig1_obj.addArg("-OReleaseSafe");
331-
zig1_obj.addArg("-fstrip");
332-
},
333-
.ReleaseSmall => {
334-
zig1_obj.addArg("-OReleaseSmall");
335-
zig1_obj.addArg("-fstrip");
336-
},
337-
}
338-
if (single_threaded orelse false) {
339-
zig1_obj.addArg("-fsingle-threaded");
340-
}
341-
342-
if (use_zig0) {
343-
exe.step.dependOn(&zig1_obj.step);
344-
exe.addObjectFile(zig1_obj_path);
345-
}
346-
347-
// This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
348-
// of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
349-
// is pointless.
350-
exe.addPackagePath("compiler_rt", "src/empty.zig");
351-
}
352260
if (cmake_cfg) |cfg| {
353261
// Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
354262
// That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
@@ -378,7 +286,6 @@ pub fn build(b: *Builder) !void {
378286
exe_options.addOption(bool, "enable_tracy_callstack", tracy_callstack);
379287
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
380288
exe_options.addOption(bool, "value_tracing", value_tracing);
381-
exe_options.addOption(bool, "have_stage1", have_stage1);
382289
if (tracy) |tracy_path| {
383290
const client_cpp = fs.path.join(
384291
b.allocator,
@@ -413,7 +320,6 @@ pub fn build(b: *Builder) !void {
413320
test_cases_options.addOption(bool, "enable_link_snapshots", enable_link_snapshots);
414321
test_cases_options.addOption(bool, "skip_non_native", skip_non_native);
415322
test_cases_options.addOption(bool, "skip_stage1", skip_stage1);
416-
test_cases_options.addOption(bool, "have_stage1", have_stage1);
417323
test_cases_options.addOption(bool, "have_llvm", enable_llvm);
418324
test_cases_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
419325
test_cases_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
@@ -1008,31 +914,6 @@ const softfloat_sources = [_][]const u8{
1008914
"deps/SoftFloat-3e/source/ui64_to_extF80M.c",
1009915
};
1010916

1011-
const stage1_sources = [_][]const u8{
1012-
"src/stage1/analyze.cpp",
1013-
"src/stage1/astgen.cpp",
1014-
"src/stage1/bigfloat.cpp",
1015-
"src/stage1/bigint.cpp",
1016-
"src/stage1/buffer.cpp",
1017-
"src/stage1/codegen.cpp",
1018-
"src/stage1/errmsg.cpp",
1019-
"src/stage1/error.cpp",
1020-
"src/stage1/heap.cpp",
1021-
"src/stage1/ir.cpp",
1022-
"src/stage1/ir_print.cpp",
1023-
"src/stage1/mem.cpp",
1024-
"src/stage1/os.cpp",
1025-
"src/stage1/parser.cpp",
1026-
"src/stage1/range_set.cpp",
1027-
"src/stage1/stage1.cpp",
1028-
"src/stage1/target.cpp",
1029-
"src/stage1/tokenizer.cpp",
1030-
"src/stage1/util.cpp",
1031-
"src/stage1/softfloat_ext.cpp",
1032-
};
1033-
const optimized_c_sources = [_][]const u8{
1034-
"src/stage1/parse_f128.c",
1035-
};
1036917
const zig_cpp_sources = [_][]const u8{
1037918
// These are planned to stay even when we are self-hosted.
1038919
"src/zig_llvm.cpp",

lib/build_runner.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ pub fn main() !void {
181181
builder.enable_darling = true;
182182
} else if (mem.eql(u8, arg, "-fno-darling")) {
183183
builder.enable_darling = false;
184-
} else if (mem.eql(u8, arg, "-fstage1")) {
185-
builder.use_stage1 = true;
186-
} else if (mem.eql(u8, arg, "-fno-stage1")) {
187-
builder.use_stage1 = false;
188184
} else if (mem.eql(u8, arg, "-freference-trace")) {
189185
builder.reference_trace = 256;
190186
} else if (mem.startsWith(u8, arg, "-freference-trace=")) {
@@ -316,8 +312,6 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
316312
try out_stream.writeAll(
317313
\\
318314
\\Advanced Options:
319-
\\ -fstage1 Force using bootstrap compiler as the codegen backend
320-
\\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
321315
\\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
322316
\\ -fno-reference-trace Disable reference trace
323317
\\ --build-file [file] Override path to build.zig

lib/std/build.zig

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub const Builder = struct {
4646
prominent_compile_errors: bool,
4747
color: enum { auto, on, off } = .auto,
4848
reference_trace: ?u32 = null,
49-
use_stage1: ?bool = null,
5049
invalid_user_input: bool,
5150
zig_exe: []const u8,
5251
default_step: *Step,
@@ -1619,7 +1618,6 @@ pub const LibExeObjStep = struct {
16191618
stack_size: ?u64 = null,
16201619

16211620
want_lto: ?bool = null,
1622-
use_stage1: ?bool = null,
16231621
use_llvm: ?bool = null,
16241622
use_lld: ?bool = null,
16251623

@@ -2459,20 +2457,6 @@ pub const LibExeObjStep = struct {
24592457
try zig_args.append(try std.fmt.allocPrint(builder.allocator, "-freference-trace={d}", .{some}));
24602458
}
24612459

2462-
if (self.use_stage1) |stage1| {
2463-
if (stage1) {
2464-
try zig_args.append("-fstage1");
2465-
} else {
2466-
try zig_args.append("-fno-stage1");
2467-
}
2468-
} else if (builder.use_stage1) |stage1| {
2469-
if (stage1) {
2470-
try zig_args.append("-fstage1");
2471-
} else {
2472-
try zig_args.append("-fno-stage1");
2473-
}
2474-
}
2475-
24762460
if (self.use_llvm) |use_llvm| {
24772461
if (use_llvm) {
24782462
try zig_args.append("-fLLVM");

lib/std/build/TranslateCStep.zig

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ output_dir: ?[]const u8,
2121
out_basename: []const u8,
2222
target: CrossTarget = CrossTarget{},
2323
output_file: build.GeneratedFile,
24-
use_stage1: ?bool = null,
2524

2625
pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2726
const self = builder.allocator.create(TranslateCStep) catch unreachable;
@@ -92,19 +91,6 @@ fn make(step: *Step) !void {
9291
try argv_list.append("-D");
9392
try argv_list.append(c_macro);
9493
}
95-
if (self.use_stage1) |stage1| {
96-
if (stage1) {
97-
try argv_list.append("-fstage1");
98-
} else {
99-
try argv_list.append("-fno-stage1");
100-
}
101-
} else if (self.builder.use_stage1) |stage1| {
102-
if (stage1) {
103-
try argv_list.append("-fstage1");
104-
} else {
105-
try argv_list.append("-fno-stage1");
106-
}
107-
}
10894

10995
try argv_list.append(self.source.getPath(self.builder));
11096

0 commit comments

Comments
 (0)