authorgravatar for readcuttingt@gmail.comTom Read Cutting <readcuttingt@gmail.com> 2021-06-02 09:09:50+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-08 21:14:26+03:00
logc822a0b59fe123ff67bcb188f20290d818467be7
treec7c76f4f38425f9ac43ef3c6d8abd2b0e58ad515
parentec4e67fb0e47ff742d0fd76c6b00b52c2a7983e4

Add linkLibCpp helper to LibExeObjStep


1 files changed, 24 insertions(+), 0 deletions(-)

lib/std/build.zig+24
...@@ -1275,6 +1275,15 @@ fn isLibCLibrary(name: []const u8) bool {...@@ -1275,6 +1275,15 @@ fn isLibCLibrary(name: []const u8) bool {
1275 return false;1275 return false;
1276}1276}
12771277
1278fn isLibCppLibrary(name: []const u8) bool {
1279 const libcpp_libraries = [_][]const u8{ "c++", "stdc++" };
1280 for (libcpp_libraries) |libcpp_lib_name| {
1281 if (mem.eql(u8, name, libcpp_lib_name))
1282 return true;
1283 }
1284 return false;
1285}
1286
1278pub const FileSource = union(enum) {1287pub const FileSource = union(enum) {
1279 /// Relative to build root1288 /// Relative to build root
1280 path: []const u8,1289 path: []const u8,
...@@ -1381,6 +1390,7 @@ pub const LibExeObjStep = struct {...@@ -1381,6 +1390,7 @@ pub const LibExeObjStep = struct {
1381 c_macros: ArrayList([]const u8),1390 c_macros: ArrayList([]const u8),
1382 output_dir: ?[]const u8,1391 output_dir: ?[]const u8,
1383 is_linking_libc: bool = false,1392 is_linking_libc: bool = false,
1393 is_linking_libcpp: bool = false,
1384 vcpkg_bin_path: ?[]const u8 = null,1394 vcpkg_bin_path: ?[]const u8 = null,
13851395
1386 /// This may be set in order to override the default install directory1396 /// This may be set in order to override the default install directory
...@@ -1661,6 +1671,9 @@ pub const LibExeObjStep = struct {...@@ -1661,6 +1671,9 @@ pub const LibExeObjStep = struct {
1661 if (isLibCLibrary(name)) {1671 if (isLibCLibrary(name)) {
1662 return self.is_linking_libc;1672 return self.is_linking_libc;
1663 }1673 }
1674 if (isLibCppLibrary(name)) {
1675 return self.is_linking_libcpp;
1676 }
1664 for (self.link_objects.items) |link_object| {1677 for (self.link_objects.items) |link_object| {
1665 switch (link_object) {1678 switch (link_object) {
1666 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,1679 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,
...@@ -1692,6 +1705,13 @@ pub const LibExeObjStep = struct {...@@ -1692,6 +1705,13 @@ pub const LibExeObjStep = struct {
1692 }1705 }
1693 }1706 }
16941707
1708 pub fn linkLibCpp(self: *LibExeObjStep) void {
1709 if (!self.is_linking_libcpp) {
1710 self.is_linking_libcpp = true;
1711 self.link_objects.append(LinkObject{ .SystemLib = "c++" }) catch unreachable;
1712 }
1713 }
1714
1695 /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.1715 /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
1696 pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void {1716 pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void {
1697 self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;1717 self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;
...@@ -1798,6 +1818,10 @@ pub const LibExeObjStep = struct {...@@ -1798,6 +1818,10 @@ pub const LibExeObjStep = struct {
1798 self.linkLibC();1818 self.linkLibC();
1799 return;1819 return;
1800 }1820 }
1821 if (isLibCppLibrary(name)) {
1822 self.linkLibCpp();
1823 return;
1824 }
1801 if (self.linkSystemLibraryPkgConfigOnly(name)) |_| {1825 if (self.linkSystemLibraryPkgConfigOnly(name)) |_| {
1802 // pkg-config worked, so nothing further needed to do.1826 // pkg-config worked, so nothing further needed to do.
1803 return;1827 return;