| ... | ... | @@ -663,13 +663,23 @@ const Target = enum { |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | pub fn exeFileExt(self: &const Target) -> []const u8 { |
| 666 | | const target_os = switch (*self) { |
| 666 | return switch (self.getOs()) { |
| 667 | builtin.Os.windows => ".exe", |
| 668 | else => "", |
| 669 | }; |
| 670 | } |
| 671 | |
| 672 | pub fn getOs(self: &const Target) -> builtin.Os { |
| 673 | return switch (*self) { |
| 667 | 674 | Target.Native => builtin.os, |
| 668 | 675 | Target.Cross => |t| t.os, |
| 669 | 676 | }; |
| 670 | | return switch (target_os) { |
| 671 | | builtin.Os.windows => ".exe", |
| 672 | | else => "", |
| 677 | } |
| 678 | |
| 679 | pub fn isDarwin(self: &const Target) -> bool { |
| 680 | return switch (self.getOs()) { |
| 681 | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true, |
| 682 | else => false, |
| 673 | 683 | }; |
| 674 | 684 | } |
| 675 | 685 | }; |
| ... | ... | @@ -697,6 +707,7 @@ pub const LibExeObjStep = struct { |
| 697 | 707 | cflags: ArrayList([]const u8), |
| 698 | 708 | include_dirs: ArrayList([]const u8), |
| 699 | 709 | disable_libc: bool, |
| 710 | frameworks: BufSet, |
| 700 | 711 | |
| 701 | 712 | // zig only stuff |
| 702 | 713 | root_src: ?[]const u8, |
| ... | ... | @@ -787,6 +798,7 @@ pub const LibExeObjStep = struct { |
| 787 | 798 | .target = Target.Native, |
| 788 | 799 | .linker_script = null, |
| 789 | 800 | .link_libs = BufSet.init(builder.allocator), |
| 801 | .frameworks = BufSet.init(builder.allocator), |
| 790 | 802 | .step = Step.init(name, builder.allocator, make), |
| 791 | 803 | .output_path = null, |
| 792 | 804 | .output_h_path = null, |
| ... | ... | @@ -824,6 +836,7 @@ pub const LibExeObjStep = struct { |
| 824 | 836 | .object_files = ArrayList([]const u8).init(builder.allocator), |
| 825 | 837 | .step = Step.init(name, builder.allocator, make), |
| 826 | 838 | .link_libs = BufSet.init(builder.allocator), |
| 839 | .frameworks = BufSet.init(builder.allocator), |
| 827 | 840 | .full_path_libs = ArrayList([]const u8).init(builder.allocator), |
| 828 | 841 | .include_dirs = ArrayList([]const u8).init(builder.allocator), |
| 829 | 842 | .output_path = null, |
| ... | ... | @@ -861,11 +874,7 @@ pub const LibExeObjStep = struct { |
| 861 | 874 | if (self.static) { |
| 862 | 875 | self.out_filename = self.builder.fmt("lib{}.a", self.name); |
| 863 | 876 | } else { |
| 864 | | const target_os = switch (self.target) { |
| 865 | | Target.Native => builtin.os, |
| 866 | | Target.Cross => |t| t.os, |
| 867 | | }; |
| 868 | | switch (target_os) { |
| 877 | switch (self.target.getOs()) { |
| 869 | 878 | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => { |
| 870 | 879 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", |
| 871 | 880 | self.name, self.version.major, self.version.minor, self.version.patch); |
| ... | ... | @@ -905,6 +914,11 @@ pub const LibExeObjStep = struct { |
| 905 | 914 | self.linker_script = path; |
| 906 | 915 | } |
| 907 | 916 | |
| 917 | pub fn linkFramework(self: &LibExeObjStep, framework_name: []const u8) { |
| 918 | assert(self.target.isDarwin()); |
| 919 | %%self.frameworks.put(framework_name); |
| 920 | } |
| 921 | |
| 908 | 922 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) { |
| 909 | 923 | assert(self.kind != Kind.Obj); |
| 910 | 924 | assert(lib.kind == Kind.Lib); |
| ... | ... | @@ -916,6 +930,14 @@ pub const LibExeObjStep = struct { |
| 916 | 930 | // TODO should be some kind of isolated directory that only has this header in it |
| 917 | 931 | %%self.include_dirs.append(self.builder.cache_root); |
| 918 | 932 | self.need_flat_namespace_hack = true; |
| 933 | |
| 934 | // inherit the object's frameworks |
| 935 | if (self.target.isDarwin() and lib.static) { |
| 936 | var it = lib.frameworks.iterator(); |
| 937 | while (it.next()) |entry| { |
| 938 | %%self.frameworks.put(entry.key); |
| 939 | } |
| 940 | } |
| 919 | 941 | } |
| 920 | 942 | |
| 921 | 943 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) { |
| ... | ... | @@ -1163,6 +1185,14 @@ pub const LibExeObjStep = struct { |
| 1163 | 1185 | %%zig_args.append(builder.pathFromRoot(full_path_lib)); |
| 1164 | 1186 | } |
| 1165 | 1187 | |
| 1188 | if (self.target.isDarwin()) { |
| 1189 | var it = self.frameworks.iterator(); |
| 1190 | while (it.next()) |entry| { |
| 1191 | %%zig_args.append("-framework"); |
| 1192 | %%zig_args.append(entry.key); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1166 | 1196 | %return builder.spawnChild(builder.zig_exe, zig_args.toSliceConst()); |
| 1167 | 1197 | |
| 1168 | 1198 | if (self.kind == Kind.Lib and !self.static) { |
| ... | ... | @@ -1225,14 +1255,7 @@ pub const LibExeObjStep = struct { |
| 1225 | 1255 | var cc_args = ArrayList([]const u8).init(builder.allocator); |
| 1226 | 1256 | defer cc_args.deinit(); |
| 1227 | 1257 | |
| 1228 | | const target_os = switch (self.target) { |
| 1229 | | Target.Native => builtin.os, |
| 1230 | | Target.Cross => |t| t.os, |
| 1231 | | }; |
| 1232 | | const is_darwin = switch (target_os) { |
| 1233 | | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true, |
| 1234 | | else => false, |
| 1235 | | }; |
| 1258 | const is_darwin = self.target.isDarwin(); |
| 1236 | 1259 | |
| 1237 | 1260 | switch (self.kind) { |
| 1238 | 1261 | Kind.Obj => { |
| ... | ... | @@ -1339,6 +1362,14 @@ pub const LibExeObjStep = struct { |
| 1339 | 1362 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); |
| 1340 | 1363 | } |
| 1341 | 1364 | |
| 1365 | if (is_darwin and !self.static) { |
| 1366 | var it = self.frameworks.iterator(); |
| 1367 | while (it.next()) |entry| { |
| 1368 | %%cc_args.append("-framework"); |
| 1369 | %%cc_args.append(entry.key); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1342 | 1373 | %return builder.spawnChild(cc, cc_args.toSliceConst()); |
| 1343 | 1374 | |
| 1344 | 1375 | %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, |
| ... | ... | @@ -1391,20 +1422,25 @@ pub const LibExeObjStep = struct { |
| 1391 | 1422 | |
| 1392 | 1423 | %%cc_args.append("-rdynamic"); |
| 1393 | 1424 | |
| 1394 | | switch (target_os) { |
| 1395 | | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => { |
| 1396 | | if (self.need_flat_namespace_hack) { |
| 1397 | | %%cc_args.append("-Wl,-flat_namespace"); |
| 1398 | | } |
| 1399 | | %%cc_args.append("-Wl,-search_paths_first"); |
| 1400 | | }, |
| 1401 | | else => {} |
| 1425 | if (is_darwin) { |
| 1426 | if (self.need_flat_namespace_hack) { |
| 1427 | %%cc_args.append("-Wl,-flat_namespace"); |
| 1428 | } |
| 1429 | %%cc_args.append("-Wl,-search_paths_first"); |
| 1402 | 1430 | } |
| 1403 | 1431 | |
| 1404 | 1432 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { |
| 1405 | 1433 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); |
| 1406 | 1434 | } |
| 1407 | 1435 | |
| 1436 | if (is_darwin) { |
| 1437 | var it = self.frameworks.iterator(); |
| 1438 | while (it.next()) |entry| { |
| 1439 | %%cc_args.append("-framework"); |
| 1440 | %%cc_args.append(entry.key); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1408 | 1444 | %return builder.spawnChild(cc, cc_args.toSliceConst()); |
| 1409 | 1445 | }, |
| 1410 | 1446 | } |