authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-09-06 02:26:26-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-09-17 03:09:45-07:00
log73f581b7bcba00176b37247c6701b056e23c651b
treeb8ea291885b9706da4506ea04186490375da9006
parent01fc6a05ef4b4de3d351ebbc64f35eef7f3afa7a

Disallow .rc/.res files unless the object format is coff


1 files changed, 29 insertions(+), 2 deletions(-)

src/main.zig+29-2
......@@ -927,6 +927,7 @@ fn buildOutputType(
927927 var symbol_wrap_set: std.StringArrayHashMapUnmanaged(void) = .{};
928928 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
929929 var rc_source_files = std.ArrayList(Compilation.RcSourceFile).init(arena);
930 var res_files = std.ArrayList(Compilation.LinkObject).init(arena);
930931 var link_objects = std.ArrayList(Compilation.LinkObject).init(arena);
931932 var framework_dirs = std.ArrayList([]const u8).init(arena);
932933 var frameworks: std.StringArrayHashMapUnmanaged(Framework) = .{};
......@@ -1602,7 +1603,8 @@ fn buildOutputType(
16021603 }
16031604 } else switch (file_ext orelse
16041605 Compilation.classifyFileExt(arg)) {
1605 .object, .static_library, .shared_library, .res => try link_objects.append(.{ .path = arg }),
1606 .object, .static_library, .shared_library => try link_objects.append(.{ .path = arg }),
1607 .res => try res_files.append(.{ .path = arg }),
16061608 .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => {
16071609 try c_source_files.append(.{
16081610 .src_path = arg,
......@@ -1702,7 +1704,11 @@ fn buildOutputType(
17021704 .ext = file_ext, // duped while parsing the args.
17031705 });
17041706 },
1705 .unknown, .shared_library, .object, .static_library, .res => try link_objects.append(.{
1707 .unknown, .shared_library, .object, .static_library => try link_objects.append(.{
1708 .path = it.only_arg,
1709 .must_link = must_link,
1710 }),
1711 .res => try res_files.append(.{
17061712 .path = it.only_arg,
17071713 .must_link = must_link,
17081714 }),
......@@ -2473,6 +2479,12 @@ fn buildOutputType(
24732479 } else if (emit_bin == .yes) {
24742480 const basename = fs.path.basename(emit_bin.yes);
24752481 break :blk basename[0 .. basename.len - fs.path.extension(basename).len];
2482 } else if (rc_source_files.items.len >= 1) {
2483 const basename = fs.path.basename(rc_source_files.items[0].src_path);
2484 break :blk basename[0 .. basename.len - fs.path.extension(basename).len];
2485 } else if (res_files.items.len >= 1) {
2486 const basename = fs.path.basename(res_files.items[0].path);
2487 break :blk basename[0 .. basename.len - fs.path.extension(basename).len];
24762488 } else if (show_builtin) {
24772489 break :blk "builtin";
24782490 } else if (arg_mode == .run) {
......@@ -2551,6 +2563,21 @@ fn buildOutputType(
25512563 link_libcpp = true;
25522564 }
25532565
2566 if (target_info.target.ofmt == .coff) {
2567 // Now that we know the target supports resources,
2568 // we can add the res files as link objects.
2569 for (res_files.items) |res_file| {
2570 try link_objects.append(res_file);
2571 }
2572 } else {
2573 if (rc_source_files.items.len != 0) {
2574 fatal("rc files are not allowed unless the target object format is coff (Windows/UEFI)", .{});
2575 }
2576 if (res_files.items.len != 0) {
2577 fatal("res files are not allowed unless the target object format is coff (Windows/UEFI)", .{});
2578 }
2579 }
2580
25542581 if (target_info.target.cpu.arch.isWasm()) blk: {
25552582 if (single_threaded == null) {
25562583 single_threaded = true;