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 {
12751275 return false;
12761276}
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
12781287pub const FileSource = union(enum) {
12791288 /// Relative to build root
12801289 path: []const u8,
......@@ -1381,6 +1390,7 @@ pub const LibExeObjStep = struct {
13811390 c_macros: ArrayList([]const u8),
13821391 output_dir: ?[]const u8,
13831392 is_linking_libc: bool = false,
1393 is_linking_libcpp: bool = false,
13841394 vcpkg_bin_path: ?[]const u8 = null,
13851395
13861396 /// This may be set in order to override the default install directory
......@@ -1661,6 +1671,9 @@ pub const LibExeObjStep = struct {
16611671 if (isLibCLibrary(name)) {
16621672 return self.is_linking_libc;
16631673 }
1674 if (isLibCppLibrary(name)) {
1675 return self.is_linking_libcpp;
1676 }
16641677 for (self.link_objects.items) |link_object| {
16651678 switch (link_object) {
16661679 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,
......@@ -1692,6 +1705,13 @@ pub const LibExeObjStep = struct {
16921705 }
16931706 }
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
16951715 /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
16961716 pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void {
16971717 self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;
......@@ -1798,6 +1818,10 @@ pub const LibExeObjStep = struct {
17981818 self.linkLibC();
17991819 return;
18001820 }
1821 if (isLibCppLibrary(name)) {
1822 self.linkLibCpp();
1823 return;
1824 }
18011825 if (self.linkSystemLibraryPkgConfigOnly(name)) |_| {
18021826 // pkg-config worked, so nothing further needed to do.
18031827 return;