Commit 798ad631f3

Andrew Kelley <andrew@ziglang.org>
2021-04-13 20:51:58
stage2 start.zig: slight simplification
fewer required language features to allow this to work
1 parent 6dba9bc
Changed files (2)
lib/std/start.zig
@@ -11,8 +11,8 @@ const builtin = @import("builtin");
 const assert = std.debug.assert;
 const uefi = std.os.uefi;
 const tlcsprng = @import("crypto/tlcsprng.zig");
-const native_arch = std.Target.current.cpu.arch;
-const native_os = std.Target.current.os.tag;
+const native_arch = builtin.cpu.arch;
+const native_os = builtin.os.tag;
 
 var argc_argv_ptr: [*]usize = undefined;
 
@@ -80,7 +80,7 @@ fn _start2() callconv(.Naked) noreturn {
 }
 
 fn exit2(code: u8) noreturn {
-    switch (native_arch) {
+    switch (builtin.stage2_arch) {
         .x86_64 => {
             asm volatile ("syscall"
                 :
src/Compilation.zig
@@ -3078,7 +3078,10 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc
         \\/// Zig version. When writing code that supports multiple versions of Zig, prefer
         \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
         \\pub const zig_version = try std.SemanticVersion.parse("{s}");
+        \\/// Temporary until self-hosted is feature complete.
         \\pub const zig_is_stage2 = {};
+        \\/// Temporary until self-hosted supports the `cpu.arch` value.
+        \\pub const stage2_arch: std.Target.Cpu.Arch = .{};
         \\
         \\pub const output_mode = std.builtin.OutputMode.{};
         \\pub const link_mode = std.builtin.LinkMode.{};
@@ -3093,6 +3096,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc
     , .{
         build_options.version,
         !use_stage1,
+        std.zig.fmtId(@tagName(target.cpu.arch)),
         std.zig.fmtId(@tagName(comp.bin_file.options.output_mode)),
         std.zig.fmtId(@tagName(comp.bin_file.options.link_mode)),
         comp.bin_file.options.is_test,