Skip to content

Commit 54f2a7c

Browse files
committed
Move std.Target.SubSystem to std.zig.Subsystem
Also updates the field names to conform with the rest of std.
1 parent 075d300 commit 54f2a7c

File tree

9 files changed

+66
-109
lines changed

9 files changed

+66
-109
lines changed

lib/std/Build/Step/Compile.zig

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ lto: ?std.zig.LtoMode = null,
171171

172172
dll_export_fns: ?bool = null,
173173

174-
subsystem: ?std.Target.SubSystem = null,
174+
subsystem: ?std.zig.Subsystem = null,
175175

176176
/// (Windows) When targeting the MinGW ABI, use the unicode entry point (wmain/wWinMain)
177177
mingw_unicode_entry_point: bool = false,
@@ -1764,16 +1764,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
17641764

17651765
if (compile.subsystem) |subsystem| {
17661766
try zig_args.append("--subsystem");
1767-
try zig_args.append(switch (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-
});
1767+
try zig_args.append(@tagName(subsystem));
17771768
}
17781769

17791770
if (compile.mingw_unicode_entry_point) {

lib/std/Target.zig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,16 +1138,8 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
11381138
};
11391139
}
11401140

1141-
pub const SubSystem = enum {
1142-
Console,
1143-
Windows,
1144-
Posix,
1145-
Native,
1146-
EfiApplication,
1147-
EfiBootServiceDriver,
1148-
EfiRom,
1149-
EfiRuntimeDriver,
1150-
};
1141+
/// Deprecated; use 'std.zig.Subsystem' instead. To be removed after 0.16.0 is tagged.
1142+
pub const SubSystem = std.zig.Subsystem;
11511143

