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(...@@ -927,6 +927,7 @@ fn buildOutputType(
927 var symbol_wrap_set: std.StringArrayHashMapUnmanaged(void) = .{};927 var symbol_wrap_set: std.StringArrayHashMapUnmanaged(void) = .{};
928 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);928 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
929 var rc_source_files = std.ArrayList(Compilation.RcSourceFile).init(arena);929 var rc_source_files = std.ArrayList(Compilation.RcSourceFile).init(arena);
930 var res_files = std.ArrayList(Compilation.LinkObject).init(arena);
930 var link_objects = std.ArrayList(Compilation.LinkObject).init(arena);931 var link_objects = std.ArrayList(Compilation.LinkObject).init(arena);
931 var framework_dirs = std.ArrayList([]const u8).init(arena);932 var framework_dirs = std.ArrayList([]const u8).init(arena);
932 var frameworks: std.StringArrayHashMapUnmanaged(Framework) = .{};933 var frameworks: std.StringArrayHashMapUnmanaged(Framework) = .{};
...@@ -1602,7 +1603,8 @@ fn buildOutputType(...@@ -1602,7 +1603,8 @@ fn buildOutputType(
1602 }1603 }
1603 } else switch (file_ext orelse1604 } else switch (file_ext orelse
1604 Compilation.classifyFileExt(arg)) {1605 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 }),
1606 .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => {1608 .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => {
1607 try c_source_files.append(.{1609 try c_source_files.append(.{
1608 .src_path = arg,1610 .src_path = arg,
...@@ -1702,7 +1704,11 @@ fn buildOutputType(...@@ -1702,7 +1704,11 @@ fn buildOutputType(
1702 .ext = file_ext, // duped while parsing the args.1704 .ext = file_ext, // duped while parsing the args.
1703 });1705 });
1704 },1706 },
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(.{
1706 .path = it.only_arg,1712 .path = it.only_arg,
1707 .must_link = must_link,1713 .must_link = must_link,
1708 }),1714 }),
...@@ -2473,6 +2479,12 @@ fn buildOutputType(...@@ -2473,6 +2479,12 @@ fn buildOutputType(
2473 } else if (emit_bin == .yes) {2479 } else if (emit_bin == .yes) {
2474 const basename = fs.path.basename(emit_bin.yes);2480 const basename = fs.path.basename(emit_bin.yes);
2475 break :blk basename[0 .. basename.len - fs.path.extension(basename).len];2481 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];
2476 } else if (show_builtin) {2488 } else if (show_builtin) {
2477 break :blk "builtin";2489 break :blk "builtin";
2478 } else if (arg_mode == .run) {2490 } else if (arg_mode == .run) {
...@@ -2551,6 +2563,21 @@ fn buildOutputType(...@@ -2551,6 +2563,21 @@ fn buildOutputType(
2551 link_libcpp = true;2563 link_libcpp = true;
2552 }2564 }
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
2554 if (target_info.target.cpu.arch.isWasm()) blk: {2581 if (target_info.target.cpu.arch.isWasm()) blk: {
2555 if (single_threaded == null) {2582 if (single_threaded == null) {
2556 single_threaded = true;2583 single_threaded = true;