| ... | @@ -97,8 +97,6 @@ out_lib_filename: []const u8, | ... | @@ -97,8 +97,6 @@ out_lib_filename: []const u8, |
| 97 | out_pdb_filename: []const u8, | 97 | out_pdb_filename: []const u8, |
| 98 | modules: std.StringArrayHashMap(*Module), | 98 | modules: std.StringArrayHashMap(*Module), |
| 99 | | 99 | |
| 100 | object_src: []const u8, | | |
| 101 | | | |
| 102 | link_objects: ArrayList(LinkObject), | 100 | link_objects: ArrayList(LinkObject), |
| 103 | include_dirs: ArrayList(IncludeDir), | 101 | include_dirs: ArrayList(IncludeDir), |
| 104 | c_macros: ArrayList([]const u8), | 102 | c_macros: ArrayList([]const u8), |
| ... | @@ -287,6 +285,8 @@ pub const Options = struct { | ... | @@ -287,6 +285,8 @@ pub const Options = struct { |
| 287 | linkage: ?Linkage = null, | 285 | linkage: ?Linkage = null, |
| 288 | version: ?std.builtin.Version = null, | 286 | version: ?std.builtin.Version = null, |
| 289 | max_rss: usize = 0, | 287 | max_rss: usize = 0, |
| | 288 | filter: ?[]const u8 = null, |
| | 289 | test_runner: ?[]const u8 = null, |
| 290 | }; | 290 | }; |
| 291 | | 291 | |
| 292 | pub const Kind = enum { | 292 | pub const Kind = enum { |
| ... | @@ -339,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -339,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 339 | options.target.zigTriple(owner.allocator) catch @panic("OOM"), | 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 | const self = owner.allocator.create(CompileStep) catch @panic("OOM"); | 359 | const self = owner.allocator.create(CompileStep) catch @panic("OOM"); |
| 343 | self.* = CompileStep{ | 360 | self.* = CompileStep{ |
| 344 | .strip = null, | 361 | .strip = null, |
| ... | @@ -360,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -360,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 360 | .max_rss = options.max_rss, | 377 | .max_rss = options.max_rss, |
| 361 | }), | 378 | }), |
| 362 | .version = options.version, | 379 | .version = options.version, |
| 363 | .out_filename = undefined, | 380 | .out_filename = out_filename, |
| 364 | .out_h_filename = owner.fmt("{s}.h", .{name}), | 381 | .out_h_filename = owner.fmt("{s}.h", .{name}), |
| 365 | .out_lib_filename = undefined, | 382 | .out_lib_filename = undefined, |
| 366 | .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), | 383 | .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), |
| ... | @@ -374,13 +391,12 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -374,13 +391,12 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 374 | .rpaths = ArrayList(FileSource).init(owner.allocator), | 391 | .rpaths = ArrayList(FileSource).init(owner.allocator), |
| 375 | .framework_dirs = ArrayList(FileSource).init(owner.allocator), | 392 | .framework_dirs = ArrayList(FileSource).init(owner.allocator), |
| 376 | .installed_headers = ArrayList(*Step).init(owner.allocator), | 393 | .installed_headers = ArrayList(*Step).init(owner.allocator), |
| 377 | .object_src = undefined, | | |
| 378 | .c_std = std.Build.CStd.C99, | 394 | .c_std = std.Build.CStd.C99, |
| 379 | .zig_lib_dir = null, | 395 | .zig_lib_dir = null, |
| 380 | .main_pkg_path = null, | 396 | .main_pkg_path = null, |
| 381 | .exec_cmd_args = null, | 397 | .exec_cmd_args = null, |
| 382 | .filter = null, | 398 | .filter = options.filter, |
| 383 | .test_runner = null, | 399 | .test_runner = options.test_runner, |
| 384 | .disable_stack_probing = false, | 400 | .disable_stack_probing = false, |
| 385 | .disable_sanitize_c = false, | 401 | .disable_sanitize_c = false, |
| 386 | .sanitize_thread = false, | 402 | .sanitize_thread = false, |
| ... | @@ -395,60 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -395,60 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 395 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, | 411 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, |
| 396 | .output_dirname_source = GeneratedFile{ .step = &self.step }, | 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 | if (self.kind == .lib) { | 417 | if (self.kind == .lib) { |
| 425 | if (self.linkage != null and self.linkage.? == .static) { | 418 | if (self.linkage != null and self.linkage.? == .static) { |
| 426 | self.out_lib_filename = self.out_filename; | 419 | self.out_lib_filename = self.out_filename; |
| 427 | } else if (self.version) |version| { | 420 | } else if (self.version) |version| { |
| 428 | if (target.isDarwin()) { | 421 | if (target_info.target.isDarwin()) { |
| 429 | self.major_only_filename = b.fmt("lib{s}.{d}.dylib", .{ | 422 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ |
| 430 | self.name, | 423 | self.name, |
| 431 | version.major, | 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 | self.out_lib_filename = self.out_filename; | 427 | self.out_lib_filename = self.out_filename; |
| 435 | } else if (target.os.tag == .windows) { | 428 | } else if (target_info.target.os.tag == .windows) { |
| 436 | self.out_lib_filename = b.fmt("{s}.lib", .{self.name}); | 429 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 437 | } else { | 430 | } else { |
| 438 | self.major_only_filename = b.fmt("lib{s}.so.{d}", .{ self.name, version.major }); | 431 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); |
| 439 | self.name_only_filename = b.fmt("lib{s}.so", .{self.name}); | 432 | self.name_only_filename = owner.fmt("lib{s}.so", .{self.name}); |
| 440 | self.out_lib_filename = self.out_filename; | 433 | self.out_lib_filename = self.out_filename; |
| 441 | } | 434 | } |
| 442 | } else { | 435 | } else { |
| 443 | if (target.isDarwin()) { | 436 | if (target_info.target.isDarwin()) { |
| 444 | self.out_lib_filename = self.out_filename; | 437 | self.out_lib_filename = self.out_filename; |
| 445 | } else if (target.os.tag == .windows) { | 438 | } else if (target_info.target.os.tag == .windows) { |
| 446 | self.out_lib_filename = b.fmt("{s}.lib", .{self.name}); | 439 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 447 | } else { | 440 | } else { |
| 448 | self.out_lib_filename = self.out_filename; | 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 | pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void { | 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,24 +838,6 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct { |
| 841 | }) catch @panic("OOM"); | 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 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 841 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 863 | pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { | 842 | pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { |
| 864 | const b = self.step.owner; | 843 | const b = self.step.owner; |