11521144
pub const Cpu = struct {
11531145
/// Architecture

lib/std/zig.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,34 @@ pub const BuildId = union(enum) {
349349

350350
pub const LtoMode = enum { none, full, thin };
351351

352+
pub 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+
352380
/// Renders a `std.Target.Cpu` value into a textual representation that can be parsed
353381
/// via the `-mcpu` flag passed to the Zig compiler.
354382
/// Appends the result to `buffer`.

src/Compilation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ pub const CreateOptions = struct {
17661766
reference_trace: ?u32 = null,
17671767
test_filters: []const []const u8 = &.{},
17681768
test_runner_path: ?[]const u8 = null,
1769-
subsystem: ?std.Target.SubSystem = null,
1769+
subsystem: ?std.zig.Subsystem = null,
17701770
mingw_unicode_entry_point: bool = false,
17711771
/// (Zig compiler development) Enable dumping linker's state as JSON.
17721772
enable_link_snapshots: bool = false,

src/link.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ pub const File = struct {
448448
allow_shlib_undefined: ?bool,
449449
allow_undefined_version: bool,
450450
enable_new_dtags: ?bool,
451-
subsystem: ?std.Target.SubSystem,
451+
subsystem: ?std.zig.Subsystem,
452452
linker_script: ?[]const u8,
453453
version_script: ?[]const u8,
454454
soname: ?[]const u8,

src/link/Lld.zig

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Coff = struct {
1919
minor_subsystem_version: u16,
2020
lib_directories: []const Cache.Directory,
2121
module_definition_file: ?[]const u8,
22-
subsystem: ?std.Target.SubSystem,
22+
subsystem: ?std.zig.Subsystem,
2323
/// These flags are populated by `codegen.llvm.updateExports` to allow us to guess the subsystem.
2424
lld_export_flags: struct {
2525
c_main: bool,
@@ -554,7 +554,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
554554
try argv.append(try allocPrint(arena, "-DEF:{s}", .{def}));
555555
}
556556

557-
const resolved_subsystem: ?std.Target.SubSystem = blk: {
557+
const resolved_subsystem: ?std.zig.Subsystem = blk: {
558558
if (coff.subsystem) |explicit| break :blk explicit;
559559
switch (target.os.tag) {
560560
.windows => {
@@ -565,13 +565,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
565565
coff.lld_export_flags.winmain_crt_startup or
566566
coff.lld_export_flags.wwinmain_crt_startup)
567567
{
568-
break :blk .Console;
568+
break :blk .console;
569569
}
570570
if (coff.lld_export_flags.winmain or coff.lld_export_flags.wwinmain)
571-
break :blk .Windows;
571+
break :blk .windows;
572572
}
573573
},
574-
.uefi => break :blk .EfiApplication,
574+
.uefi => break :blk .efi_application,
575575
else => {},
576576
}
577577
break :blk null;
@@ -580,60 +580,23 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
580580
const Mode = enum { uefi, win32 };
581581
const mode: Mode = mode: {
582582
if (resolved_subsystem) |subsystem| {
583-
const subsystem_suffix = try allocPrint(arena, ",{d}.{d}", .{
584-
coff.major_subsystem_version, coff.minor_subsystem_version,
585-
});
586-
587-
switch (subsystem) {
588-
.Console => {
589-
try argv.append(try allocPrint(arena, "-SUBSYSTEM:console{s}", .{
590-
subsystem_suffix,
591-
}));
592-
break :mode .win32;
593-
},
594-
.EfiApplication => {
595-
try argv.append(try allocPrint(arena, "-SUBSYSTEM:efi_application{s}", .{
596-
subsystem_suffix,
597-
}));
598-
break :mode .uefi;
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-
}
583+
try argv.append(try allocPrint(arena, "-SUBSYSTEM:{s},{d}.{d}", .{
584+
@tagName(subsystem),
585+
coff.major_subsystem_version,
586+
coff.minor_subsystem_version,
587+
}));
588+
break :mode switch (subsystem) {
589+
.console,
590+
.windows,
591+
.posix,
592+
.native,
593+
=> .win32,
594+
.efi_application,
595+
.efi_boot_service_driver,
596+
.efi_rom,
597+
.efi_runtime_driver,
598+
=> .uefi,
599+
};
637600
} else if (target.os.tag == .uefi) {
638601
break :mode .uefi;
639602
} else {

src/main.zig

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ fn buildOutputType(
893893
var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
894894
var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
895895
var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;
896-
var subsystem: ?std.Target.SubSystem = null;
896+
var subsystem: ?std.zig.Subsystem = null;
897897
var major_subsystem_version: ?u16 = null;
898898
var minor_subsystem_version: ?u16 = null;
899899
var mingw_unicode_entry_point: bool = false;
@@ -1135,7 +1135,7 @@ fn buildOutputType(
11351135
}
11361136
n_jobs = num;
11371137
} else if (mem.eql(u8, arg, "--subsystem")) {
1138-
subsystem = try parseSubSystem(args_iter.nextOrFatal());
1138+
subsystem = try parseSubsystem(args_iter.nextOrFatal());
11391139
} else if (mem.eql(u8, arg, "-O")) {
11401140
mod_opts.optimize_mode = parseOptimizeMode(args_iter.nextOrFatal());
11411141
} else if (mem.cutPrefix(u8, arg, "-fentry=")) |rest| {
@@ -2415,7 +2415,7 @@ fn buildOutputType(
24152415
} else if (mem.eql(u8, arg, "-rpath") or mem.eql(u8, arg, "--rpath") or mem.eql(u8, arg, "-R")) {
24162416
try create_module.rpath_list.append(arena, linker_args_it.nextOrFatal());
24172417
} else if (mem.eql(u8, arg, "--subsystem")) {
2418-
subsystem = try parseSubSystem(linker_args_it.nextOrFatal());
2418+
subsystem = try parseSubsystem(linker_args_it.nextOrFatal());
24192419
} else if (mem.eql(u8, arg, "-I") or
24202420
mem.eql(u8, arg, "--dynamic-linker") or
24212421
mem.eql(u8, arg, "-dynamic-linker"))
@@ -2743,7 +2743,7 @@ fn buildOutputType(
27432743
try symbol_wrap_set.put(arena, next_arg, {});
27442744
} else if (mem.startsWith(u8, arg, "/subsystem:")) {
27452745
var split_it = mem.splitBackwardsScalar(u8, arg, ':');
2746-
subsystem = try parseSubSystem(split_it.first());
2746+
subsystem = try parseSubsystem(split_it.first());
27472747
} else if (mem.startsWith(u8, arg, "/implib:")) {
27482748
var split_it = mem.splitBackwardsScalar(u8, arg, ':');
27492749
emit_implib = .{ .yes = split_it.first() };
@@ -6657,26 +6657,10 @@ fn warnAboutForeignBinaries(
66576657
}
66586658
}
66596659

6660-
fn parseSubSystem(next_arg: []const u8) !std.Target.SubSystem {
6661-
if (mem.eql(u8, next_arg, "console")) {
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 {
6660+
fn parseSubsystem(arg: []const u8) !std.zig.Subsystem {
6661+
return std.meta.stringToEnum(std.zig.Subsystem, arg) orelse
66786662
fatal("invalid: --subsystem: '{s}'. Options are:\n{s}", .{
6679-
next_arg,
6663+
arg,
66806664
\\ console
66816665
\\ windows
66826666
\\ posix
@@ -6687,7 +6671,6 @@ fn parseSubSystem(next_arg: []const u8) !std.Target.SubSystem {
66876671
\\ efi_runtime_driver
66886672
\\
66896673
});
6690-
}
66916674
}
66926675

66936676
/// Model a header searchlist as a group.

test/standalone/issue_5825/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void {
3131
.target = target,
3232
}),
3333
});
34-
exe.subsystem = .Console;
34+
exe.subsystem = .console;
3535
exe.root_module.linkSystemLibrary("kernel32", .{});
3636
exe.root_module.linkSystemLibrary("ntdll", .{});
3737
exe.root_module.addObject(obj);

test/standalone/windows_entry_points/build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn build(b: *std.Build) void {
5353
.link_libc = true,
5454
}),
5555
});
56-
// Note: `exe.subsystem = .Windows;` is not necessary
56+
// Note: `exe.subsystem = .windows;` is not necessary
5757
exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") });
5858

5959
_ = exe.getEmittedBin();
@@ -71,7 +71,7 @@ pub fn build(b: *std.Build) void {
7171
}),
7272
});
7373
exe.mingw_unicode_entry_point = true;
74-
// Note: `exe.subsystem = .Windows;` is not necessary
74+
// Note: `exe.subsystem = .windows;` is not necessary
7575
exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") });
7676

7777
_ = exe.getEmittedBin();

0 commit comments

Comments
 (0)