| author | |
| committer | |
| log | d93a0763d4c732fcdb3ed891d5b44a10943ccfed |
| tree | 47dfd634d9ed9e4f3dc777ca39221fed11da3850 |
| parent | 041f7d69f0656254cfa62a59af2fa65ac1b1c433 |
7 files changed, 76 insertions(+), 63 deletions(-)
test/link.zig-4| ... | @@ -135,10 +135,6 @@ pub const cases = [_]Case{ | ... | @@ -135,10 +135,6 @@ pub const cases = [_]Case{ |
| 135 | .build_root = "test/link/macho/linksection", | 135 | .build_root = "test/link/macho/linksection", |
| 136 | .import = @import("link/macho/linksection/build.zig"), | 136 | .import = @import("link/macho/linksection/build.zig"), |
| 137 | }, | 137 | }, |
| 138 | .{ | ||
| 139 | .build_root = "test/link/macho/needed_framework", | ||
| 140 | .import = @import("link/macho/needed_framework/build.zig"), | ||
| 141 | }, | ||
| 142 | .{ | 138 | .{ |
| 143 | .build_root = "test/link/macho/needed_library", | 139 | .build_root = "test/link/macho/needed_library", |
| 144 | .import = @import("link/macho/needed_library/build.zig"), | 140 | .import = @import("link/macho/needed_library/build.zig"), |
test/link/elf.zig+3-1| ... | @@ -2,7 +2,8 @@ | ... | @@ -2,7 +2,8 @@ |
| 2 | //! Currently, we support linking x86_64 Linux, but in the future we | 2 | //! Currently, we support linking x86_64 Linux, but in the future we |
| 3 | //! will progressively relax those to exercise more combinations. | 3 | //! will progressively relax those to exercise more combinations. |
| 4 | 4 | ||
| 5 | pub fn testAll(b: *Build) *Step { | 5 | pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 6 | _ = build_opts; | ||
| 6 | const elf_step = b.step("test-elf", "Run ELF tests"); | 7 | const elf_step = b.step("test-elf", "Run ELF tests"); |
| 7 | 8 | ||
| 8 | const default_target = b.resolveTargetQuery(.{ | 9 | const default_target = b.resolveTargetQuery(.{ |
| ... | @@ -3901,6 +3902,7 @@ const link = @import("link.zig"); | ... | @@ -3901,6 +3902,7 @@ const link = @import("link.zig"); |
| 3901 | const std = @import("std"); | 3902 | const std = @import("std"); |
| 3902 | 3903 | ||
| 3903 | const Build = std.Build; | 3904 | const Build = std.Build; |
| 3905 | const BuildOptions = link.BuildOptions; | ||
| 3904 | const Options = link.Options; | 3906 | const Options = link.Options; |
| 3905 | const Step = Build.Step; | 3907 | const Step = Build.Step; |
| 3906 | const WriteFile = Step.WriteFile; | 3908 | const WriteFile = Step.WriteFile; |
test/link/link.zig+18-2| ... | @@ -2,10 +2,26 @@ pub fn build(b: *Build) void { | ... | @@ -2,10 +2,26 @@ pub fn build(b: *Build) void { |
| 2 | const test_step = b.step("test-link", "Run link tests"); | 2 | const test_step = b.step("test-link", "Run link tests"); |
| 3 | b.default_step = test_step; | 3 | b.default_step = test_step; |
| 4 | 4 | ||
| 5 | test_step.dependOn(@import("elf.zig").testAll(b)); | 5 | const has_macos_sdk = b.option(bool, "has_macos_sdk", "whether the host provides a macOS SDK in system path"); |
| 6 | test_step.dependOn(@import("macho.zig").testAll(b)); | 6 | const has_ios_sdk = b.option(bool, "has_ios_sdk", "whether the host provides a iOS SDK in system path"); |
| 7 | const has_symlinks_windows = b.option(bool, "has_symlinks_windows", "whether the host is windows and has symlinks enabled"); | ||
| 8 | |||
| 9 | const build_opts: BuildOptions = .{ | ||
| 10 | .has_macos_sdk = has_macos_sdk orelse false, | ||
| 11 | .has_ios_sdk = has_ios_sdk orelse false, | ||
| 12 | .has_symlinks_windows = has_symlinks_windows orelse false, | ||
| 13 | }; | ||
| 14 | |||
| 15 | test_step.dependOn(@import("elf.zig").testAll(b, build_opts)); | ||
| 16 | test_step.dependOn(@import("macho.zig").testAll(b, build_opts)); | ||
| 7 | } | 17 | } |
| 8 | 18 | ||
| 19 | pub const BuildOptions = struct { | ||
| 20 | has_macos_sdk: bool, | ||
| 21 | has_ios_sdk: bool, | ||
| 22 | has_symlinks_windows: bool, | ||
| 23 | }; | ||
| 24 | |||
| 9 | pub const Options = struct { | 25 | pub const Options = struct { |
| 10 | target: std.Build.ResolvedTarget, | 26 | target: std.Build.ResolvedTarget, |
| 11 | optimize: std.builtin.OptimizeMode = .Debug, | 27 | optimize: std.builtin.OptimizeMode = .Debug, |
test/link/macho.zig+27-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | //! Here we test our MachO linker for correctness and functionality. | 1 | //! Here we test our MachO linker for correctness and functionality. |
| 2 | //! TODO migrate standalone tests from test/link/macho/* to here. | 2 | //! TODO migrate standalone tests from test/link/macho/* to here. |
| 3 | 3 | ||
| 4 | pub fn testAll(b: *std.Build) *Step { | 4 | pub fn testAll(b: *std.Build, build_opts: BuildOptions) *Step { |
| 5 | const macho_step = b.step("test-macho", "Run MachO tests"); | 5 | const macho_step = b.step("test-macho", "Run MachO tests"); |
| 6 | 6 | ||
| 7 | const default_target = b.resolveTargetQuery(.{ | 7 | const default_target = b.resolveTargetQuery(.{ |
| ... | @@ -13,6 +13,11 @@ pub fn testAll(b: *std.Build) *Step { | ... | @@ -13,6 +13,11 @@ pub fn testAll(b: *std.Build) *Step { |
| 13 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); | 13 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); |
| 14 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); | 14 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); |
| 15 | 15 | ||
| 16 | // Tests requiring presence of macOS SDK in system path | ||
| 17 | if (build_opts.has_macos_sdk and build_opts.has_symlinks_windows) { | ||
| 18 | macho_step.dependOn(testNeededFramework(b, .{ .target = b.host })); | ||
| 19 | } | ||
| 20 | |||
| 16 | return macho_step; | 21 | return macho_step; |
| 17 | } | 22 | } |
| 18 | 23 | ||
| ... | @@ -151,6 +156,26 @@ fn testEntryPointDylib(b: *std.Build, opts: Options) *Step { | ... | @@ -151,6 +156,26 @@ fn testEntryPointDylib(b: *std.Build, opts: Options) *Step { |
| 151 | return test_step; | 156 | return test_step; |
| 152 | } | 157 | } |
| 153 | 158 | ||
| 159 | fn testNeededFramework(b: *std.Build, opts: Options) *Step { | ||
| 160 | const test_step = addTestStep(b, "macho-needed-framework", opts); | ||
| 161 | |||
| 162 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" }); | ||
| 163 | exe.linkFrameworkNeeded("Cocoa"); | ||
| 164 | exe.dead_strip_dylibs = true; | ||
| 165 | |||
| 166 | const check = exe.checkObject(); | ||
| 167 | check.checkInHeaders(); | ||
| 168 | check.checkExact("cmd LOAD_DYLIB"); | ||
| 169 | check.checkContains("Cocoa"); | ||
| 170 | test_step.dependOn(&check.step); | ||
| 171 | |||
| 172 | const run = addRunArtifact(exe); | ||
| 173 | run.expectExitCode(0); | ||
| 174 | test_step.dependOn(&run.step); | ||
| 175 | |||
| 176 | return test_step; | ||
| 177 | } | ||
| 178 | |||
| 154 | fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step { | 179 | fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step { |
| 155 | const test_step = addTestStep(b, "macho-section-boundary-symbols", opts); | 180 | const test_step = addTestStep(b, "macho-section-boundary-symbols", opts); |
| 156 | 181 | ||
| ... | @@ -311,5 +336,6 @@ const addSharedLibrary = link.addSharedLibrary; | ... | @@ -311,5 +336,6 @@ const addSharedLibrary = link.addSharedLibrary; |
| 311 | const expectLinkErrors = link.expectLinkErrors; | 336 | const expectLinkErrors = link.expectLinkErrors; |
| 312 | const link = @import("link.zig"); | 337 | const link = @import("link.zig"); |
| 313 | const std = @import("std"); | 338 | const std = @import("std"); |
| 339 | const BuildOptions = link.BuildOptions; | ||
| 314 | const Options = link.Options; | 340 | const Options = link.Options; |
| 315 | const Step = std.Build.Step; | 341 | const Step = std.Build.Step; |
test/link/macho/needed_framework/build.zig deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub const requires_symlinks = true; | ||
| 4 | pub const requires_macos_sdk = true; | ||
| 5 | |||
| 6 | pub fn build(b: *std.Build) void { | ||
| 7 | const test_step = b.step("test", "Test it"); | ||
| 8 | b.default_step = test_step; | ||
| 9 | |||
| 10 | add(b, test_step, .Debug); | ||
| 11 | add(b, test_step, .ReleaseFast); | ||
| 12 | add(b, test_step, .ReleaseSmall); | ||
| 13 | add(b, test_step, .ReleaseSafe); | ||
| 14 | } | ||
| 15 | |||
| 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | ||
| 17 | // -dead_strip_dylibs | ||
| 18 | // -needed_framework Cocoa | ||
| 19 | const exe = b.addExecutable(.{ | ||
| 20 | .name = "test", | ||
| 21 | .optimize = optimize, | ||
| 22 | .target = b.host, | ||
| 23 | }); | ||
| 24 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | ||
| 25 | exe.linkLibC(); | ||
| 26 | exe.linkFrameworkNeeded("Cocoa"); | ||
| 27 | exe.dead_strip_dylibs = true; | ||
| 28 | |||
| 29 | const check = exe.checkObject(); | ||
| 30 | check.checkInHeaders(); | ||
| 31 | check.checkExact("cmd LOAD_DYLIB"); | ||
| 32 | check.checkContains("Cocoa"); | ||
| 33 | test_step.dependOn(&check.step); | ||
| 34 | |||
| 35 | const run_cmd = b.addRunArtifact(exe); | ||
| 36 | test_step.dependOn(&run_cmd.step); | ||
| 37 | } | ||
test/link/macho/needed_framework/main.c deleted-3| ... | @@ -1,3 +0,0 @@ | ||
| 1 | int main(int argc, char* argv[]) { | ||
| 2 | return 0; | ||
| 3 | } | ||
test/tests.zig+28-15| ... | @@ -750,26 +750,39 @@ pub fn addLinkTests( | ... | @@ -750,26 +750,39 @@ pub fn addLinkTests( |
| 750 | const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows; | 750 | const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows; |
| 751 | 751 | ||
| 752 | inline for (link.cases) |case| { | 752 | inline for (link.cases) |case| { |
| 753 | const requires_stage2 = @hasDecl(case.import, "requires_stage2") and | 753 | if (mem.eql(u8, @typeName(case.import), "test.link.link")) { |
| 754 | case.import.requires_stage2; | 754 | const dep = b.anonymousDependency(case.build_root, case.import, .{ |
| 755 | const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and | 755 | .has_macos_sdk = enable_macos_sdk, |
| 756 | case.import.requires_symlinks; | 756 | .has_ios_sdk = enable_ios_sdk, |
| 757 | const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and | 757 | .has_symlinks_windows = !omit_symlinks, |
| 758 | case.import.requires_macos_sdk; | 758 | }); |
| 759 | const requires_ios_sdk = @hasDecl(case.import, "requires_ios_sdk") and | ||
| 760 | case.import.requires_ios_sdk; | ||
| 761 | const bad = | ||
| 762 | (requires_stage2 and omit_stage2) or | ||
| 763 | (requires_symlinks and omit_symlinks) or | ||
| 764 | (requires_macos_sdk and !enable_macos_sdk) or | ||
| 765 | (requires_ios_sdk and !enable_ios_sdk); | ||
| 766 | if (!bad) { | ||
| 767 | const dep = b.anonymousDependency(case.build_root, case.import, .{}); | ||
| 768 | const dep_step = dep.builder.default_step; | 759 | const dep_step = dep.builder.default_step; |
| 769 | assert(mem.startsWith(u8, dep.builder.dep_prefix, "test.")); | 760 | assert(mem.startsWith(u8, dep.builder.dep_prefix, "test.")); |
| 770 | const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..]; | 761 | const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..]; |
| 771 | dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name }); | 762 | dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name }); |
| 772 | step.dependOn(dep_step); | 763 | step.dependOn(dep_step); |
| 764 | } else { | ||
| 765 | const requires_stage2 = @hasDecl(case.import, "requires_stage2") and | ||
| 766 | case.import.requires_stage2; | ||
| 767 | const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and | ||
| 768 | case.import.requires_symlinks; | ||
| 769 | const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and | ||
| 770 | case.import.requires_macos_sdk; | ||
| 771 | const requires_ios_sdk = @hasDecl(case.import, "requires_ios_sdk") and | ||
| 772 | case.import.requires_ios_sdk; | ||
| 773 | const bad = | ||
| 774 | (requires_stage2 and omit_stage2) or | ||
| 775 | (requires_symlinks and omit_symlinks) or | ||
| 776 | (requires_macos_sdk and !enable_macos_sdk) or | ||
| 777 | (requires_ios_sdk and !enable_ios_sdk); | ||
| 778 | if (!bad) { | ||
| 779 | const dep = b.anonymousDependency(case.build_root, case.import, .{}); | ||
| 780 | const dep_step = dep.builder.default_step; | ||
| 781 | assert(mem.startsWith(u8, dep.builder.dep_prefix, "test.")); | ||
| 782 | const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..]; | ||
| 783 | dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name }); | ||
| 784 | step.dependOn(dep_step); | ||
| 785 | } | ||
| 773 | } | 786 | } |
| 774 | } | 787 | } |
| 775 | 788 |