authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-26 22:37:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-26 22:37:19-07:00
loga9082b4ec51debdbffc20b56e9b37cb82dd04750
tree251eaeee7562ee64757b3a171cd327c4d23a116c
parent4b403c7eaca50815cae8f2ddde19b4fb476ae8ca

stage2: add CLI support for --subsystem


4 files changed, 44 insertions(+), 2 deletions(-)

BRANCH_TODO-1
......@@ -1,4 +1,3 @@
1 * subsystem
21 * COFF LLD linking
32 * mingw-w64
43 * MachO LLD linking
src/Compilation.zig+7-1
......@@ -377,6 +377,7 @@ pub const InitOptions = struct {
377377 color: @import("main.zig").Color = .Auto,
378378 test_filter: ?[]const u8 = null,
379379 test_name_prefix: ?[]const u8 = null,
380 subsystem: ?std.Target.SubSystem = null,
380381};
381382
382383pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
......@@ -767,6 +768,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
767768 .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc,
768769 .each_lib_rpath = options.each_lib_rpath orelse false,
769770 .disable_lld_caching = options.disable_lld_caching,
771 .subsystem = options.subsystem,
770772 });
771773 errdefer bin_file.destroy();
772774 comp.* = .{
......@@ -2557,6 +2559,10 @@ fn updateStage1Module(comp: *Compilation) !void {
25572559 const stage1_pkg = try createStage1Pkg(arena, "root", mod.root_pkg, null);
25582560 const test_filter = comp.test_filter orelse ""[0..0];
25592561 const test_name_prefix = comp.test_name_prefix orelse ""[0..0];
2562 const subsystem = if (comp.bin_file.options.subsystem) |s|
2563 @intToEnum(stage1.TargetSubsystem, @enumToInt(s))
2564 else
2565 stage1.TargetSubsystem.Auto;
25602566 stage1_module.* = .{
25612567 .root_name_ptr = comp.bin_file.options.root_name.ptr,
25622568 .root_name_len = comp.bin_file.options.root_name.len,
......@@ -2581,7 +2587,7 @@ fn updateStage1Module(comp: *Compilation) !void {
25812587 .userdata = @ptrToInt(comp),
25822588 .root_pkg = stage1_pkg,
25832589 .code_model = @enumToInt(comp.bin_file.options.machine_code_model),
2584 .subsystem = stage1.TargetSubsystem.Auto,
2590 .subsystem = subsystem,
25852591 .err_color = @enumToInt(comp.color),
25862592 .pic = comp.bin_file.options.pic,
25872593 .link_libc = comp.bin_file.options.link_libc,
src/link.zig+1
......@@ -77,6 +77,7 @@ pub const Options = struct {
7777 disable_lld_caching: bool,
7878 gc_sections: ?bool = null,
7979 allow_shlib_undefined: ?bool = null,
80 subsystem: ?std.Target.SubSystem = null,
8081 linker_script: ?[]const u8 = null,
8182 version_script: ?[]const u8 = null,
8283 override_soname: ?[]const u8 = null,
src/main.zig+36
......@@ -273,6 +273,7 @@ const usage_build_generic =
273273 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
274274 \\ -dynamic Force output to be dynamically linked
275275 \\ -static Force output to be statically linked
276 \\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
276277 \\
277278 \\Test Options:
278279 \\ --test-filter [text] Skip tests that do not match filter
......@@ -439,6 +440,7 @@ fn buildOutputType(
439440 var override_lib_dir: ?[]const u8 = null;
440441 var main_pkg_path: ?[]const u8 = null;
441442 var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;
443 var subsystem: ?std.Target.SubSystem = null;
442444
443445 var system_libs = std.ArrayList([]const u8).init(gpa);
444446 defer system_libs.deinit();
......@@ -575,6 +577,39 @@ fn buildOutputType(
575577 } else {
576578 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});
577579 }
580 } else if (mem.eql(u8, arg, "--subsystem")) {
581 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
582 i += 1;
583 if (mem.eql(u8, args[i], "console")) {
584 subsystem = .Console;
585 } else if (mem.eql(u8, args[i], "windows")) {
586 subsystem = .Windows;
587 } else if (mem.eql(u8, args[i], "posix")) {
588 subsystem = .Posix;
589 } else if (mem.eql(u8, args[i], "native")) {
590 subsystem = .Native;
591 } else if (mem.eql(u8, args[i], "efi_application")) {
592 subsystem = .EfiApplication;
593 } else if (mem.eql(u8, args[i], "efi_boot_service_driver")) {
594 subsystem = .EfiBootServiceDriver;
595 } else if (mem.eql(u8, args[i], "efi_rom")) {
596 subsystem = .EfiRom;
597 } else if (mem.eql(u8, args[i], "efi_runtime_driver")) {
598 subsystem = .EfiRuntimeDriver;
599 } else {
600 fatal("invalid: --subsystem: '{s}'. Options are:\n{s}", .{
601 args[i],
602 \\ console
603 \\ windows
604 \\ posix
605 \\ native
606 \\ efi_application
607 \\ efi_boot_service_driver
608 \\ efi_rom
609 \\ efi_runtime_driver
610 \\
611 });
612 }
578613 } else if (mem.eql(u8, arg, "-O")) {
579614 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
580615 i += 1;
......@@ -1539,6 +1574,7 @@ fn buildOutputType(
15391574 .test_filter = test_filter,
15401575 .test_name_prefix = test_name_prefix,
15411576 .disable_lld_caching = !have_enable_cache,
1577 .subsystem = subsystem,
15421578 }) catch |err| {
15431579 fatal("unable to create compilation: {}", .{@errorName(err)});
15441580 };