| ... | ... | @@ -3480,109 +3480,25 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3480 | 3480 | return test_step; |
| 3481 | 3481 | } |
| 3482 | 3482 | |
| 3483 | | const Options = struct { |
| 3484 | | target: CrossTarget = .{ .cpu_arch = .x86_64, .os_tag = .linux }, |
| 3485 | | optimize: std.builtin.OptimizeMode = .Debug, |
| 3486 | | use_llvm: bool = true, |
| 3487 | | use_lld: bool = false, |
| 3488 | | }; |
| 3489 | | |
| 3490 | 3483 | fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { |
| 3491 | | const target = opts.target.zigTriple(b.allocator) catch @panic("OOM"); |
| 3492 | | const optimize = @tagName(opts.optimize); |
| 3493 | | const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; |
| 3494 | | const name = std.fmt.allocPrint(b.allocator, "test-elf-" ++ prefix ++ "-{s}-{s}-{s}", .{ |
| 3495 | | target, |
| 3496 | | optimize, |
| 3497 | | use_llvm, |
| 3498 | | }) catch @panic("OOM"); |
| 3499 | | return b.step(name, ""); |
| 3500 | | } |
| 3501 | | |
| 3502 | | fn addExecutable(b: *Build, name: []const u8, opts: Options) *Compile { |
| 3503 | | return b.addExecutable(.{ |
| 3504 | | .name = name, |
| 3505 | | .target = opts.target, |
| 3506 | | .optimize = opts.optimize, |
| 3507 | | .use_llvm = opts.use_llvm, |
| 3508 | | .use_lld = opts.use_lld, |
| 3509 | | }); |
| 3510 | | } |
| 3511 | | |
| 3512 | | fn addObject(b: *Build, name: []const u8, opts: Options) *Compile { |
| 3513 | | return b.addObject(.{ |
| 3514 | | .name = name, |
| 3515 | | .target = opts.target, |
| 3516 | | .optimize = opts.optimize, |
| 3517 | | .use_llvm = opts.use_llvm, |
| 3518 | | .use_lld = opts.use_lld, |
| 3519 | | }); |
| 3520 | | } |
| 3521 | | |
| 3522 | | fn addStaticLibrary(b: *Build, name: []const u8, opts: Options) *Compile { |
| 3523 | | return b.addStaticLibrary(.{ |
| 3524 | | .name = name, |
| 3525 | | .target = opts.target, |
| 3526 | | .optimize = opts.optimize, |
| 3527 | | .use_llvm = opts.use_llvm, |
| 3528 | | .use_lld = opts.use_lld, |
| 3529 | | }); |
| 3530 | | } |
| 3531 | | |
| 3532 | | fn addSharedLibrary(b: *Build, name: []const u8, opts: Options) *Compile { |
| 3533 | | return b.addSharedLibrary(.{ |
| 3534 | | .name = name, |
| 3535 | | .target = opts.target, |
| 3536 | | .optimize = opts.optimize, |
| 3537 | | .use_llvm = opts.use_llvm, |
| 3538 | | .use_lld = opts.use_lld, |
| 3539 | | }); |
| 3540 | | } |
| 3541 | | |
| 3542 | | fn addRunArtifact(comp: *Compile) *Run { |
| 3543 | | const b = comp.step.owner; |
| 3544 | | const run = b.addRunArtifact(comp); |
| 3545 | | run.skip_foreign_checks = true; |
| 3546 | | return run; |
| 3547 | | } |
| 3548 | | |
| 3549 | | fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { |
| 3550 | | const b = comp.step.owner; |
| 3551 | | const file = WriteFile.create(b).add("a.zig", bytes); |
| 3552 | | file.addStepDependencies(&comp.step); |
| 3553 | | comp.root_src = file; |
| 3554 | | } |
| 3555 | | |
| 3556 | | fn addCSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void { |
| 3557 | | const b = comp.step.owner; |
| 3558 | | const file = WriteFile.create(b).add("a.c", bytes); |
| 3559 | | comp.addCSourceFile(.{ .file = file, .flags = flags }); |
| 3560 | | } |
| 3561 | | |
| 3562 | | fn addCppSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void { |
| 3563 | | const b = comp.step.owner; |
| 3564 | | const file = WriteFile.create(b).add("a.cpp", bytes); |
| 3565 | | comp.addCSourceFile(.{ .file = file, .flags = flags }); |
| 3566 | | } |
| 3567 | | |
| 3568 | | fn addAsmSourceBytes(comp: *Compile, bytes: []const u8) void { |
| 3569 | | const b = comp.step.owner; |
| 3570 | | const actual_bytes = std.fmt.allocPrint(b.allocator, "{s}\n", .{bytes}) catch @panic("OOM"); |
| 3571 | | const file = WriteFile.create(b).add("a.s", actual_bytes); |
| 3572 | | comp.addAssemblyFile(file); |
| 3573 | | } |
| 3574 | | |
| 3575 | | fn expectLinkErrors(comp: *Compile, test_step: *Step, expected_errors: Compile.ExpectedCompileErrors) void { |
| 3576 | | comp.expect_errors = expected_errors; |
| 3577 | | const bin_file = comp.getEmittedBin(); |
| 3578 | | bin_file.addStepDependencies(test_step); |
| 3579 | | } |
| 3580 | | |
| 3484 | return link.addTestStep(b, "elf-" ++ prefix, opts); |
| 3485 | } |
| 3486 | |
| 3487 | const addAsmSourceBytes = link.addAsmSourceBytes; |
| 3488 | const addCSourceBytes = link.addCSourceBytes; |
| 3489 | const addCppSourceBytes = link.addCppSourceBytes; |
| 3490 | const addExecutable = link.addExecutable; |
| 3491 | const addObject = link.addObject; |
| 3492 | const addRunArtifact = link.addRunArtifact; |
| 3493 | const addSharedLibrary = link.addSharedLibrary; |
| 3494 | const addStaticLibrary = link.addStaticLibrary; |
| 3495 | const addZigSourceBytes = link.addZigSourceBytes; |
| 3496 | const expectLinkErrors = link.expectLinkErrors; |
| 3497 | const link = @import("link.zig"); |
| 3581 | 3498 | const std = @import("std"); |
| 3582 | 3499 | |
| 3583 | 3500 | const Build = std.Build; |
| 3584 | | const Compile = Step.Compile; |
| 3585 | 3501 | const CrossTarget = std.zig.CrossTarget; |
| 3586 | | const Run = Step.Run; |
| 3502 | const Options = link.Options; |
| 3587 | 3503 | const Step = Build.Step; |
| 3588 | 3504 | const WriteFile = Step.WriteFile; |