authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-24 15:22:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-25 01:42:12-07:00
logb11170294052585ae81b9946d770f860d163da8f
treeeb4b73867e878ca8706b73f27eafa21ea6ccaa98
parent9684947faae674e093dda4c81d94f51b9568369e

Recognize the .res extension and link it as if it were an object file

.res files are compiled Windows resource files that get linked into executables/libraries. The linker knows what to do with them, but previously you had to trick Zig into thinking it was an object file (by renaming it to have the .obj extension, for example). After this commit, the following works: zig build-exe main.zig resource.res or, in build.zig: exe.addObjectFile("resource.res"); Closes #6488

2 files changed, 8 insertions(+), 3 deletions(-)

src/Compilation.zig+6-1
......@@ -4436,7 +4436,7 @@ pub fn addCCArgs(
44364436 try argv.append("-fno-unwind-tables");
44374437 }
44384438 },
4439 .shared_library, .ll, .bc, .unknown, .static_library, .object, .def, .zig => {},
4439 .shared_library, .ll, .bc, .unknown, .static_library, .object, .def, .zig, .res => {},
44404440 .assembly, .assembly_with_cpp => {
44414441 // The Clang assembler does not accept the list of CPU features like the
44424442 // compiler frontend does. Therefore we must hard-code the -m flags for
......@@ -4602,6 +4602,7 @@ pub const FileExt = enum {
46024602 static_library,
46034603 zig,
46044604 def,
4605 res,
46054606 unknown,
46064607
46074608 pub fn clangSupportsDepFile(ext: FileExt) bool {
......@@ -4617,6 +4618,7 @@ pub const FileExt = enum {
46174618 .static_library,
46184619 .zig,
46194620 .def,
4621 .res,
46204622 .unknown,
46214623 => false,
46224624 };
......@@ -4639,6 +4641,7 @@ pub const FileExt = enum {
46394641 .static_library => target.staticLibSuffix(),
46404642 .zig => ".zig",
46414643 .def => ".def",
4644 .res => ".res",
46424645 .unknown => "",
46434646 };
46444647 }
......@@ -4730,6 +4733,8 @@ pub fn classifyFileExt(filename: []const u8) FileExt {
47304733 return .cu;
47314734 } else if (mem.endsWith(u8, filename, ".def")) {
47324735 return .def;
4736 } else if (mem.endsWith(u8, filename, ".res")) {
4737 return .res;
47334738 } else {
47344739 return .unknown;
47354740 }
src/main.zig+2-2
......@@ -1510,7 +1510,7 @@ fn buildOutputType(
15101510 }
15111511 } else switch (file_ext orelse
15121512 Compilation.classifyFileExt(arg)) {
1513 .object, .static_library, .shared_library => try link_objects.append(.{ .path = arg }),
1513 .object, .static_library, .shared_library, .res => try link_objects.append(.{ .path = arg }),
15141514 .assembly, .assembly_with_cpp, .c, .cpp, .h, .ll, .bc, .m, .mm, .cu => {
15151515 try c_source_files.append(.{
15161516 .src_path = arg,
......@@ -1605,7 +1605,7 @@ fn buildOutputType(
16051605 .ext = file_ext, // duped while parsing the args.
16061606 });
16071607 },
1608 .unknown, .shared_library, .object, .static_library => try link_objects.append(.{
1608 .unknown, .shared_library, .object, .static_library, .res => try link_objects.append(.{
16091609 .path = it.only_arg,
16101610 .must_link = must_link,
16111611 }),