| ... | ... | @@ -97,8 +97,6 @@ out_lib_filename: []const u8, |
| 97 | 97 | out_pdb_filename: []const u8, |
| 98 | 98 | modules: std.StringArrayHashMap(*Module), |
| 99 | 99 | |
| 100 | | object_src: []const u8, |
| 101 | | |
| 102 | 100 | link_objects: ArrayList(LinkObject), |
| 103 | 101 | include_dirs: ArrayList(IncludeDir), |
| 104 | 102 | c_macros: ArrayList([]const u8), |
| ... | ... | @@ -287,6 +285,8 @@ pub const Options = struct { |
| 287 | 285 | linkage: ?Linkage = null, |
| 288 | 286 | version: ?std.builtin.Version = null, |
| 289 | 287 | max_rss: usize = 0, |
| 288 | filter: ?[]const u8 = null, |
| 289 | test_runner: ?[]const u8 = null, |
| 290 | 290 | }; |
| 291 | 291 | |
| 292 | 292 | pub const Kind = enum { |
| ... | ... | @@ -339,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 339 | 339 | options.target.zigTriple(owner.allocator) catch @panic("OOM"), |
| 340 | 340 | }); |
| 341 | 341 | |
| 342 | const target_info = NativeTargetInfo.detect(options.target) catch @panic("unhandled error"); |
| 343 | |
| 344 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ |
| 345 | .root_name = name, |
| 346 | .target = target_info.target, |
| 347 | .output_mode = switch (options.kind) { |
| 348 | .lib => .Lib, |
| 349 | .obj => .Obj, |
| 350 | .exe, .@"test" => .Exe, |
| 351 | }, |
| 352 | .link_mode = if (options.linkage) |some| @as(std.builtin.LinkMode, switch (some) { |
| 353 | .dynamic => .Dynamic, |
| 354 | .static => .Static, |
| 355 | }) else null, |
| 356 | .version = options.version, |
| 357 | }) catch @panic("OOM"); |
| 358 | |
| 342 | 359 | const self = owner.allocator.create(CompileStep) catch @panic("OOM"); |
| 343 | 360 | self.* = CompileStep{ |
| 344 | 361 | .strip = null, |
| ... | ... | @@ -360,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 360 | 377 | .max_rss = options.max_rss, |
| 361 | 378 | }), |
| 362 | 379 | .version = options.version, |
| 363 | | .out_filename = undefined, |
| 380 | .out_filename = out_filename, |
| 364 | 381 | .out_h_filename = owner.fmt("{s}.h", .{name}), |
| 365 | 382 | .out_lib_filename = undefined, |
| 366 | 383 | .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), |
| ... | ... | @@ -374,13 +391,12 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 374 | 391 | .rpaths = ArrayList(FileSource).init(owner.allocator), |
| 375 | 392 | .framework_dirs = ArrayList(FileSource).init(owner.allocator), |
| 376 | 393 | .installed_headers = ArrayList(*Step).init(owner.allocator), |
| 377 | | .object_src = undefined, |
| 378 | 394 | .c_std = std.Build.CStd.C99, |
| 379 | 395 | .zig_lib_dir = null, |
| 380 | 396 | .main_pkg_path = null, |
| 381 | 397 | .exec_cmd_args = null, |
| 382 | | .filter = null, |
| 383 | | .test_runner = null, |
| 398 | .filter = options.filter, |
| 399 | .test_runner = options.test_runner, |
| 384 | 400 | .disable_stack_probing = false, |
| 385 | 401 | .disable_sanitize_c = false, |
| 386 | 402 | .sanitize_thread = false, |
| ... | ... | @@ -395,60 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 395 | 411 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, |
| 396 | 412 | .output_dirname_source = GeneratedFile{ .step = &self.step }, |
| 397 | 413 | |
| 398 | | .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"), |
| 414 | .target_info = target_info, |
| 399 | 415 | }; |
| 400 | | self.computeOutFileNames(); |
| 401 | | if (root_src) |rs| rs.addStepDependencies(&self.step); |
| 402 | | return self; |
| 403 | | } |
| 404 | | |
| 405 | | fn computeOutFileNames(self: *CompileStep) void { |
| 406 | | const b = self.step.owner; |
| 407 | | const target = self.target_info.target; |
| 408 | | |
| 409 | | self.out_filename = std.zig.binNameAlloc(b.allocator, .{ |
| 410 | | .root_name = self.name, |
| 411 | | .target = target, |
| 412 | | .output_mode = switch (self.kind) { |
| 413 | | .lib => .Lib, |
| 414 | | .obj => .Obj, |
| 415 | | .exe, .@"test" => .Exe, |
| 416 | | }, |
| 417 | | .link_mode = if (self.linkage) |some| @as(std.builtin.LinkMode, switch (some) { |
| 418 | | .dynamic => .Dynamic, |
| 419 | | .static => .Static, |
| 420 | | }) else null, |
| 421 | | .version = self.version, |
| 422 | | }) catch @panic("OOM"); |
| 423 | 416 | |
| 424 | 417 | if (self.kind == .lib) { |
| 425 | 418 | if (self.linkage != null and self.linkage.? == .static) { |
| 426 | 419 | self.out_lib_filename = self.out_filename; |
| 427 | 420 | } else if (self.version) |version| { |
| 428 | | if (target.isDarwin()) { |
| 429 | | self.major_only_filename = b.fmt("lib{s}.{d}.dylib", .{ |
| 421 | if (target_info.target.isDarwin()) { |
| 422 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ |
| 430 | 423 | self.name, |
| 431 | 424 | version.major, |
| 432 | 425 | }); |
| 433 | | self.name_only_filename = b.fmt("lib{s}.dylib", .{self.name}); |
| 426 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); |
| 434 | 427 | self.out_lib_filename = self.out_filename; |
| 435 | | } else if (target.os.tag == .windows) { |
| 436 | | self.out_lib_filename = b.fmt("{s}.lib", .{self.name}); |
| 428 | } else if (target_info.target.os.tag == .windows) { |
| 429 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 437 | 430 | } else { |
| 438 | | self.major_only_filename = b.fmt("lib{s}.so.{d}", .{ self.name, version.major }); |
| 439 | | self.name_only_filename = b.fmt("lib{s}.so", .{self.name}); |
| 431 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); |
| 432 | self.name_only_filename = owner.fmt("lib{s}.so", .{self.name}); |
| 440 | 433 | self.out_lib_filename = self.out_filename; |
| 441 | 434 | } |
| 442 | 435 | } else { |
| 443 | | if (target.isDarwin()) { |
| 436 | if (target_info.target.isDarwin()) { |
| 444 | 437 | self.out_lib_filename = self.out_filename; |
| 445 | | } else if (target.os.tag == .windows) { |
| 446 | | self.out_lib_filename = b.fmt("{s}.lib", .{self.name}); |
| 438 | } else if (target_info.target.os.tag == .windows) { |
| 439 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 447 | 440 | } else { |
| 448 | 441 | self.out_lib_filename = self.out_filename; |
| 449 | 442 | } |
| 450 | 443 | } |
| 451 | 444 | } |
| 445 | |
| 446 | if (root_src) |rs| rs.addStepDependencies(&self.step); |
| 447 | |
| 448 | return self; |
| 452 | 449 | } |
| 453 | 450 | |
| 454 | 451 | pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void { |
| ... | ... | @@ -841,24 +838,6 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct { |
| 841 | 838 | }) catch @panic("OOM"); |
| 842 | 839 | } |
| 843 | 840 | |
| 844 | | pub fn setName(self: *CompileStep, text: []const u8) void { |
| 845 | | const b = self.step.owner; |
| 846 | | assert(self.kind == .@"test"); |
| 847 | | self.name = b.dupe(text); |
| 848 | | } |
| 849 | | |
| 850 | | pub fn setFilter(self: *CompileStep, text: ?[]const u8) void { |
| 851 | | const b = self.step.owner; |
| 852 | | assert(self.kind == .@"test"); |
| 853 | | self.filter = if (text) |t| b.dupe(t) else null; |
| 854 | | } |
| 855 | | |
| 856 | | pub fn setTestRunner(self: *CompileStep, path: ?[]const u8) void { |
| 857 | | const b = self.step.owner; |
| 858 | | assert(self.kind == .@"test"); |
| 859 | | self.test_runner = if (path) |p| b.dupePath(p) else null; |
| 860 | | } |
| 861 | | |
| 862 | 841 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 863 | 842 | pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { |
| 864 | 843 | const b = self.step.owner; |