authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-02 18:36:51+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-02 18:38:09+01:00
log7f5c96378d0fa91265aef7a2d5c33c7953c23b5b
tree7982d871b169cf193afe507821a87fc71252b6fc
parent317c555a5cdc52612e998d8b4bcbaf730be1a6f1

Refactor the code according to Andrew's suggestions


4 files changed, 13 insertions(+), 59 deletions(-)

lib/std/build.zig+5-29
...@@ -1207,7 +1207,6 @@ pub const LibExeObjStep = struct {...@@ -1207,7 +1207,6 @@ pub const LibExeObjStep = struct {
1207 name_only_filename: []const u8,1207 name_only_filename: []const u8,
1208 strip: bool,1208 strip: bool,
1209 lib_paths: ArrayList([]const u8),1209 lib_paths: ArrayList([]const u8),
1210 syslibroot: ?[]const u8 = null,
1211 framework_dirs: ArrayList([]const u8),1210 framework_dirs: ArrayList([]const u8),
1212 frameworks: BufSet,1211 frameworks: BufSet,
1213 verbose_link: bool,1212 verbose_link: bool,
...@@ -1842,10 +1841,6 @@ pub const LibExeObjStep = struct {...@@ -1842,10 +1841,6 @@ pub const LibExeObjStep = struct {
1842 self.lib_paths.append(self.builder.dupe(path)) catch unreachable;1841 self.lib_paths.append(self.builder.dupe(path)) catch unreachable;
1843 }1842 }
18441843
1845 pub fn addSyslibroot(self: *LibExeObjStep, path: []const u8) void {
1846 self.syslibroot = path;
1847 }
1848
1849 pub fn addFrameworkDir(self: *LibExeObjStep, dir_path: []const u8) void {1844 pub fn addFrameworkDir(self: *LibExeObjStep, dir_path: []const u8) void {
1850 self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;1845 self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;
1851 }1846 }
...@@ -1920,18 +1915,11 @@ pub const LibExeObjStep = struct {...@@ -1920,18 +1915,11 @@ pub const LibExeObjStep = struct {
1920 }1915 }
1921 }1916 }
19221917
1923 if (self.target.isDarwin()) {1918 // Inherit dependencies on darwin frameworks
1924 // Inherit syslibroot1919 if (self.target.isDarwin() and !other.isDynamicLibrary()) {
1925 if (other.syslibroot) |path| {1920 var it = other.frameworks.iterator();
1926 self.syslibroot = path;1921 while (it.next()) |entry| {
1927 }1922 self.frameworks.put(entry.key) catch unreachable;
1928
1929 // Inherit dependencies on darwin frameworks
1930 if (!other.isDynamicLibrary()) {
1931 var it = other.frameworks.iterator();
1932 while (it.next()) |entry| {
1933 self.frameworks.put(entry.key) catch unreachable;
1934 }
1935 }1923 }
1936 }1924 }
1937 }1925 }
...@@ -2283,18 +2271,6 @@ pub const LibExeObjStep = struct {...@@ -2283,18 +2271,6 @@ pub const LibExeObjStep = struct {
2283 }2271 }
22842272
2285 if (self.target.isDarwin()) {2273 if (self.target.isDarwin()) {
2286 if (self.syslibroot) |path| {
2287 try zig_args.append("-syslibroot");
2288 try zig_args.append(path);
2289 } else {
2290 if (self.target.isNative()) {
2291 const syslibroot = try std.zig.system.getSDKPath(builder.allocator);
2292 errdefer builder.allocator.free(syslibroot);
2293 try zig_args.append("-syslibroot");
2294 try zig_args.append(syslibroot);
2295 }
2296 }
2297
2298 for (self.framework_dirs.span()) |dir| {2274 for (self.framework_dirs.span()) |dir| {
2299 try zig_args.append("-F");2275 try zig_args.append("-F");
2300 try zig_args.append(dir);2276 try zig_args.append(dir);
lib/std/zig/system/macos.zig+1-1
...@@ -461,7 +461,7 @@ test "version_from_build" {...@@ -461,7 +461,7 @@ test "version_from_build" {
461/// The caller needs to free the resulting path slice.461/// The caller needs to free the resulting path slice.
462pub fn getSDKPath(allocator: *mem.Allocator) ![]u8 {462pub fn getSDKPath(allocator: *mem.Allocator) ![]u8 {
463 assert(std.Target.current.isDarwin());463 assert(std.Target.current.isDarwin());
464 const argv = &[_][]const u8{ "/usr/bin/xcrun", "--show-sdk-path" };464 const argv = &[_][]const u8{ "xcrun", "--show-sdk-path" };
465 const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv });465 const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv });
466 defer {466 defer {
467 allocator.free(result.stderr);467 allocator.free(result.stderr);
src/Compilation.zig+6-2
...@@ -333,7 +333,6 @@ pub const InitOptions = struct {...@@ -333,7 +333,6 @@ pub const InitOptions = struct {
333 keep_source_files_loaded: bool = false,333 keep_source_files_loaded: bool = false,
334 clang_argv: []const []const u8 = &[0][]const u8{},334 clang_argv: []const []const u8 = &[0][]const u8{},
335 lld_argv: []const []const u8 = &[0][]const u8{},335 lld_argv: []const []const u8 = &[0][]const u8{},
336 syslibroot: ?[]const u8 = null,
337 lib_dirs: []const []const u8 = &[0][]const u8{},336 lib_dirs: []const []const u8 = &[0][]const u8{},
338 rpath_list: []const []const u8 = &[0][]const u8{},337 rpath_list: []const []const u8 = &[0][]const u8{},
339 c_source_files: []const CSourceFile = &[0]CSourceFile{},338 c_source_files: []const CSourceFile = &[0]CSourceFile{},
...@@ -473,6 +472,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -473,6 +472,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
473 break :blk false;472 break :blk false;
474 };473 };
475474
475 const syslibroot = if (use_lld and options.is_native_os and options.target.isDarwin()) blk: {
476 const syslibroot_path = try std.zig.system.getSDKPath(arena);
477 break :blk syslibroot_path;
478 } else null;
479
476 const link_libc = options.link_libc or target_util.osRequiresLibC(options.target);480 const link_libc = options.link_libc or target_util.osRequiresLibC(options.target);
477481
478 const must_dynamic_link = dl: {482 const must_dynamic_link = dl: {
...@@ -774,7 +778,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -774,7 +778,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
774 .frameworks = options.frameworks,778 .frameworks = options.frameworks,
775 .framework_dirs = options.framework_dirs,779 .framework_dirs = options.framework_dirs,
776 .system_libs = system_libs,780 .system_libs = system_libs,
777 .syslibroot = options.syslibroot,781 .syslibroot = syslibroot,
778 .lib_dirs = options.lib_dirs,782 .lib_dirs = options.lib_dirs,
779 .rpath_list = options.rpath_list,783 .rpath_list = options.rpath_list,
780 .strip = strip,784 .strip = strip,
src/main.zig+1-27
...@@ -315,9 +315,8 @@ const usage_build_generic =...@@ -315,9 +315,8 @@ const usage_build_generic =
315 \\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"315 \\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
316 \\ --stack [size] Override default stack size316 \\ --stack [size] Override default stack size
317 \\ --image-base [addr] Set base address for executable image317 \\ --image-base [addr] Set base address for executable image
318 \\ -syslibroot [dir] (darwin) prepend a prefix to all search paths
319 \\ -framework [name] (darwin) link against framework318 \\ -framework [name] (darwin) link against framework
320 \\ -F [dir] (darwin) add search path for frameworks319 \\ -F[dir] (darwin) add search path for frameworks
321 \\320 \\
322 \\Test Options:321 \\Test Options:
323 \\ --test-filter [text] Skip tests that do not match filter322 \\ --test-filter [text] Skip tests that do not match filter
...@@ -493,7 +492,6 @@ fn buildOutputType(...@@ -493,7 +492,6 @@ fn buildOutputType(
493 var main_pkg_path: ?[]const u8 = null;492 var main_pkg_path: ?[]const u8 = null;
494 var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;493 var clang_preprocessor_mode: Compilation.ClangPreprocessorMode = .no;
495 var subsystem: ?std.Target.SubSystem = null;494 var subsystem: ?std.Target.SubSystem = null;
496 var syslibroot: ?[]const u8 = null;
497495
498 var system_libs = std.ArrayList([]const u8).init(gpa);496 var system_libs = std.ArrayList([]const u8).init(gpa);
499 defer system_libs.deinit();497 defer system_libs.deinit();
...@@ -684,10 +682,6 @@ fn buildOutputType(...@@ -684,10 +682,6 @@ fn buildOutputType(
684 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});682 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
685 i += 1;683 i += 1;
686 try lib_dirs.append(args[i]);684 try lib_dirs.append(args[i]);
687 } else if (mem.eql(u8, arg, "-syslibroot")) {
688 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
689 i += 1;
690 syslibroot = args[i];
691 } else if (mem.eql(u8, arg, "-F")) {685 } else if (mem.eql(u8, arg, "-F")) {
692 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});686 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
693 i += 1;687 i += 1;
...@@ -1386,12 +1380,6 @@ fn buildOutputType(...@@ -1386,12 +1380,6 @@ fn buildOutputType(
1386 }1380 }
1387 }1381 }
13881382
1389 if (cross_target.isNativeOs() and std.Target.current.isDarwin()) {
1390 if (syslibroot == null) {
1391 syslibroot = try std.zig.system.getSDKPath(arena);
1392 }
1393 }
1394
1395 const object_format: std.Target.ObjectFormat = blk: {1383 const object_format: std.Target.ObjectFormat = blk: {
1396 const ofmt = target_ofmt orelse break :blk target_info.target.getObjectFormat();1384 const ofmt = target_ofmt orelse break :blk target_info.target.getObjectFormat();
1397 if (mem.eql(u8, ofmt, "elf")) {1385 if (mem.eql(u8, ofmt, "elf")) {
...@@ -1640,7 +1628,6 @@ fn buildOutputType(...@@ -1640,7 +1628,6 @@ fn buildOutputType(
1640 .rpath_list = rpath_list.items,1628 .rpath_list = rpath_list.items,
1641 .c_source_files = c_source_files.items,1629 .c_source_files = c_source_files.items,
1642 .link_objects = link_objects.items,1630 .link_objects = link_objects.items,
1643 .syslibroot = syslibroot,
1644 .framework_dirs = framework_dirs.items,1631 .framework_dirs = framework_dirs.items,
1645 .frameworks = frameworks.items,1632 .frameworks = frameworks.items,
1646 .system_libs = system_libs.items,1633 .system_libs = system_libs.items,
...@@ -2172,7 +2159,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2172,7 +2159,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2172 var override_lib_dir: ?[]const u8 = null;2159 var override_lib_dir: ?[]const u8 = null;
2173 var override_global_cache_dir: ?[]const u8 = null;2160 var override_global_cache_dir: ?[]const u8 = null;
2174 var override_local_cache_dir: ?[]const u8 = null;2161 var override_local_cache_dir: ?[]const u8 = null;
2175 var syslibroot: ?[]const u8 = null;
2176 var child_argv = std.ArrayList([]const u8).init(arena);2162 var child_argv = std.ArrayList([]const u8).init(arena);
21772163
2178 const argv_index_exe = child_argv.items.len;2164 const argv_index_exe = child_argv.items.len;
...@@ -2214,11 +2200,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2214,11 +2200,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2214 override_global_cache_dir = args[i];2200 override_global_cache_dir = args[i];
2215 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });2201 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
2216 continue;2202 continue;
2217 } else if (mem.eql(u8, arg, "--syslibroot")) {
2218 if (i + 1 >= args.len) fatal("expected argument after '{}'", .{arg});
2219 i += 1;
2220 syslibroot = args[i];
2221 continue;
2222 }2203 }
2223 }2204 }
2224 try child_argv.append(arg);2205 try child_argv.append(arg);
...@@ -2324,12 +2305,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2324,12 +2305,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2324 const cross_target: std.zig.CrossTarget = .{};2305 const cross_target: std.zig.CrossTarget = .{};
2325 const target_info = try detectNativeTargetInfo(gpa, cross_target);2306 const target_info = try detectNativeTargetInfo(gpa, cross_target);
23262307
2327 if (cross_target.isNativeOs() and target_info.target.isDarwin()) {
2328 if (syslibroot == null) {
2329 syslibroot = try std.zig.system.getSDKPath(arena);
2330 }
2331 }
2332
2333 const exe_basename = try std.zig.binNameAlloc(arena, .{2308 const exe_basename = try std.zig.binNameAlloc(arena, .{
2334 .root_name = "build",2309 .root_name = "build",
2335 .target = target_info.target,2310 .target = target_info.target,
...@@ -2353,7 +2328,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v...@@ -2353,7 +2328,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
2353 .target = target_info.target,2328 .target = target_info.target,
2354 .is_native_os = cross_target.isNativeOs(),2329 .is_native_os = cross_target.isNativeOs(),
2355 .dynamic_linker = target_info.dynamic_linker.get(),2330 .dynamic_linker = target_info.dynamic_linker.get(),
2356 .syslibroot = syslibroot,
2357 .output_mode = .Exe,2331 .output_mode = .Exe,
2358 .root_pkg = &root_pkg,2332 .root_pkg = &root_pkg,
2359 .emit_bin = emit_bin,2333 .emit_bin = emit_bin,