| author | |
| committer | |
| log | 71ff60f1265da83e619b1b6b2488ecb448fdfd36 |
| tree | c38e652543d15bae6eebb03a2ec4711e56611d42 |
| parent | 063888afff75f9d91fd221d84e1b74b111304ac3 |
This is a breaking change that makes the API for creating build
artifacts no longer have any period of time where the target and
optimization mode are not set.2 files changed, 120 insertions(+), 127 deletions(-)
lib/std/build.zig+98-68| ... | @@ -414,82 +414,123 @@ pub const Builder = struct { | ... | @@ -414,82 +414,123 @@ pub const Builder = struct { |
| 414 | self.h_dir = self.pathJoin(&h_list); | 414 | self.h_dir = self.pathJoin(&h_list); |
| 415 | } | 415 | } |
| 416 | 416 | ||
| 417 | fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource { | ||
| 418 | return if (path) |p| | ||
| 419 | FileSource{ .path = p } | ||
| 420 | else | ||
| 421 | null; | ||
| 422 | } | ||
| 423 | |||
| 424 | pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { | ||
| 425 | return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src)); | ||
| 426 | } | ||
| 427 | |||
| 428 | pub fn addExecutableSource(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | ||
| 429 | return LibExeObjStep.createExecutable(builder, name, root_src); | ||
| 430 | } | ||
| 431 | |||
| 432 | pub fn addOptions(self: *Builder) *OptionsStep { | 417 | pub fn addOptions(self: *Builder) *OptionsStep { |
| 433 | return OptionsStep.create(self); | 418 | return OptionsStep.create(self); |
| 434 | } | 419 | } |
| 435 | 420 | ||
| 436 | pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { | 421 | pub const ExecutableOptions = struct { |
| 437 | return addObjectSource(self, name, convertOptionalPathToFileSource(root_src)); | ||
| 438 | } | ||
| 439 | |||
| 440 | pub fn addObjectSource(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | ||
| 441 | return LibExeObjStep.createObject(builder, name, root_src); | ||
| 442 | } | ||
| 443 | |||
| 444 | pub fn addSharedLibrary( | ||
| 445 | self: *Builder, | ||
| 446 | name: []const u8, | 422 | name: []const u8, |
| 447 | root_src: ?[]const u8, | 423 | root_source_file: ?FileSource, |
| 448 | kind: LibExeObjStep.SharedLibKind, | 424 | version: ?std.builtin.Version = null, |
| 449 | ) *LibExeObjStep { | 425 | target: CrossTarget, |
| 450 | return addSharedLibrarySource(self, name, convertOptionalPathToFileSource(root_src), kind); | 426 | optimize: std.builtin.Mode, |
| 427 | linkage: ?LibExeObjStep.Linkage = null, | ||
| 428 | }; | ||
| 429 | |||
| 430 | pub fn addExecutable(b: *Builder, options: ExecutableOptions) *LibExeObjStep { | ||
| 431 | return LibExeObjStep.create(b, .{ | ||
| 432 | .name = options.name, | ||
| 433 | .root_source_file = options.root_source_file, | ||
| 434 | .version = options.version, | ||
| 435 | .target = options.target, | ||
| 436 | .optimize = options.optimize, | ||
| 437 | .kind = .exe, | ||
| 438 | .linkage = options.linkage, | ||
| 439 | .version = options.version, | ||
| 440 | }); | ||
| 451 | } | 441 | } |
| 452 | 442 | ||
| 453 | pub fn addSharedLibrarySource( | 443 | pub const ObjectOptions = struct { |
| 454 | self: *Builder, | ||
| 455 | name: []const u8, | 444 | name: []const u8, |
| 456 | root_src: ?FileSource, | 445 | root_source_file: ?FileSource, |
| 457 | kind: LibExeObjStep.SharedLibKind, | 446 | target: CrossTarget, |
| 458 | ) *LibExeObjStep { | 447 | optimize: std.builtin.Mode, |
| 459 | return LibExeObjStep.createSharedLibrary(self, name, root_src, kind); | 448 | }; |
| 460 | } | ||
| 461 | 449 | ||
| 462 | pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { | 450 | pub fn addObject(b: *Builder, options: ObjectOptions) *LibExeObjStep { |
| 463 | return addStaticLibrarySource(self, name, convertOptionalPathToFileSource(root_src)); | 451 | return LibExeObjStep.create(b, .{ |
| 452 | .name = options.name, | ||
| 453 | .root_source_file = options.root_source_file, | ||
| 454 | .target = options.target, | ||
| 455 | .optimize = options.optimize, | ||
| 456 | .kind = .obj, | ||
| 457 | }); | ||
| 464 | } | 458 | } |
| 465 | 459 | ||
| 466 | pub fn addStaticLibrarySource(self: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | 460 | pub const SharedLibraryOptions = struct { |
| 467 | return LibExeObjStep.createStaticLibrary(self, name, root_src); | 461 | name: []const u8, |
| 468 | } | 462 | root_source_file: ?FileSource, |
| 463 | version: ?std.builtin.Version = null, | ||
| 464 | target: CrossTarget, | ||
| 465 | optimize: std.builtin.Mode, | ||
| 466 | }; | ||
| 469 | 467 | ||
| 470 | pub fn addTest(self: *Builder, root_src: []const u8) *LibExeObjStep { | 468 | pub fn addSharedLibrary(b: *Builder, options: SharedLibraryOptions) *LibExeObjStep { |
| 471 | return LibExeObjStep.createTest(self, "test", .{ .path = root_src }); | 469 | return LibExeObjStep.create(b, .{ |
| 470 | .name = options.name, | ||
| 471 | .root_source_file = options.root_source_file, | ||
| 472 | .kind = .lib, | ||
| 473 | .linkage = .dynamic, | ||
| 474 | .version = options.version, | ||
| 475 | .target = options.target, | ||
| 476 | .optimize = options.optimize, | ||
| 477 | }); | ||
| 472 | } | 478 | } |
| 473 | 479 | ||
| 474 | pub fn addTestSource(self: *Builder, root_src: FileSource) *LibExeObjStep { | 480 | pub const StaticLibraryOptions = struct { |
| 475 | return LibExeObjStep.createTest(self, "test", root_src.dupe(self)); | 481 | name: []const u8, |
| 476 | } | 482 | root_source_file: ?FileSource = null, |
| 483 | target: CrossTarget, | ||
| 484 | optimize: std.builtin.Mode, | ||
| 485 | version: ?std.builtin.Version = null, | ||
| 486 | }; | ||
| 477 | 487 | ||
| 478 | pub fn addTestExe(self: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep { | 488 | pub fn addStaticLibrary(b: *Builder, options: StaticLibraryOptions) *LibExeObjStep { |
| 479 | return LibExeObjStep.createTestExe(self, name, .{ .path = root_src }); | 489 | return LibExeObjStep.create(b, .{ |
| 480 | } | 490 | .name = options.name, |
| 491 | .root_source_file = options.root_source_file, | ||
| 492 | .kind = .lib, | ||
| 493 | .linkage = .static, | ||
| 494 | .version = options.version, | ||
| 495 | .target = options.target, | ||
| 496 | .optimize = options.optimize, | ||
| 497 | }); | ||
| 498 | } | ||
| 499 | |||
| 500 | pub const TestOptions = struct { | ||
| 501 | name: []const u8 = "test", | ||
| 502 | kind: LibExeObjStep.Kind = .@"test", | ||
| 503 | root_source_file: FileSource, | ||
| 504 | target: CrossTarget, | ||
| 505 | optimize: std.builtin.Mode, | ||
| 506 | version: ?std.builtin.Version = null, | ||
| 507 | }; | ||
| 481 | 508 | ||
| 482 | pub fn addTestExeSource(self: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { | 509 | pub fn addTest(b: *Builder, options: TestOptions) *LibExeObjStep { |
| 483 | return LibExeObjStep.createTestExe(self, name, root_src.dupe(self)); | 510 | return LibExeObjStep.create(b, .{ |
| 511 | .name = options.name, | ||
| 512 | .kind = options.kind, | ||
| 513 | .root_source_file = options.root_source_file, | ||
| 514 | .target = options.target, | ||
| 515 | .optimize = options.optimize, | ||
| 516 | }); | ||
| 484 | } | 517 | } |
| 485 | 518 | ||
| 486 | pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep { | 519 | pub const AssemblyOptions = struct { |
| 487 | return addAssembleSource(self, name, .{ .path = src }); | 520 | name: []const u8, |
| 488 | } | 521 | source_file: FileSource, |
| 522 | target: CrossTarget, | ||
| 523 | optimize: std.builtin.Mode, | ||
| 524 | }; | ||
| 489 | 525 | ||
| 490 | pub fn addAssembleSource(self: *Builder, name: []const u8, src: FileSource) *LibExeObjStep { | 526 | pub fn addAssembly(b: *Builder, options: AssemblyOptions) *LibExeObjStep { |
| 491 | const obj_step = LibExeObjStep.createObject(self, name, null); | 527 | const obj_step = LibExeObjStep.create(b, .{ |
| 492 | obj_step.addAssemblyFileSource(src.dupe(self)); | 528 | .name = options.name, |
| 529 | .root_source_file = null, | ||
| 530 | .target = options.target, | ||
| 531 | .optimize = options.optimize, | ||
| 532 | }); | ||
| 533 | obj_step.addAssemblyFileSource(options.source_file.dupe(b)); | ||
| 493 | return obj_step; | 534 | return obj_step; |
| 494 | } | 535 | } |
| 495 | 536 | ||
| ... | @@ -593,17 +634,6 @@ pub const Builder = struct { | ... | @@ -593,17 +634,6 @@ pub const Builder = struct { |
| 593 | return TranslateCStep.create(self, source.dupe(self)); | 634 | return TranslateCStep.create(self, source.dupe(self)); |
| 594 | } | 635 | } |
| 595 | 636 | ||
| 596 | pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind { | ||
| 597 | _ = self; | ||
| 598 | return .{ | ||
| 599 | .versioned = .{ | ||
| 600 | .major = major, | ||
| 601 | .minor = minor, | ||
| 602 | .patch = patch, | ||
| 603 | }, | ||
| 604 | }; | ||
| 605 | } | ||
| 606 | |||
| 607 | pub fn make(self: *Builder, step_names: []const []const u8) !void { | 637 | pub fn make(self: *Builder, step_names: []const []const u8) !void { |
| 608 | try self.makePath(self.cache_root); | 638 | try self.makePath(self.cache_root); |
| 609 | 639 |
lib/std/build/LibExeObjStep.zig+22-59| ... | @@ -36,14 +36,14 @@ pub const base_id = .lib_exe_obj; | ... | @@ -36,14 +36,14 @@ pub const base_id = .lib_exe_obj; |
| 36 | step: Step, | 36 | step: Step, |
| 37 | builder: *Builder, | 37 | builder: *Builder, |
| 38 | name: []const u8, | 38 | name: []const u8, |
| 39 | target: CrossTarget = CrossTarget{}, | 39 | target: CrossTarget, |
| 40 | target_info: NativeTargetInfo, | 40 | target_info: NativeTargetInfo, |
| 41 | optimize: std.builtin.Mode, | ||
| 41 | linker_script: ?FileSource = null, | 42 | linker_script: ?FileSource = null, |
| 42 | version_script: ?[]const u8 = null, | 43 | version_script: ?[]const u8 = null, |
| 43 | out_filename: []const u8, | 44 | out_filename: []const u8, |
| 44 | linkage: ?Linkage = null, | 45 | linkage: ?Linkage = null, |
| 45 | version: ?std.builtin.Version, | 46 | version: ?std.builtin.Version, |
| 46 | build_mode: std.builtin.Mode, | ||
| 47 | kind: Kind, | 47 | kind: Kind, |
| 48 | major_only_filename: ?[]const u8, | 48 | major_only_filename: ?[]const u8, |
| 49 | name_only_filename: ?[]const u8, | 49 | name_only_filename: ?[]const u8, |
| ... | @@ -271,6 +271,16 @@ pub const IncludeDir = union(enum) { | ... | @@ -271,6 +271,16 @@ pub const IncludeDir = union(enum) { |
| 271 | config_header_step: *ConfigHeaderStep, | 271 | config_header_step: *ConfigHeaderStep, |
| 272 | }; | 272 | }; |
| 273 | 273 | ||
| 274 | pub const Options = struct { | ||
| 275 | name: []const u8, | ||
| 276 | root_source_file: ?FileSource = null, | ||
| 277 | target: CrossTarget, | ||
| 278 | optimize: std.builtin.Mode, | ||
| 279 | kind: Kind, | ||
| 280 | linkage: ?Linkage = null, | ||
| 281 | version: ?std.builtin.Version = null, | ||
| 282 | }; | ||
| 283 | |||
| 274 | pub const Kind = enum { | 284 | pub const Kind = enum { |
| 275 | exe, | 285 | exe, |
| 276 | lib, | 286 | lib, |
| ... | @@ -279,11 +289,6 @@ pub const Kind = enum { | ... | @@ -279,11 +289,6 @@ pub const Kind = enum { |
| 279 | test_exe, | 289 | test_exe, |
| 280 | }; | 290 | }; |
| 281 | 291 | ||
| 282 | pub const SharedLibKind = union(enum) { | ||
| 283 | versioned: std.builtin.Version, | ||
| 284 | unversioned: void, | ||
| 285 | }; | ||
| 286 | |||
| 287 | pub const Linkage = enum { dynamic, static }; | 292 | pub const Linkage = enum { dynamic, static }; |
| 288 | 293 | ||
| 289 | pub const EmitOption = union(enum) { | 294 | pub const EmitOption = union(enum) { |
| ... | @@ -302,43 +307,9 @@ pub const EmitOption = union(enum) { | ... | @@ -302,43 +307,9 @@ pub const EmitOption = union(enum) { |
| 302 | } | 307 | } |
| 303 | }; | 308 | }; |
| 304 | 309 | ||
| 305 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, kind: SharedLibKind) *LibExeObjStep { | 310 | pub fn create(builder: *Builder, options: Options) *LibExeObjStep { |
| 306 | return initExtraArgs(builder, name, root_src, .lib, .dynamic, switch (kind) { | 311 | const name = builder.dupe(options.name); |
| 307 | .versioned => |ver| ver, | 312 | const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(builder) else null; |
| 308 | .unversioned => null, | ||
| 309 | }); | ||
| 310 | } | ||
| 311 | |||
| 312 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | ||
| 313 | return initExtraArgs(builder, name, root_src, .lib, .static, null); | ||
| 314 | } | ||
| 315 | |||
| 316 | pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | ||
| 317 | return initExtraArgs(builder, name, root_src, .obj, null, null); | ||
| 318 | } | ||
| 319 | |||
| 320 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep { | ||
| 321 | return initExtraArgs(builder, name, root_src, .exe, null, null); | ||
| 322 | } | ||
| 323 | |||
| 324 | pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { | ||
| 325 | return initExtraArgs(builder, name, root_src, .@"test", null, null); | ||
| 326 | } | ||
| 327 | |||
| 328 | pub fn createTestExe(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep { | ||
| 329 | return initExtraArgs(builder, name, root_src, .test_exe, null, null); | ||
| 330 | } | ||
| 331 | |||
| 332 | fn initExtraArgs( | ||
| 333 | builder: *Builder, | ||
| 334 | name_raw: []const u8, | ||
| 335 | root_src_raw: ?FileSource, | ||
| 336 | kind: Kind, | ||
| 337 | linkage: ?Linkage, | ||
| 338 | ver: ?std.builtin.Version, | ||
| 339 | ) *LibExeObjStep { | ||
| 340 | const name = builder.dupe(name_raw); | ||
| 341 | const root_src: ?FileSource = if (root_src_raw) |rsrc| rsrc.dupe(builder) else null; | ||
| 342 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { | 313 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { |
| 343 | panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); | 314 | panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); |
| 344 | } | 315 | } |
| ... | @@ -350,14 +321,15 @@ fn initExtraArgs( | ... | @@ -350,14 +321,15 @@ fn initExtraArgs( |
| 350 | .builder = builder, | 321 | .builder = builder, |
| 351 | .verbose_link = false, | 322 | .verbose_link = false, |
| 352 | .verbose_cc = false, | 323 | .verbose_cc = false, |
| 353 | .build_mode = std.builtin.Mode.Debug, | 324 | .optimize = options.optimize, |
| 354 | .linkage = linkage, | 325 | .target = options.target, |
| 355 | .kind = kind, | 326 | .linkage = options.linkage, |
| 327 | .kind = options.kind, | ||
| 356 | .root_src = root_src, | 328 | .root_src = root_src, |
| 357 | .name = name, | 329 | .name = name, |
| 358 | .frameworks = StringHashMap(FrameworkLinkInfo).init(builder.allocator), | 330 | .frameworks = StringHashMap(FrameworkLinkInfo).init(builder.allocator), |
| 359 | .step = Step.init(base_id, name, builder.allocator, make), | 331 | .step = Step.init(base_id, name, builder.allocator, make), |
| 360 | .version = ver, | 332 | .version = options.version, |
| 361 | .out_filename = undefined, | 333 | .out_filename = undefined, |
| 362 | .out_h_filename = builder.fmt("{s}.h", .{name}), | 334 | .out_h_filename = builder.fmt("{s}.h", .{name}), |
| 363 | .out_lib_filename = undefined, | 335 | .out_lib_filename = undefined, |
| ... | @@ -457,11 +429,6 @@ fn computeOutFileNames(self: *LibExeObjStep) void { | ... | @@ -457,11 +429,6 @@ fn computeOutFileNames(self: *LibExeObjStep) void { |
| 457 | } | 429 | } |
| 458 | } | 430 | } |
| 459 | 431 | ||
| 460 | pub fn setTarget(self: *LibExeObjStep, target: CrossTarget) void { | ||
| 461 | self.target = target; | ||
| 462 | self.computeOutFileNames(); | ||
| 463 | } | ||
| 464 | |||
| 465 | pub fn setOutputDir(self: *LibExeObjStep, dir: []const u8) void { | 432 | pub fn setOutputDir(self: *LibExeObjStep, dir: []const u8) void { |
| 466 | self.output_dir = self.builder.dupePath(dir); | 433 | self.output_dir = self.builder.dupePath(dir); |
| 467 | } | 434 | } |
| ... | @@ -889,10 +856,6 @@ pub fn setVerboseCC(self: *LibExeObjStep, value: bool) void { | ... | @@ -889,10 +856,6 @@ pub fn setVerboseCC(self: *LibExeObjStep, value: bool) void { |
| 889 | self.verbose_cc = value; | 856 | self.verbose_cc = value; |
| 890 | } | 857 | } |
| 891 | 858 | ||
| 892 | pub fn setBuildMode(self: *LibExeObjStep, mode: std.builtin.Mode) void { | ||
| 893 | self.build_mode = mode; | ||
| 894 | } | ||
| 895 | |||
| 896 | pub fn overrideZigLibDir(self: *LibExeObjStep, dir_path: []const u8) void { | 859 | pub fn overrideZigLibDir(self: *LibExeObjStep, dir_path: []const u8) void { |
| 897 | self.override_lib_dir = self.builder.dupePath(dir_path); | 860 | self.override_lib_dir = self.builder.dupePath(dir_path); |
| 898 | } | 861 | } |
| ... | @@ -1376,9 +1339,9 @@ fn make(step: *Step) !void { | ... | @@ -1376,9 +1339,9 @@ fn make(step: *Step) !void { |
| 1376 | try zig_args.append(libc_file); | 1339 | try zig_args.append(libc_file); |
| 1377 | } | 1340 | } |
| 1378 | 1341 | ||
| 1379 | switch (self.build_mode) { | 1342 | switch (self.optimize) { |
| 1380 | .Debug => {}, // Skip since it's the default. | 1343 | .Debug => {}, // Skip since it's the default. |
| 1381 | else => zig_args.append(builder.fmt("-O{s}", .{@tagName(self.build_mode)})) catch unreachable, | 1344 | else => zig_args.append(builder.fmt("-O{s}", .{@tagName(self.optimize)})) catch unreachable, |
| 1382 | } | 1345 | } |
| 1383 | 1346 | ||
| 1384 | try zig_args.append("--cache-dir"); | 1347 | try zig_args.append("--cache-dir"); |