authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-02 21:49:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-03 09:52:15-07:00
log4089f96defa7dae169e2b6cdba5e545293e57cb8
treeaa5113504d95d1cb94a993e76bce05d0db01d64a
parent9dd9aa49a59cf8534aaf9b44ee20d526ba8da1c6

darwin: pass -iframework to clang for system frameworks


2 files changed, 22 insertions(+), 6 deletions(-)

src/Compilation.zig+20-1
...@@ -124,6 +124,7 @@ zig_lib_directory: Directory,...@@ -124,6 +124,7 @@ zig_lib_directory: Directory,
124local_cache_directory: Directory,124local_cache_directory: Directory,
125global_cache_directory: Directory,125global_cache_directory: Directory,
126libc_include_dir_list: []const []const u8,126libc_include_dir_list: []const []const u8,
127libc_framework_dir_list: []const []const u8,
127thread_pool: *ThreadPool,128thread_pool: *ThreadPool,
128129
129/// Populated when we build the libc++ static library. A Job to build this is placed in the queue130/// Populated when we build the libc++ static library. A Job to build this is placed in the queue
...@@ -1593,6 +1594,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1593,6 +1594,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1593 .cache_parent = cache,1594 .cache_parent = cache,
1594 .self_exe_path = options.self_exe_path,1595 .self_exe_path = options.self_exe_path,
1595 .libc_include_dir_list = libc_dirs.libc_include_dir_list,1596 .libc_include_dir_list = libc_dirs.libc_include_dir_list,
1597 .libc_framework_dir_list = libc_dirs.libc_framework_dir_list,
1596 .sanitize_c = sanitize_c,1598 .sanitize_c = sanitize_c,
1597 .thread_pool = options.thread_pool,1599 .thread_pool = options.thread_pool,
1598 .clang_passthrough_mode = options.clang_passthrough_mode,1600 .clang_passthrough_mode = options.clang_passthrough_mode,
...@@ -4335,8 +4337,12 @@ pub fn addCCArgs(...@@ -4335,8 +4337,12 @@ pub fn addCCArgs(
4335 try argv.append("-ObjC++");4337 try argv.append("-ObjC++");
4336 }4338 }
43374339
4340 for (comp.libc_framework_dir_list) |framework_dir| {
4341 try argv.appendSlice(&.{ "-iframework", framework_dir });
4342 }
4343
4338 for (comp.bin_file.options.framework_dirs) |framework_dir| {4344 for (comp.bin_file.options.framework_dirs) |framework_dir| {
4339 try argv.appendSlice(&.{ "-isystem", framework_dir });4345 try argv.appendSlice(&.{ "-F", framework_dir });
4340 }4346 }
43414347
4342 // According to Rich Felker libc headers are supposed to go before C language headers.4348 // According to Rich Felker libc headers are supposed to go before C language headers.
...@@ -4821,6 +4827,7 @@ test "classifyFileExt" {...@@ -4821,6 +4827,7 @@ test "classifyFileExt" {
4821const LibCDirs = struct {4827const LibCDirs = struct {
4822 libc_include_dir_list: []const []const u8,4828 libc_include_dir_list: []const []const u8,
4823 libc_installation: ?*const LibCInstallation,4829 libc_installation: ?*const LibCInstallation,
4830 libc_framework_dir_list: []const []const u8,
4824};4831};
48254832
4826fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs {4833fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs {
...@@ -4851,6 +4858,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8,...@@ -4851,6 +4858,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8,
4851 return LibCDirs{4858 return LibCDirs{
4852 .libc_include_dir_list = list,4859 .libc_include_dir_list = list,
4853 .libc_installation = null,4860 .libc_installation = null,
4861 .libc_framework_dir_list = &.{},
4854 };4862 };
4855}4863}
48564864
...@@ -4866,6 +4874,7 @@ fn detectLibCIncludeDirs(...@@ -4866,6 +4874,7 @@ fn detectLibCIncludeDirs(
4866 return LibCDirs{4874 return LibCDirs{
4867 .libc_include_dir_list = &[0][]u8{},4875 .libc_include_dir_list = &[0][]u8{},
4868 .libc_installation = null,4876 .libc_installation = null,
4877 .libc_framework_dir_list = &.{},
4869 };4878 };
4870 }4879 }
48714880
...@@ -4921,11 +4930,13 @@ fn detectLibCIncludeDirs(...@@ -4921,11 +4930,13 @@ fn detectLibCIncludeDirs(
4921 return LibCDirs{4930 return LibCDirs{
4922 .libc_include_dir_list = &[0][]u8{},4931 .libc_include_dir_list = &[0][]u8{},
4923 .libc_installation = null,4932 .libc_installation = null,
4933 .libc_framework_dir_list = &.{},
4924 };4934 };
4925}4935}
49264936
4927fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs {4937fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs {
4928 var list = try std.ArrayList([]const u8).initCapacity(arena, 5);4938 var list = try std.ArrayList([]const u8).initCapacity(arena, 5);
4939 var framework_list = std.ArrayList([]const u8).init(arena);
49294940
4930 list.appendAssumeCapacity(lci.include_dir.?);4941 list.appendAssumeCapacity(lci.include_dir.?);
49314942
...@@ -4953,9 +4964,16 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const...@@ -4953,9 +4964,16 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const
4953 list.appendAssumeCapacity(config_dir);4964 list.appendAssumeCapacity(config_dir);
4954 }4965 }
49554966
4967 if (target.isDarwin()) d: {
4968 const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
4969 const down2 = std.fs.path.dirname(down1) orelse break :d;
4970 try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
4971 }
4972
4956 return LibCDirs{4973 return LibCDirs{
4957 .libc_include_dir_list = list.items,4974 .libc_include_dir_list = list.items,
4958 .libc_installation = lci,4975 .libc_installation = lci,
4976 .libc_framework_dir_list = framework_list.items,
4959 };4977 };
4960}4978}
49614979
...@@ -5015,6 +5033,7 @@ fn detectLibCFromBuilding(...@@ -5015,6 +5033,7 @@ fn detectLibCFromBuilding(
5015 return LibCDirs{5033 return LibCDirs{
5016 .libc_include_dir_list = list,5034 .libc_include_dir_list = list,
5017 .libc_installation = null,5035 .libc_installation = null,
5036 .libc_framework_dir_list = &.{},
5018 };5037 };
5019}5038}
50205039
src/main.zig+2-5
...@@ -2695,11 +2695,8 @@ fn buildOutputType(...@@ -2695,11 +2695,8 @@ fn buildOutputType(
2695 try rpath_list.appendSlice(paths.rpaths.items);2695 try rpath_list.appendSlice(paths.rpaths.items);
2696 }2696 }
26972697
2698 // Now that we have target info, we can find out if any of the system libraries2698 // If any libs in this list are statically provided, we omit them from the
2699 // are part of libc or libc++. We remove them from the list and communicate their2699 // resolved list and populate the link_objects array instead.
2700 // existence via flags instead.
2701 // Similarly, if any libs in this list are statically provided, we omit
2702 // them from the resolved list and populate the link_objects array instead.
2703 {2700 {
2704 var test_path = std.ArrayList(u8).init(gpa);2701 var test_path = std.ArrayList(u8).init(gpa);
2705 defer test_path.deinit();2702 defer test_path.deinit();