From c822a0b59fe123ff67bcb188f20290d818467be7 Mon Sep 17 00:00:00 2001 From: Tom Maenan Read Cutting Date: Wed, 2 Jun 2021 09:09:50 +0100 Subject: [PATCH] Add linkLibCpp helper to LibExeObjStep --- lib/std/build.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/std/build.zig b/lib/std/build.zig index 7628a18c5c..349e689141 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1275,6 +1275,15 @@ fn isLibCLibrary(name: []const u8) bool { return false; } +fn isLibCppLibrary(name: []const u8) bool { + const libcpp_libraries = [_][]const u8{ "c++", "stdc++" }; + for (libcpp_libraries) |libcpp_lib_name| { + if (mem.eql(u8, name, libcpp_lib_name)) + return true; + } + return false; +} + pub const FileSource = union(enum) { /// Relative to build root path: []const u8, @@ -1381,6 +1390,7 @@ pub const LibExeObjStep = struct { c_macros: ArrayList([]const u8), output_dir: ?[]const u8, is_linking_libc: bool = false, + is_linking_libcpp: bool = false, vcpkg_bin_path: ?[]const u8 = null, /// This may be set in order to override the default install directory @@ -1661,6 +1671,9 @@ pub const LibExeObjStep = struct { if (isLibCLibrary(name)) { return self.is_linking_libc; } + if (isLibCppLibrary(name)) { + return self.is_linking_libcpp; + } for (self.link_objects.items) |link_object| { switch (link_object) { LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true, @@ -1692,6 +1705,13 @@ pub const LibExeObjStep = struct { } } + pub fn linkLibCpp(self: *LibExeObjStep) void { + if (!self.is_linking_libcpp) { + self.is_linking_libcpp = true; + self.link_objects.append(LinkObject{ .SystemLib = "c++" }) catch unreachable; + } + } + /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void { self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable; @@ -1798,6 +1818,10 @@ pub const LibExeObjStep = struct { self.linkLibC(); return; } + if (isLibCppLibrary(name)) { + self.linkLibCpp(); + return; + } if (self.linkSystemLibraryPkgConfigOnly(name)) |_| { // pkg-config worked, so nothing further needed to do. return;