authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-09-05 17:50:46+02:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-11-05 01:31:26+01:00
log54f2a7c833bf2ca0b370ebe2470bb0dd71206cba
treebad5322f30fbc01a0b842d8128659d43d947f82e
parent075d300342afa72f5328c0ee4232151dd0968264

Move `std.Target.SubSystem` to `std.zig.Subsystem`

Also updates the field names to conform with the rest of std.

9 files changed, 66 insertions(+), 109 deletions(-)

lib/std/Build/Step/Compile.zig+2-11
...@@ -171,7 +171,7 @@ lto: ?std.zig.LtoMode = null,...@@ -171,7 +171,7 @@ lto: ?std.zig.LtoMode = null,
171171
172dll_export_fns: ?bool = null,172dll_export_fns: ?bool = null,
173173
174subsystem: ?std.Target.SubSystem = null,174subsystem: ?std.zig.Subsystem = null,
175175
176/// (Windows) When targeting the MinGW ABI, use the unicode entry point (wmain/wWinMain)176/// (Windows) When targeting the MinGW ABI, use the unicode entry point (wmain/wWinMain)
177mingw_unicode_entry_point: bool = false,177mingw_unicode_entry_point: bool = false,
...@@ -1764,16 +1764,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {...@@ -1764,16 +1764,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
17641764
1765 if (compile.subsystem) |subsystem| {1765 if (compile.subsystem) |subsystem| {
1766 try zig_args.append("--subsystem");1766 try zig_args.append("--subsystem");
1767 try zig_args.append(switch (subsystem) {1767 try zig_args.append(@tagName(subsystem));
1768 .Console => "console",
1769 .Windows => "windows",
1770 .Posix => "posix",
1771 .Native => "native",
1772 .EfiApplication => "efi_application",
1773 .EfiBootServiceDriver => "efi_boot_service_driver",
1774 .EfiRom => "efi_rom",
1775 .EfiRuntimeDriver => "efi_runtime_driver",
1776 });
1777 }1768 }
17781769
1779 if (compile.mingw_unicode_entry_point) {1770 if (compile.mingw_unicode_entry_point) {
lib/std/Target.zig+2-10
...@@ -1138,16 +1138,8 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {...@@ -1138,16 +1138,8 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
1138 };1138 };
1139}1139}
11401140
1141pub const SubSystem = enum {1141/// Deprecated; use 'std.zig.Subsystem' instead. To be removed after 0.16.0 is tagged.
1142 Console,1142pub const SubSystem = std.zig.Subsystem;
1143 Windows,
1144 Posix,
1145 Native,
1146 EfiApplication,
1147 EfiBootServiceDriver,
1148 EfiRom,
1149 EfiRuntimeDriver,
1150};
11511143
1152pub const Cpu = struct {1144pub const Cpu = struct {
1153 /// Architecture1145 /// Architecture
lib/std/zig.zig+28
...@@ -349,6 +349,34 @@ pub const BuildId = union(enum) {...@@ -349,6 +349,34 @@ pub const BuildId = union(enum) {
349349
350pub const LtoMode = enum { none, full, thin };350pub const LtoMode = enum { none, full, thin };
351351
352pub const Subsystem = enum {
353 console,
354 windows,
355 posix,
356 native,
357 efi_application,
358 efi_boot_service_driver,
359 efi_rom,
360 efi_runtime_driver,
361
362 /// Deprecated; use '.console' instead. To be removed after 0.16.0 is tagged.
363 pub const Console: Subsystem = .console;
364 /// Deprecated; use '.windows' instead. To be removed after 0.16.0 is tagged.
365 pub const Windows: Subsystem = .windows;
366 /// Deprecated; use '.posix' instead. To be removed after 0.16.0 is tagged.
367 pub const Posix: Subsystem = .posix;
368 /// Deprecated; use '.native' instead. To be removed after 0.16.0 is tagged.
369 pub const Native: Subsystem = .native;
370 /// Deprecated; use '.efi_application' instead. To be removed after 0.16.0 is tagged.
371 pub const EfiApplication: Subsystem = .efi_application;
372 /// Deprecated; use '.efi_boot_service_driver' instead. To be removed after 0.16.0 is tagged.
373 pub const EfiBootServiceDriver: Subsystem = .efi_boot_service_driver;
374 /// Deprecated; use '.efi_rom' instead. To be removed after 0.16.0 is tagged.
375 pub const EfiRom: Subsystem = .efi_rom;
376 /// Deprecated; use '.efi_runtime_driver' instead. To be removed after 0.16.0 is tagged.
377 pub const EfiRuntimeDriver: Subsystem = .efi_runtime_driver;
378};
379
352/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed380/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
353/// via the `-mcpu` flag passed to the Zig compiler.381/// via the `-mcpu` flag passed to the Zig compiler.
354/// Appends the result to `buffer`.382/// Appends the result to `buffer`.
src/Compilation.zig+1-1
...@@ -1766,7 +1766,7 @@ pub const CreateOptions = struct {...@@ -1766,7 +1766,7 @@ pub const CreateOptions = struct {
1766 reference_trace: ?u32 = null,1766 reference_trace: ?u32 = null,
1767 test_filters: []const []const u8 = &.{},1767 test_filters: []const []const u8 = &.{},
1768 test_runner_path: ?[]const u8 = null,1768 test_runner_path: ?[]const u8 = null,
1769 subsystem: ?std.Target.SubSystem = null,1769 subsystem: ?std.zig.Subsystem = null,
1770 mingw_unicode_entry_point: bool = false,1770 mingw_unicode_entry_point: bool = false,
1771 /// (Zig compiler development) Enable dumping linker's state as JSON.1771 /// (Zig compiler development) Enable dumping linker's state as JSON.
1772 enable_link_snapshots: bool = false,1772 enable_link_snapshots: bool = false,
src/link.zig+1-1
...@@ -448,7 +448,7 @@ pub const File = struct {...@@ -448,7 +448,7 @@ pub const File = struct {
448 allow_shlib_undefined: ?bool,448 allow_shlib_undefined: ?bool,
449 allow_undefined_version: bool,449 allow_undefined_version: bool,
450 enable_new_dtags: ?bool,450 enable_new_dtags: ?bool,
451 subsystem: ?std.Target.SubSystem,451 subsystem: ?std.zig.Subsystem,
452 linker_script: ?[]const u8,452 linker_script: ?[]const u8,
453 version_script: ?[]const u8,453 version_script: ?[]const u8,
454 soname: ?[]const u8,454 soname: ?[]const u8,
src/link/Lld.zig+22-59
...@@ -19,7 +19,7 @@ const Coff = struct {...@@ -19,7 +19,7 @@ const Coff = struct {
19 minor_subsystem_version: u16,19 minor_subsystem_version: u16,
20 lib_directories: []const Cache.Directory,20 lib_directories: []const Cache.Directory,
21 module_definition_file: ?[]const u8,21 module_definition_file: ?[]const u8,
22 subsystem: ?std.Target.SubSystem,22 subsystem: ?std.zig.Subsystem,
23 /// These flags are populated by `codegen.llvm.updateExports` to allow us to guess the subsystem.23 /// These flags are populated by `codegen.llvm.updateExports` to allow us to guess the subsystem.
24 lld_export_flags: struct {24 lld_export_flags: struct {
25 c_main: bool,25 c_main: bool,
...@@ -554,7 +554,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {...@@ -554,7 +554,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
554 try argv.append(try allocPrint(arena, "-DEF:{s}", .{def}));554 try argv.append(try allocPrint(arena, "-DEF:{s}", .{def}));
555 }555 }
556556
557 const resolved_subsystem: ?std.Target.SubSystem = blk: {557 const resolved_subsystem: ?std.zig.Subsystem = blk: {
558 if (coff.subsystem) |explicit| break :blk explicit;558 if (coff.subsystem) |explicit| break :blk explicit;
559 switch (target.os.tag) {559 switch (target.os.tag) {
560 .windows => {560 .windows => {
...@@ -565,13 +565,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {...@@ -565,13 +565,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
565 coff.lld_export_flags.winmain_crt_startup or565 coff.lld_export_flags.winmain_crt_startup or
566 coff.lld_export_flags.wwinmain_crt_startup)566 coff.lld_export_flags.wwinmain_crt_startup)
567 {567 {
568 break :blk .Console;568 break :blk .console;
569 }569 }
570 if (coff.lld_export_flags.winmain or coff.lld_export_flags.wwinmain)570 if (coff.lld_export_flags.winmain or coff.lld_export_flags.wwinmain)
571 break :blk .Windows;571 break :blk .windows;
572 }572 }
573 },573 },
574 .uefi => break :blk .EfiApplication,574 .uefi => break :blk .efi_application,
575 else => {},575 else => {},
576 }576 }
577 break :blk null;577 break :blk null;
...@@ -580,60 +580,23 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {...@@ -580,60 +580,23 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
580 const Mode = enum { uefi, win32 };580 const Mode = enum { uefi, win32 };
581 const mode: Mode = mode: {581 const mode: Mode = mode: {
582 if (resolved_subsystem) |subsystem| {582 if (resolved_subsystem) |subsystem| {
583 const subsystem_suffix = try allocPrint(arena, ",{d}.{d}", .{583 try argv.append(try allocPrint(arena, "-SUBSYSTEM:{s},{d}.{d}", .{
584 coff.major_subsystem_version, coff.minor_subsystem_version,584 @tagName(subsystem),
585 });585 coff.major_subsystem_version,
586586 coff.minor_subsystem_version,
587 switch (subsystem) {587 }));
588 .Console => {588 break :mode switch (subsystem) {
589 try argv.append(try allocPrint(arena, "-SUBSYSTEM:console{s}", .{589 .console,
590 subsystem_suffix,590 .windows,
591 }));591 .posix,
592 break :mode .win32;592 .native,
593 },593 => .win32,
594 .EfiApplication => {594 .efi_application,
595 try argv.append(try allocPrint(arena, "-SUBSYSTEM:efi_application{s}", .{595 .efi_boot_service_driver,
596 subsystem_suffix,596 .efi_rom,
597 }));597 .efi_runtime_driver,
598 break :mode .uefi;598 => .uefi,
599 },599 };
600 .EfiBootServiceDriver => {
601 try argv.append(try allocPrint(arena, "-SUBSYSTEM:efi_boot_service_driver{s}", .{
602 subsystem_suffix,
603 }));
604 break :mode .uefi;
605 },
606 .EfiRom => {
607 try argv.append(try allocPrint(arena, "-SUBSYSTEM:efi_rom{s}", .{
608 subsystem_suffix,
609 }));
610 break :mode .uefi;
611 },
612 .EfiRuntimeDriver => {
613 try argv.append(try allocPrint(arena, "-SUBSYSTEM:efi_runtime_driver{s}", .{
614 subsystem_suffix,
615 }));
616 break :mode .uefi;
617 },
618 .Native => {
619 try argv.append(try allocPrint(arena, "-SUBSYSTEM:native{s}", .{
620 subsystem_suffix,
621 }));
622 break :mode .win32;
623 },
624 .Posix => {
625 try argv.append(try allocPrint(arena, "-SUBSYSTEM:posix{s}", .{
626 subsystem_suffix,
627 }));
628 break :mode .win32;
629 },
630 .Windows => {
631 try argv.append(try allocPrint(arena, "-SUBSYSTEM:windows{s}", .{
632 subsystem_suffix,
633 }));
634 break :mode .win32;
635 },
636 }
637 } else if (target.os.tag == .uefi) {600 } else if (target.os.tag == .uefi) {
638 break :mode .uefi;601 break :mode .uefi;
639 } else {602 } else {
src/main.zig+7-24
...@@ -893,7 +893,7 @@ fn buildOutputType(...@@ -893,7 +893,7 @@ fn buildOutputType(
893 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);893 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
894 var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);894 var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
895 var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;895 var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;
896 var subsystem: ?std.Target.SubSystem = null;896 var subsystem: ?std.zig.Subsystem = null;
897 var major_subsystem_version: ?u16 = null;897 var major_subsystem_version: ?u16 = null;
898 var minor_subsystem_version: ?u16 = null;898 var minor_subsystem_version: ?u16 = null;
899 var mingw_unicode_entry_point: bool = false;899 var mingw_unicode_entry_point: bool = false;
...@@ -1135,7 +1135,7 @@ fn buildOutputType(...@@ -1135,7 +1135,7 @@ fn buildOutputType(
1135 }1135 }
1136 n_jobs = num;1136 n_jobs = num;
1137 } else if (mem.eql(u8, arg, "--subsystem")) {1137 } else if (mem.eql(u8, arg, "--subsystem")) {
1138 subsystem = try parseSubSystem(args_iter.nextOrFatal());1138 subsystem = try parseSubsystem(args_iter.nextOrFatal());
1139 } else if (mem.eql(u8, arg, "-O")) {1139 } else if (mem.eql(u8, arg, "-O")) {
1140 mod_opts.optimize_mode = parseOptimizeMode(args_iter.nextOrFatal());1140 mod_opts.optimize_mode = parseOptimizeMode(args_iter.nextOrFatal());
1141 } else if (mem.cutPrefix(u8, arg, "-fentry=")) |rest| {1141 } else if (mem.cutPrefix(u8, arg, "-fentry=")) |rest| {
...@@ -2415,7 +2415,7 @@ fn buildOutputType(...@@ -2415,7 +2415,7 @@ fn buildOutputType(
2415 } else if (mem.eql(u8, arg, "-rpath") or mem.eql(u8, arg, "--rpath") or mem.eql(u8, arg, "-R")) {2415 } else if (mem.eql(u8, arg, "-rpath") or mem.eql(u8, arg, "--rpath") or mem.eql(u8, arg, "-R")) {
2416 try create_module.rpath_list.append(arena, linker_args_it.nextOrFatal());2416 try create_module.rpath_list.append(arena, linker_args_it.nextOrFatal());
2417 } else if (mem.eql(u8, arg, "--subsystem")) {2417 } else if (mem.eql(u8, arg, "--subsystem")) {
2418 subsystem = try parseSubSystem(linker_args_it.nextOrFatal());2418 subsystem = try parseSubsystem(linker_args_it.nextOrFatal());
2419 } else if (mem.eql(u8, arg, "-I") or2419 } else if (mem.eql(u8, arg, "-I") or
2420 mem.eql(u8, arg, "--dynamic-linker") or2420 mem.eql(u8, arg, "--dynamic-linker") or
2421 mem.eql(u8, arg, "-dynamic-linker"))2421 mem.eql(u8, arg, "-dynamic-linker"))
...@@ -2743,7 +2743,7 @@ fn buildOutputType(...@@ -2743,7 +2743,7 @@ fn buildOutputType(
2743 try symbol_wrap_set.put(arena, next_arg, {});2743 try symbol_wrap_set.put(arena, next_arg, {});
2744 } else if (mem.startsWith(u8, arg, "/subsystem:")) {2744 } else if (mem.startsWith(u8, arg, "/subsystem:")) {
2745 var split_it = mem.splitBackwardsScalar(u8, arg, ':');2745 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
2746 subsystem = try parseSubSystem(split_it.first());2746 subsystem = try parseSubsystem(split_it.first());
2747 } else if (mem.startsWith(u8, arg, "/implib:")) {2747 } else if (mem.startsWith(u8, arg, "/implib:")) {
2748 var split_it = mem.splitBackwardsScalar(u8, arg, ':');2748 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
2749 emit_implib = .{ .yes = split_it.first() };2749 emit_implib = .{ .yes = split_it.first() };
...@@ -6657,26 +6657,10 @@ fn warnAboutForeignBinaries(...@@ -6657,26 +6657,10 @@ fn warnAboutForeignBinaries(
6657 }6657 }
6658}6658}
66596659
6660fn parseSubSystem(next_arg: []const u8) !std.Target.SubSystem {6660fn parseSubsystem(arg: []const u8) !std.zig.Subsystem {
6661 if (mem.eql(u8, next_arg, "console")) {6661 return std.meta.stringToEnum(std.zig.Subsystem, arg) orelse
6662 return .Console;
6663 } else if (mem.eql(u8, next_arg, "windows")) {
6664 return .Windows;
6665 } else if (mem.eql(u8, next_arg, "posix")) {
6666 return .Posix;
6667 } else if (mem.eql(u8, next_arg, "native")) {
6668 return .Native;
6669 } else if (mem.eql(u8, next_arg, "efi_application")) {
6670 return .EfiApplication;
6671 } else if (mem.eql(u8, next_arg, "efi_boot_service_driver")) {
6672 return .EfiBootServiceDriver;
6673 } else if (mem.eql(u8, next_arg, "efi_rom")) {
6674 return .EfiRom;
6675 } else if (mem.eql(u8, next_arg, "efi_runtime_driver")) {
6676 return .EfiRuntimeDriver;
6677 } else {
6678 fatal("invalid: --subsystem: '{s}'. Options are:\n{s}", .{6662 fatal("invalid: --subsystem: '{s}'. Options are:\n{s}", .{
6679 next_arg,6663 arg,
6680 \\ console6664 \\ console
6681 \\ windows6665 \\ windows
6682 \\ posix6666 \\ posix
...@@ -6687,7 +6671,6 @@ fn parseSubSystem(next_arg: []const u8) !std.Target.SubSystem {...@@ -6687,7 +6671,6 @@ fn parseSubSystem(next_arg: []const u8) !std.Target.SubSystem {
6687 \\ efi_runtime_driver6671 \\ efi_runtime_driver
6688 \\6672 \\
6689 });6673 });
6690 }
6691}6674}
66926675
6693/// Model a header searchlist as a group.6676/// Model a header searchlist as a group.
test/standalone/issue_5825/build.zig+1-1
...@@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void {...@@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void {
31 .target = target,31 .target = target,
32 }),32 }),
33 });33 });
34 exe.subsystem = .Console;34 exe.subsystem = .console;
35 exe.root_module.linkSystemLibrary("kernel32", .{});35 exe.root_module.linkSystemLibrary("kernel32", .{});
36 exe.root_module.linkSystemLibrary("ntdll", .{});36 exe.root_module.linkSystemLibrary("ntdll", .{});
37 exe.root_module.addObject(obj);37 exe.root_module.addObject(obj);
test/standalone/windows_entry_points/build.zig+2-2
...@@ -53,7 +53,7 @@ pub fn build(b: *std.Build) void {...@@ -53,7 +53,7 @@ pub fn build(b: *std.Build) void {
53 .link_libc = true,53 .link_libc = true,
54 }),54 }),
55 });55 });
56 // Note: `exe.subsystem = .Windows;` is not necessary56 // Note: `exe.subsystem = .windows;` is not necessary
57 exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") });57 exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") });
5858
59 _ = exe.getEmittedBin();59 _ = exe.getEmittedBin();
...@@ -71,7 +71,7 @@ pub fn build(b: *std.Build) void {...@@ -71,7 +71,7 @@ pub fn build(b: *std.Build) void {
71 }),71 }),
72 });72 });
73 exe.mingw_unicode_entry_point = true;73 exe.mingw_unicode_entry_point = true;
74 // Note: `exe.subsystem = .Windows;` is not necessary74 // Note: `exe.subsystem = .windows;` is not necessary
75 exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") });75 exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") });
7676
77 _ = exe.getEmittedBin();77 _ = exe.getEmittedBin();