| ... | @@ -663,13 +663,23 @@ const Target = enum { | ... | @@ -663,13 +663,23 @@ const Target = enum { |
| 663 | } | 663 | } |
| 664 | | 664 | |
| 665 | pub fn exeFileExt(self: &const Target) -> []const u8 { | 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 | Target.Native => builtin.os, | 674 | Target.Native => builtin.os, |
| 668 | Target.Cross => |t| t.os, | 675 | Target.Cross => |t| t.os, |
| 669 | }; | 676 | }; |
| 670 | return switch (target_os) { | 677 | } |
| 671 | builtin.Os.windows => ".exe", | 678 | |
| 672 | else => "", | 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,6 +707,7 @@ pub const LibExeObjStep = struct { |
| 697 | cflags: ArrayList([]const u8), | 707 | cflags: ArrayList([]const u8), |
| 698 | include_dirs: ArrayList([]const u8), | 708 | include_dirs: ArrayList([]const u8), |
| 699 | disable_libc: bool, | 709 | disable_libc: bool, |
| | 710 | frameworks: BufSet, |
| 700 | | 711 | |
| 701 | // zig only stuff | 712 | // zig only stuff |
| 702 | root_src: ?[]const u8, | 713 | root_src: ?[]const u8, |
| ... | @@ -787,6 +798,7 @@ pub const LibExeObjStep = struct { | ... | @@ -787,6 +798,7 @@ pub const LibExeObjStep = struct { |
| 787 | .target = Target.Native, | 798 | .target = Target.Native, |
| 788 | .linker_script = null, | 799 | .linker_script = null, |
| 789 | .link_libs = BufSet.init(builder.allocator), | 800 | .link_libs = BufSet.init(builder.allocator), |
| | 801 | .frameworks = BufSet.init(builder.allocator), |
| 790 | .step = Step.init(name, builder.allocator, make), | 802 | .step = Step.init(name, builder.allocator, make), |
| 791 | .output_path = null, | 803 | .output_path = null, |
| 792 | .output_h_path = null, | 804 | .output_h_path = null, |
| ... | @@ -824,6 +836,7 @@ pub const LibExeObjStep = struct { | ... | @@ -824,6 +836,7 @@ pub const LibExeObjStep = struct { |
| 824 | .object_files = ArrayList([]const u8).init(builder.allocator), | 836 | .object_files = ArrayList([]const u8).init(builder.allocator), |
| 825 | .step = Step.init(name, builder.allocator, make), | 837 | .step = Step.init(name, builder.allocator, make), |
| 826 | .link_libs = BufSet.init(builder.allocator), | 838 | .link_libs = BufSet.init(builder.allocator), |
| | 839 | .frameworks = BufSet.init(builder.allocator), |
| 827 | .full_path_libs = ArrayList([]const u8).init(builder.allocator), | 840 | .full_path_libs = ArrayList([]const u8).init(builder.allocator), |
| 828 | .include_dirs = ArrayList([]const u8).init(builder.allocator), | 841 | .include_dirs = ArrayList([]const u8).init(builder.allocator), |
| 829 | .output_path = null, | 842 | .output_path = null, |
| ... | @@ -861,11 +874,7 @@ pub const LibExeObjStep = struct { | ... | @@ -861,11 +874,7 @@ pub const LibExeObjStep = struct { |
| 861 | if (self.static) { | 874 | if (self.static) { |
| 862 | self.out_filename = self.builder.fmt("lib{}.a", self.name); | 875 | self.out_filename = self.builder.fmt("lib{}.a", self.name); |
| 863 | } else { | 876 | } else { |
| 864 | const target_os = switch (self.target) { | 877 | switch (self.target.getOs()) { |
| 865 | Target.Native => builtin.os, | | |
| 866 | Target.Cross => |t| t.os, | | |
| 867 | }; | | |
| 868 | switch (target_os) { | | |
| 869 | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => { | 878 | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => { |
| 870 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", | 879 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", |
| 871 | self.name, self.version.major, self.version.minor, self.version.patch); | 880 | self.name, self.version.major, self.version.minor, self.version.patch); |
| ... | @@ -905,6 +914,11 @@ pub const LibExeObjStep = struct { | ... | @@ -905,6 +914,11 @@ pub const LibExeObjStep = struct { |
| 905 | self.linker_script = path; | 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 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) { | 922 | pub fn linkLibrary(self: &LibExeObjStep, lib: &LibExeObjStep) { |
| 909 | assert(self.kind != Kind.Obj); | 923 | assert(self.kind != Kind.Obj); |
| 910 | assert(lib.kind == Kind.Lib); | 924 | assert(lib.kind == Kind.Lib); |
| ... | @@ -916,6 +930,14 @@ pub const LibExeObjStep = struct { | ... | @@ -916,6 +930,14 @@ pub const LibExeObjStep = struct { |
| 916 | // TODO should be some kind of isolated directory that only has this header in it | 930 | // TODO should be some kind of isolated directory that only has this header in it |
| 917 | %%self.include_dirs.append(self.builder.cache_root); | 931 | %%self.include_dirs.append(self.builder.cache_root); |
| 918 | self.need_flat_namespace_hack = true; | 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 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) { | 943 | pub fn linkSystemLibrary(self: &LibExeObjStep, name: []const u8) { |
| ... | @@ -1163,6 +1185,14 @@ pub const LibExeObjStep = struct { | ... | @@ -1163,6 +1185,14 @@ pub const LibExeObjStep = struct { |
| 1163 | %%zig_args.append(builder.pathFromRoot(full_path_lib)); | 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 | %return builder.spawnChild(builder.zig_exe, zig_args.toSliceConst()); | 1196 | %return builder.spawnChild(builder.zig_exe, zig_args.toSliceConst()); |
| 1167 | | 1197 | |
| 1168 | if (self.kind == Kind.Lib and !self.static) { | 1198 | if (self.kind == Kind.Lib and !self.static) { |
| ... | @@ -1225,14 +1255,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1225,14 +1255,7 @@ pub const LibExeObjStep = struct { |
| 1225 | var cc_args = ArrayList([]const u8).init(builder.allocator); | 1255 | var cc_args = ArrayList([]const u8).init(builder.allocator); |
| 1226 | defer cc_args.deinit(); | 1256 | defer cc_args.deinit(); |
| 1227 | | 1257 | |
| 1228 | const target_os = switch (self.target) { | 1258 | const is_darwin = self.target.isDarwin(); |
| 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 | }; | | |
| 1236 | | 1259 | |
| 1237 | switch (self.kind) { | 1260 | switch (self.kind) { |
| 1238 | Kind.Obj => { | 1261 | Kind.Obj => { |
| ... | @@ -1339,6 +1362,14 @@ pub const LibExeObjStep = struct { | ... | @@ -1339,6 +1362,14 @@ pub const LibExeObjStep = struct { |
| 1339 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); | 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 | %return builder.spawnChild(cc, cc_args.toSliceConst()); | 1373 | %return builder.spawnChild(cc, cc_args.toSliceConst()); |
| 1343 | | 1374 | |
| 1344 | %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, | 1375 | %return doAtomicSymLinks(builder.allocator, output_path, self.major_only_filename, |
| ... | @@ -1391,20 +1422,25 @@ pub const LibExeObjStep = struct { | ... | @@ -1391,20 +1422,25 @@ pub const LibExeObjStep = struct { |
| 1391 | | 1422 | |
| 1392 | %%cc_args.append("-rdynamic"); | 1423 | %%cc_args.append("-rdynamic"); |
| 1393 | | 1424 | |
| 1394 | switch (target_os) { | 1425 | if (is_darwin) { |
| 1395 | builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => { | 1426 | if (self.need_flat_namespace_hack) { |
| 1396 | if (self.need_flat_namespace_hack) { | 1427 | %%cc_args.append("-Wl,-flat_namespace"); |
| 1397 | %%cc_args.append("-Wl,-flat_namespace"); | 1428 | } |
| 1398 | } | 1429 | %%cc_args.append("-Wl,-search_paths_first"); |
| 1399 | %%cc_args.append("-Wl,-search_paths_first"); | | |
| 1400 | }, | | |
| 1401 | else => {} | | |
| 1402 | } | 1430 | } |
| 1403 | | 1431 | |
| 1404 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { | 1432 | for (self.full_path_libs.toSliceConst()) |full_path_lib| { |
| 1405 | %%cc_args.append(builder.pathFromRoot(full_path_lib)); | 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 | %return builder.spawnChild(cc, cc_args.toSliceConst()); | 1444 | %return builder.spawnChild(cc, cc_args.toSliceConst()); |
| 1409 | }, | 1445 | }, |
| 1410 | } | 1446 | } |