| author | |
| committer | |
| log | 7c13bdb1c9c7f61def9b58b1f24072a4eddc54c1 |
| tree | cf48ca1d4072ed9b6454d935fac42e4fd05abcbf |
| parent | 546c75ca46eff73e5f038e2b894ff96c65cd8960 |
| parent | 72c0cebe5c5e6954ae9992d36f8164ae9433df9e |
| signature |
Implement EmulatableRunStep for linker tests15 files changed, 413 insertions(+), 125 deletions(-)
ci/zinc/linux_test.sh+1| ... | @@ -67,6 +67,7 @@ $STAGE1_ZIG build test-cli -fqemu -fwasmtime | ... | @@ -67,6 +67,7 @@ $STAGE1_ZIG build test-cli -fqemu -fwasmtime |
| 67 | $STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime | 67 | $STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime |
| 68 | $STAGE1_ZIG build docs -fqemu -fwasmtime | 68 | $STAGE1_ZIG build docs -fqemu -fwasmtime |
| 69 | $STAGE1_ZIG build test-cases -fqemu -fwasmtime | 69 | $STAGE1_ZIG build test-cases -fqemu -fwasmtime |
| 70 | $STAGE1_ZIG build test-link -fqemu -fwasmtime | ||
| 70 | 71 | ||
| 71 | # Produce the experimental std lib documentation. | 72 | # Produce the experimental std lib documentation. |
| 72 | mkdir -p "$RELEASE_STAGING/docs/std" | 73 | mkdir -p "$RELEASE_STAGING/docs/std" |
lib/std/build.zig+17| ... | @@ -26,6 +26,7 @@ pub const CheckFileStep = @import("build/CheckFileStep.zig"); | ... | @@ -26,6 +26,7 @@ pub const CheckFileStep = @import("build/CheckFileStep.zig"); |
| 26 | pub const CheckObjectStep = @import("build/CheckObjectStep.zig"); | 26 | pub const CheckObjectStep = @import("build/CheckObjectStep.zig"); |
| 27 | pub const InstallRawStep = @import("build/InstallRawStep.zig"); | 27 | pub const InstallRawStep = @import("build/InstallRawStep.zig"); |
| 28 | pub const OptionsStep = @import("build/OptionsStep.zig"); | 28 | pub const OptionsStep = @import("build/OptionsStep.zig"); |
| 29 | pub const EmulatableRunStep = @import("build/EmulatableRunStep.zig"); | ||
| 29 | 30 | ||
| 30 | pub const Builder = struct { | 31 | pub const Builder = struct { |
| 31 | install_tls: TopLevelStep, | 32 | install_tls: TopLevelStep, |
| ... | @@ -1890,6 +1891,21 @@ pub const LibExeObjStep = struct { | ... | @@ -1890,6 +1891,21 @@ pub const LibExeObjStep = struct { |
| 1890 | return run_step; | 1891 | return run_step; |
| 1891 | } | 1892 | } |
| 1892 | 1893 | ||
| 1894 | /// Creates an `EmulatableRunStep` with an executable built with `addExecutable`. | ||
| 1895 | /// Allows running foreign binaries through emulation platforms such as Qemu or Rosetta. | ||
| 1896 | /// When a binary cannot be ran through emulation or the option is disabled, a warning | ||
| 1897 | /// will be printed and the binary will *NOT* be ran. | ||
| 1898 | pub fn runEmulatable(exe: *LibExeObjStep) *EmulatableRunStep { | ||
| 1899 | assert(exe.kind == .exe or exe.kind == .text_exe); | ||
| 1900 | |||
| 1901 | const run_step = EmulatableRunStep.create(exe.builder.fmt("run {s}", .{exe.step.name}), exe); | ||
| 1902 | if (exe.vcpkg_bin_path) |path| { | ||
| 1903 | run_step.addPathDir(path); | ||
| 1904 | } | ||
| 1905 | |||
| 1906 | return run_step; | ||
| 1907 | } | ||
| 1908 | |||
| 1893 | pub fn checkObject(self: *LibExeObjStep, obj_format: std.Target.ObjectFormat) *CheckObjectStep { | 1909 | pub fn checkObject(self: *LibExeObjStep, obj_format: std.Target.ObjectFormat) *CheckObjectStep { |
| 1894 | return CheckObjectStep.create(self.builder, self.getOutputSource(), obj_format); | 1910 | return CheckObjectStep.create(self.builder, self.getOutputSource(), obj_format); |
| 1895 | } | 1911 | } |
| ... | @@ -3604,6 +3620,7 @@ pub const Step = struct { | ... | @@ -3604,6 +3620,7 @@ pub const Step = struct { |
| 3604 | translate_c, | 3620 | translate_c, |
| 3605 | write_file, | 3621 | write_file, |
| 3606 | run, | 3622 | run, |
| 3623 | emulatable_run, | ||
| 3607 | check_file, | 3624 | check_file, |
| 3608 | check_object, | 3625 | check_object, |
| 3609 | install_raw, | 3626 | install_raw, |
lib/std/build/CheckObjectStep.zig+11| ... | @@ -12,6 +12,7 @@ const CheckObjectStep = @This(); | ... | @@ -12,6 +12,7 @@ const CheckObjectStep = @This(); |
| 12 | const Allocator = mem.Allocator; | 12 | const Allocator = mem.Allocator; |
| 13 | const Builder = build.Builder; | 13 | const Builder = build.Builder; |
| 14 | const Step = build.Step; | 14 | const Step = build.Step; |
| 15 | const EmulatableRunStep = build.EmulatableRunStep; | ||
| 15 | 16 | ||
| 16 | pub const base_id = .check_obj; | 17 | pub const base_id = .check_obj; |
| 17 | 18 | ||
| ... | @@ -37,6 +38,16 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe | ... | @@ -37,6 +38,16 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe |
| 37 | return self; | 38 | return self; |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 41 | /// Runs and (optionally) compares the output of a binary. | ||
| 42 | /// Asserts `self` was generated from an executable step. | ||
| 43 | pub fn runAndCompare(self: *CheckObjectStep) *EmulatableRunStep { | ||
| 44 | const dependencies_len = self.step.dependencies.items.len; | ||
| 45 | assert(dependencies_len > 0); | ||
| 46 | const exe_step = self.step.dependencies.items[dependencies_len - 1]; | ||
| 47 | const exe = exe_step.cast(std.build.LibExeObjStep).?; | ||
| 48 | return EmulatableRunStep.create(self.builder, "EmulatableRun", exe); | ||
| 49 | } | ||
| 50 | |||
| 40 | /// There two types of actions currently suported: | 51 | /// There two types of actions currently suported: |
| 41 | /// * `.match` - is the main building block of standard matchers with optional eat-all token `{*}` | 52 | /// * `.match` - is the main building block of standard matchers with optional eat-all token `{*}` |
| 42 | /// and extractors by name such as `{n_value}`. Please note this action is very simplistic in nature | 53 | /// and extractors by name such as `{n_value}`. Please note this action is very simplistic in nature |
lib/std/build/EmulatableRunStep.zig created+215| ... | @@ -0,0 +1,215 @@ | ||
| 1 | //! Unlike `RunStep` this step will provide emulation, when enabled, to run foreign binaries. | ||
| 2 | //! When a binary is foreign, but emulation for the target is disabled, the specified binary | ||
| 3 | //! will not be run and therefore also not validated against its output. | ||
| 4 | //! This step can be useful when wishing to run a built binary on multiple platforms, | ||
| 5 | //! without having to verify if it's possible to be ran against. | ||
| 6 | |||
| 7 | const std = @import("../std.zig"); | ||
| 8 | const build = std.build; | ||
| 9 | const Step = std.build.Step; | ||
| 10 | const Builder = std.build.Builder; | ||
| 11 | const LibExeObjStep = std.build.LibExeObjStep; | ||
| 12 | const RunStep = std.build.RunStep; | ||
| 13 | |||
| 14 | const fs = std.fs; | ||
| 15 | const process = std.process; | ||
| 16 | const EnvMap = process.EnvMap; | ||
| 17 | |||
| 18 | const EmulatableRunStep = @This(); | ||
| 19 | |||
| 20 | pub const base_id = .emulatable_run; | ||
| 21 | |||
| 22 | const max_stdout_size = 1 * 1024 * 1024; // 1 MiB | ||
| 23 | |||
| 24 | step: Step, | ||
| 25 | builder: *Builder, | ||
| 26 | |||
| 27 | /// The artifact (executable) to be run by this step | ||
| 28 | exe: *LibExeObjStep, | ||
| 29 | |||
| 30 | /// Set this to `null` to ignore the exit code for the purpose of determining a successful execution | ||
| 31 | expected_exit_code: ?u8 = 0, | ||
| 32 | |||
| 33 | /// Override this field to modify the environment | ||
| 34 | env_map: ?*EnvMap, | ||
| 35 | |||
| 36 | /// Set this to modify the current working directory | ||
| 37 | cwd: ?[]const u8, | ||
| 38 | |||
| 39 | stdout_action: RunStep.StdIoAction = .inherit, | ||
| 40 | stderr_action: RunStep.StdIoAction = .inherit, | ||
| 41 | |||
| 42 | /// When set to true, hides the warning of skipping a foreign binary which cannot be run on the host | ||
| 43 | /// or through emulation. | ||
| 44 | hide_foreign_binaries_warning: bool, | ||
| 45 | |||
| 46 | /// Creates a step that will execute the given artifact. This step will allow running the | ||
| 47 | /// binary through emulation when any of the emulation options such as `enable_rosetta` are set to true. | ||
| 48 | /// When set to false, and the binary is foreign, running the executable is skipped. | ||
| 49 | /// Asserts given artifact is an executable. | ||
| 50 | pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *EmulatableRunStep { | ||
| 51 | std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe); | ||
| 52 | const self = builder.allocator.create(EmulatableRunStep) catch unreachable; | ||
| 53 | |||
| 54 | const option_name = "hide-foreign-warnings"; | ||
| 55 | const hide_warnings = if (builder.available_options_map.get(option_name) == null) warn: { | ||
| 56 | break :warn builder.option(bool, option_name, "Hide the warning when a foreign binary which is incompatible is skipped") orelse false; | ||
| 57 | } else false; | ||
| 58 | |||
| 59 | self.* = .{ | ||
| 60 | .builder = builder, | ||
| 61 | .step = Step.init(.emulatable_run, name, builder.allocator, make), | ||
| 62 | .exe = artifact, | ||
| 63 | .env_map = null, | ||
| 64 | .cwd = null, | ||
| 65 | .hide_foreign_binaries_warning = hide_warnings, | ||
| 66 | }; | ||
| 67 | self.step.dependOn(&artifact.step); | ||
| 68 | |||
| 69 | return self; | ||
| 70 | } | ||
| 71 | |||
| 72 | fn make(step: *Step) !void { | ||
| 73 | const self = @fieldParentPtr(EmulatableRunStep, "step", step); | ||
| 74 | const host_info = self.builder.host; | ||
| 75 | |||
| 76 | var argv_list = std.ArrayList([]const u8).init(self.builder.allocator); | ||
| 77 | defer argv_list.deinit(); | ||
| 78 | |||
| 79 | const need_cross_glibc = self.exe.target.isGnuLibC() and self.exe.is_linking_libc; | ||
| 80 | switch (host_info.getExternalExecutor(self.exe.target_info, .{ | ||
| 81 | .qemu_fixes_dl = need_cross_glibc and self.builder.glibc_runtimes_dir != null, | ||
| 82 | .link_libc = self.exe.is_linking_libc, | ||
| 83 | })) { | ||
| 84 | .native => {}, | ||
| 85 | .rosetta => if (!self.builder.enable_rosetta) return warnAboutForeignBinaries(self), | ||
| 86 | .wine => |bin_name| if (self.builder.enable_wine) { | ||
| 87 | try argv_list.append(bin_name); | ||
| 88 | } else return, | ||
| 89 | .qemu => |bin_name| if (self.builder.enable_qemu) { | ||
| 90 | const glibc_dir_arg = if (need_cross_glibc) | ||
| 91 | self.builder.glibc_runtimes_dir orelse return | ||
| 92 | else | ||
| 93 | null; | ||
| 94 | try argv_list.append(bin_name); | ||
| 95 | if (glibc_dir_arg) |dir| { | ||
| 96 | // TODO look into making this a call to `linuxTriple`. This | ||
| 97 | // needs the directory to be called "i686" rather than | ||
| 98 | // "i386" which is why we do it manually here. | ||
| 99 | const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; | ||
| 100 | const cpu_arch = self.exe.target.getCpuArch(); | ||
| 101 | const os_tag = self.exe.target.getOsTag(); | ||
| 102 | const abi = self.exe.target.getAbi(); | ||
| 103 | const cpu_arch_name: []const u8 = if (cpu_arch == .i386) | ||
| 104 | "i686" | ||
| 105 | else | ||
| 106 | @tagName(cpu_arch); | ||
| 107 | const full_dir = try std.fmt.allocPrint(self.builder.allocator, fmt_str, .{ | ||
| 108 | dir, cpu_arch_name, @tagName(os_tag), @tagName(abi), | ||
| 109 | }); | ||
| 110 | |||
| 111 | try argv_list.append("-L"); | ||
| 112 | try argv_list.append(full_dir); | ||
| 113 | } | ||
| 114 | } else return warnAboutForeignBinaries(self), | ||
| 115 | .darling => |bin_name| if (self.builder.enable_darling) { | ||
| 116 | try argv_list.append(bin_name); | ||
| 117 | } else return warnAboutForeignBinaries(self), | ||
| 118 | .wasmtime => |bin_name| if (self.builder.enable_wasmtime) { | ||
| 119 | try argv_list.append(bin_name); | ||
| 120 | try argv_list.append("--dir=."); | ||
| 121 | } else return warnAboutForeignBinaries(self), | ||
| 122 | else => return warnAboutForeignBinaries(self), | ||
| 123 | } | ||
| 124 | |||
| 125 | if (self.exe.target.isWindows()) { | ||
| 126 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | ||
| 127 | RunStep.addPathForDynLibsInternal(&self.step, self.builder, self.exe); | ||
| 128 | } | ||
| 129 | |||
| 130 | const executable_path = self.exe.installed_path orelse self.exe.getOutputSource().getPath(self.builder); | ||
| 131 | try argv_list.append(executable_path); | ||
| 132 | |||
| 133 | try RunStep.runCommand( | ||
| 134 | argv_list.items, | ||
| 135 | self.builder, | ||
| 136 | self.expected_exit_code, | ||
| 137 | self.stdout_action, | ||
| 138 | self.stderr_action, | ||
| 139 | .Inherit, | ||
| 140 | self.env_map, | ||
| 141 | self.cwd, | ||
| 142 | false, | ||
| 143 | ); | ||
| 144 | } | ||
| 145 | |||
| 146 | pub fn expectStdErrEqual(self: *EmulatableRunStep, bytes: []const u8) void { | ||
| 147 | self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) }; | ||
| 148 | } | ||
| 149 | |||
| 150 | pub fn expectStdOutEqual(self: *EmulatableRunStep, bytes: []const u8) void { | ||
| 151 | self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) }; | ||
| 152 | } | ||
| 153 | |||
| 154 | fn warnAboutForeignBinaries(step: *EmulatableRunStep) void { | ||
| 155 | if (step.hide_foreign_binaries_warning) return; | ||
| 156 | const builder = step.builder; | ||
| 157 | const artifact = step.exe; | ||
| 158 | |||
| 159 | const host_name = builder.host.target.zigTriple(builder.allocator) catch unreachable; | ||
| 160 | const foreign_name = artifact.target.zigTriple(builder.allocator) catch unreachable; | ||
| 161 | const target_info = std.zig.system.NativeTargetInfo.detect(builder.allocator, artifact.target) catch unreachable; | ||
| 162 | const need_cross_glibc = artifact.target.isGnuLibC() and artifact.is_linking_libc; | ||
| 163 | switch (builder.host.getExternalExecutor(target_info, .{ | ||
| 164 | .qemu_fixes_dl = need_cross_glibc and builder.glibc_runtimes_dir != null, | ||
| 165 | .link_libc = artifact.is_linking_libc, | ||
| 166 | })) { | ||
| 167 | .native => unreachable, | ||
| 168 | .bad_dl => |foreign_dl| { | ||
| 169 | const host_dl = builder.host.dynamic_linker.get() orelse "(none)"; | ||
| 170 | std.debug.print("the host system does not appear to be capable of executing binaries from the target because the host dynamic linker is '{s}', while the target dynamic linker is '{s}'. Consider setting the dynamic linker as '{s}'.\n", .{ | ||
| 171 | host_dl, foreign_dl, host_dl, | ||
| 172 | }); | ||
| 173 | }, | ||
| 174 | .bad_os_or_cpu => { | ||
| 175 | std.debug.print("the host system ({s}) does not appear to be capable of executing binaries from the target ({s}).\n", .{ | ||
| 176 | host_name, foreign_name, | ||
| 177 | }); | ||
| 178 | }, | ||
| 179 | .darling => if (!builder.enable_darling) { | ||
| 180 | std.debug.print( | ||
| 181 | "the host system ({s}) does not appear to be capable of executing binaries " ++ | ||
| 182 | "from the target ({s}). Consider enabling darling.\n", | ||
| 183 | .{ host_name, foreign_name }, | ||
| 184 | ); | ||
| 185 | }, | ||
| 186 | .rosetta => if (!builder.enable_rosetta) { | ||
| 187 | std.debug.print( | ||
| 188 | "the host system ({s}) does not appear to be capable of executing binaries " ++ | ||
| 189 | "from the target ({s}). Consider enabling rosetta.\n", | ||
| 190 | .{ host_name, foreign_name }, | ||
| 191 | ); | ||
| 192 | }, | ||
| 193 | .wine => if (!builder.enable_wine) { | ||
| 194 | std.debug.print( | ||
| 195 | "the host system ({s}) does not appear to be capable of executing binaries " ++ | ||
| 196 | "from the target ({s}). Consider enabling wine.\n", | ||
| 197 | .{ host_name, foreign_name }, | ||
| 198 | ); | ||
| 199 | }, | ||
| 200 | .qemu => if (!builder.enable_qemu) { | ||
| 201 | std.debug.print( | ||
| 202 | "the host system ({s}) does not appear to be capable of executing binaries " ++ | ||
| 203 | "from the target ({s}). Consider enabling qemu.\n", | ||
| 204 | .{ host_name, foreign_name }, | ||
| 205 | ); | ||
| 206 | }, | ||
| 207 | .wasmtime => { | ||
| 208 | std.debug.print( | ||
| 209 | "the host system ({s}) does not appear to be capable of executing binaries " ++ | ||
| 210 | "from the target ({s}). Consider enabling wasmtime.\n", | ||
| 211 | .{ host_name, foreign_name }, | ||
| 212 | ); | ||
| 213 | }, | ||
| 214 | } | ||
| 215 | } | ||
lib/std/build/RunStep.zig+79-34| ... | @@ -97,24 +97,42 @@ pub fn clearEnvironment(self: *RunStep) void { | ... | @@ -97,24 +97,42 @@ pub fn clearEnvironment(self: *RunStep) void { |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn addPathDir(self: *RunStep, search_path: []const u8) void { | 99 | pub fn addPathDir(self: *RunStep, search_path: []const u8) void { |
| 100 | const env_map = self.getEnvMap(); | 100 | addPathDirInternal(&self.step, self.builder, search_path); |
| 101 | } | ||
| 102 | |||
| 103 | /// For internal use only, users of `RunStep` should use `addPathDir` directly. | ||
| 104 | fn addPathDirInternal(step: *Step, builder: *Builder, search_path: []const u8) void { | ||
| 105 | const env_map = getEnvMapInternal(step, builder.allocator); | ||
| 101 | 106 | ||
| 102 | const key = "PATH"; | 107 | const key = "PATH"; |
| 103 | var prev_path = env_map.get(key); | 108 | var prev_path = env_map.get(key); |
| 104 | 109 | ||
| 105 | if (prev_path) |pp| { | 110 | if (prev_path) |pp| { |
| 106 | const new_path = self.builder.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path }); | 111 | const new_path = builder.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path }); |
| 107 | env_map.put(key, new_path) catch unreachable; | 112 | env_map.put(key, new_path) catch unreachable; |
| 108 | } else { | 113 | } else { |
| 109 | env_map.put(key, self.builder.dupePath(search_path)) catch unreachable; | 114 | env_map.put(key, builder.dupePath(search_path)) catch unreachable; |
| 110 | } | 115 | } |
| 111 | } | 116 | } |
| 112 | 117 | ||
| 113 | pub fn getEnvMap(self: *RunStep) *EnvMap { | 118 | pub fn getEnvMap(self: *RunStep) *EnvMap { |
| 114 | return self.env_map orelse { | 119 | return getEnvMapInternal(&self.step, self.builder.allocator); |
| 115 | const env_map = self.builder.allocator.create(EnvMap) catch unreachable; | 120 | } |
| 116 | env_map.* = process.getEnvMap(self.builder.allocator) catch unreachable; | 121 | |
| 117 | self.env_map = env_map; | 122 | fn getEnvMapInternal(step: *Step, allocator: Allocator) *EnvMap { |
| 123 | const maybe_env_map = switch (step.id) { | ||
| 124 | .run => step.cast(RunStep).?.env_map, | ||
| 125 | .emulatable_run => step.cast(build.EmulatableRunStep).?.env_map, | ||
| 126 | else => unreachable, | ||
| 127 | }; | ||
| 128 | return maybe_env_map orelse { | ||
| 129 | const env_map = allocator.create(EnvMap) catch unreachable; | ||
| 130 | env_map.* = process.getEnvMap(allocator) catch unreachable; | ||
| 131 | switch (step.id) { | ||
| 132 | .run => step.cast(RunStep).?.env_map = env_map, | ||
| 133 | .emulatable_run => step.cast(RunStep).?.env_map = env_map, | ||
| 134 | else => unreachable, | ||
| 135 | } | ||
| 118 | return env_map; | 136 | return env_map; |
| 119 | }; | 137 | }; |
| 120 | } | 138 | } |
| ... | @@ -146,10 +164,7 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { | ... | @@ -146,10 +164,7 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { |
| 146 | fn make(step: *Step) !void { | 164 | fn make(step: *Step) !void { |
| 147 | const self = @fieldParentPtr(RunStep, "step", step); | 165 | const self = @fieldParentPtr(RunStep, "step", step); |
| 148 | 166 | ||
| 149 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; | ||
| 150 | |||
| 151 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); | 167 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); |
| 152 | |||
| 153 | for (self.argv.items) |arg| { | 168 | for (self.argv.items) |arg| { |
| 154 | switch (arg) { | 169 | switch (arg) { |
| 155 | .bytes => |bytes| try argv_list.append(bytes), | 170 | .bytes => |bytes| try argv_list.append(bytes), |
| ... | @@ -165,24 +180,48 @@ fn make(step: *Step) !void { | ... | @@ -165,24 +180,48 @@ fn make(step: *Step) !void { |
| 165 | } | 180 | } |
| 166 | } | 181 | } |
| 167 | 182 | ||
| 168 | const argv = argv_list.items; | 183 | try runCommand( |
| 184 | argv_list.items, | ||
| 185 | self.builder, | ||
| 186 | self.expected_exit_code, | ||
| 187 | self.stdout_action, | ||
| 188 | self.stderr_action, | ||
| 189 | self.stdin_behavior, | ||
| 190 | self.env_map, | ||
| 191 | self.cwd, | ||
| 192 | self.print, | ||
| 193 | ); | ||
| 194 | } | ||
| 195 | |||
| 196 | pub fn runCommand( | ||
| 197 | argv: []const []const u8, | ||
| 198 | builder: *Builder, | ||
| 199 | expected_exit_code: ?u8, | ||
| 200 | stdout_action: StdIoAction, | ||
| 201 | stderr_action: StdIoAction, | ||
| 202 | stdin_behavior: std.ChildProcess.StdIo, | ||
| 203 | env_map: ?*EnvMap, | ||
| 204 | maybe_cwd: ?[]const u8, | ||
| 205 | print: bool, | ||
| 206 | ) !void { | ||
| 207 | const cwd = if (maybe_cwd) |cwd| builder.pathFromRoot(cwd) else builder.build_root; | ||
| 169 | 208 | ||
| 170 | if (!std.process.can_spawn) { | 209 | if (!std.process.can_spawn) { |
| 171 | const cmd = try std.mem.join(self.builder.allocator, " ", argv); | 210 | const cmd = try std.mem.join(builder.addInstallDirectory, " ", argv); |
| 172 | std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); | 211 | std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd }); |
| 173 | self.builder.allocator.free(cmd); | 212 | builder.allocator.free(cmd); |
| 174 | return ExecError.ExecNotSupported; | 213 | return ExecError.ExecNotSupported; |
| 175 | } | 214 | } |
| 176 | 215 | ||
| 177 | var child = std.ChildProcess.init(argv, self.builder.allocator); | 216 | var child = std.ChildProcess.init(argv, builder.allocator); |
| 178 | child.cwd = cwd; | 217 | child.cwd = cwd; |
| 179 | child.env_map = self.env_map orelse self.builder.env_map; | 218 | child.env_map = env_map orelse builder.env_map; |
| 180 | 219 | ||
| 181 | child.stdin_behavior = self.stdin_behavior; | 220 | child.stdin_behavior = stdin_behavior; |
| 182 | child.stdout_behavior = stdIoActionToBehavior(self.stdout_action); | 221 | child.stdout_behavior = stdIoActionToBehavior(stdout_action); |
| 183 | child.stderr_behavior = stdIoActionToBehavior(self.stderr_action); | 222 | child.stderr_behavior = stdIoActionToBehavior(stderr_action); |
| 184 | 223 | ||
| 185 | if (self.print) | 224 | if (print) |
| 186 | printCmd(cwd, argv); | 225 | printCmd(cwd, argv); |
| 187 | 226 | ||
| 188 | child.spawn() catch |err| { | 227 | child.spawn() catch |err| { |
| ... | @@ -193,21 +232,21 @@ fn make(step: *Step) !void { | ... | @@ -193,21 +232,21 @@ fn make(step: *Step) !void { |
| 193 | // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). | 232 | // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). |
| 194 | 233 | ||
| 195 | var stdout: ?[]const u8 = null; | 234 | var stdout: ?[]const u8 = null; |
| 196 | defer if (stdout) |s| self.builder.allocator.free(s); | 235 | defer if (stdout) |s| builder.allocator.free(s); |
| 197 | 236 | ||
| 198 | switch (self.stdout_action) { | 237 | switch (stdout_action) { |
| 199 | .expect_exact, .expect_matches => { | 238 | .expect_exact, .expect_matches => { |
| 200 | stdout = child.stdout.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; | 239 | stdout = child.stdout.?.reader().readAllAlloc(builder.allocator, max_stdout_size) catch unreachable; |
| 201 | }, | 240 | }, |
| 202 | .inherit, .ignore => {}, | 241 | .inherit, .ignore => {}, |
| 203 | } | 242 | } |
| 204 | 243 | ||
| 205 | var stderr: ?[]const u8 = null; | 244 | var stderr: ?[]const u8 = null; |
| 206 | defer if (stderr) |s| self.builder.allocator.free(s); | 245 | defer if (stderr) |s| builder.allocator.free(s); |
| 207 | 246 | ||
| 208 | switch (self.stderr_action) { | 247 | switch (stderr_action) { |
| 209 | .expect_exact, .expect_matches => { | 248 | .expect_exact, .expect_matches => { |
| 210 | stderr = child.stderr.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; | 249 | stderr = child.stderr.?.reader().readAllAlloc(builder.allocator, max_stdout_size) catch unreachable; |
| 211 | }, | 250 | }, |
| 212 | .inherit, .ignore => {}, | 251 | .inherit, .ignore => {}, |
| 213 | } | 252 | } |
| ... | @@ -219,18 +258,18 @@ fn make(step: *Step) !void { | ... | @@ -219,18 +258,18 @@ fn make(step: *Step) !void { |
| 219 | 258 | ||
| 220 | switch (term) { | 259 | switch (term) { |
| 221 | .Exited => |code| blk: { | 260 | .Exited => |code| blk: { |
| 222 | const expected_exit_code = self.expected_exit_code orelse break :blk; | 261 | const expected_code = expected_exit_code orelse break :blk; |
| 223 | 262 | ||
| 224 | if (code != expected_exit_code) { | 263 | if (code != expected_code) { |
| 225 | if (self.builder.prominent_compile_errors) { | 264 | if (builder.prominent_compile_errors) { |
| 226 | std.debug.print("Run step exited with error code {} (expected {})\n", .{ | 265 | std.debug.print("Run step exited with error code {} (expected {})\n", .{ |
| 227 | code, | 266 | code, |
| 228 | expected_exit_code, | 267 | expected_code, |
| 229 | }); | 268 | }); |
| 230 | } else { | 269 | } else { |
| 231 | std.debug.print("The following command exited with error code {} (expected {}):\n", .{ | 270 | std.debug.print("The following command exited with error code {} (expected {}):\n", .{ |
| 232 | code, | 271 | code, |
| 233 | expected_exit_code, | 272 | expected_code, |
| 234 | }); | 273 | }); |
| 235 | printCmd(cwd, argv); | 274 | printCmd(cwd, argv); |
| 236 | } | 275 | } |
| ... | @@ -245,7 +284,7 @@ fn make(step: *Step) !void { | ... | @@ -245,7 +284,7 @@ fn make(step: *Step) !void { |
| 245 | }, | 284 | }, |
| 246 | } | 285 | } |
| 247 | 286 | ||
| 248 | switch (self.stderr_action) { | 287 | switch (stderr_action) { |
| 249 | .inherit, .ignore => {}, | 288 | .inherit, .ignore => {}, |
| 250 | .expect_exact => |expected_bytes| { | 289 | .expect_exact => |expected_bytes| { |
| 251 | if (!mem.eql(u8, expected_bytes, stderr.?)) { | 290 | if (!mem.eql(u8, expected_bytes, stderr.?)) { |
| ... | @@ -277,7 +316,7 @@ fn make(step: *Step) !void { | ... | @@ -277,7 +316,7 @@ fn make(step: *Step) !void { |
| 277 | }, | 316 | }, |
| 278 | } | 317 | } |
| 279 | 318 | ||
| 280 | switch (self.stdout_action) { | 319 | switch (stdout_action) { |
| 281 | .inherit, .ignore => {}, | 320 | .inherit, .ignore => {}, |
| 282 | .expect_exact => |expected_bytes| { | 321 | .expect_exact => |expected_bytes| { |
| 283 | if (!mem.eql(u8, expected_bytes, stdout.?)) { | 322 | if (!mem.eql(u8, expected_bytes, stdout.?)) { |
| ... | @@ -319,12 +358,18 @@ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { | ... | @@ -319,12 +358,18 @@ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { |
| 319 | } | 358 | } |
| 320 | 359 | ||
| 321 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { | 360 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { |
| 361 | addPathForDynLibsInternal(&self.step, self.builder, artifact); | ||
| 362 | } | ||
| 363 | |||
| 364 | /// This should only be used for internal usage, this is called automatically | ||
| 365 | /// for the user. | ||
| 366 | pub fn addPathForDynLibsInternal(step: *Step, builder: *Builder, artifact: *LibExeObjStep) void { | ||
| 322 | for (artifact.link_objects.items) |link_object| { | 367 | for (artifact.link_objects.items) |link_object| { |
| 323 | switch (link_object) { | 368 | switch (link_object) { |
| 324 | .other_step => |other| { | 369 | .other_step => |other| { |
| 325 | if (other.target.isWindows() and other.isDynamicLibrary()) { | 370 | if (other.target.isWindows() and other.isDynamicLibrary()) { |
| 326 | self.addPathDir(fs.path.dirname(other.getOutputSource().getPath(self.builder)).?); | 371 | addPathDirInternal(step, builder, fs.path.dirname(other.getOutputSource().getPath(builder)).?); |
| 327 | self.addPathForDynLibs(other); | 372 | addPathForDynLibsInternal(step, builder, other); |
| 328 | } | 373 | } |
| 329 | }, | 374 | }, |
| 330 | else => {}, | 375 | else => {}, |
test/link.zig+63-65| ... | @@ -47,69 +47,67 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -47,69 +47,67 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 47 | .requires_stage2 = true, | 47 | .requires_stage2 = true, |
| 48 | }); | 48 | }); |
| 49 | 49 | ||
| 50 | if (builtin.os.tag == .macos) { | 50 | cases.addBuildFile("test/link/macho/entry/build.zig", .{ |
| 51 | cases.addBuildFile("test/link/macho/entry/build.zig", .{ | 51 | .build_modes = true, |
| 52 | .build_modes = true, | 52 | }); |
| 53 | }); | 53 | |
| 54 | 54 | cases.addBuildFile("test/link/macho/pagezero/build.zig", .{ | |
| 55 | cases.addBuildFile("test/link/macho/pagezero/build.zig", .{ | 55 | .build_modes = false, |
| 56 | .build_modes = false, | 56 | }); |
| 57 | }); | 57 | |
| 58 | 58 | cases.addBuildFile("test/link/macho/dylib/build.zig", .{ | |
| 59 | cases.addBuildFile("test/link/macho/dylib/build.zig", .{ | 59 | .build_modes = true, |
| 60 | .build_modes = true, | 60 | }); |
| 61 | }); | 61 | |
| 62 | 62 | cases.addBuildFile("test/link/macho/dead_strip/build.zig", .{ | |
| 63 | cases.addBuildFile("test/link/macho/dead_strip/build.zig", .{ | 63 | .build_modes = false, |
| 64 | .build_modes = false, | 64 | }); |
| 65 | }); | 65 | |
| 66 | 66 | cases.addBuildFile("test/link/macho/dead_strip_dylibs/build.zig", .{ | |
| 67 | cases.addBuildFile("test/link/macho/dead_strip_dylibs/build.zig", .{ | 67 | .build_modes = true, |
| 68 | .build_modes = true, | 68 | .requires_macos_sdk = true, |
| 69 | .requires_macos_sdk = true, | 69 | }); |
| 70 | }); | 70 | |
| 71 | 71 | cases.addBuildFile("test/link/macho/needed_library/build.zig", .{ | |
| 72 | cases.addBuildFile("test/link/macho/needed_library/build.zig", .{ | 72 | .build_modes = true, |
| 73 | .build_modes = true, | 73 | }); |
| 74 | }); | 74 | |
| 75 | 75 | cases.addBuildFile("test/link/macho/weak_library/build.zig", .{ | |
| 76 | cases.addBuildFile("test/link/macho/weak_library/build.zig", .{ | 76 | .build_modes = true, |
| 77 | .build_modes = true, | 77 | }); |
| 78 | }); | 78 | |
| 79 | 79 | cases.addBuildFile("test/link/macho/needed_framework/build.zig", .{ | |
| 80 | cases.addBuildFile("test/link/macho/needed_framework/build.zig", .{ | 80 | .build_modes = true, |
| 81 | .build_modes = true, | 81 | .requires_macos_sdk = true, |
| 82 | .requires_macos_sdk = true, | 82 | }); |
| 83 | }); | 83 | |
| 84 | 84 | cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{ | |
| 85 | cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{ | 85 | .build_modes = true, |
| 86 | .build_modes = true, | 86 | .requires_macos_sdk = true, |
| 87 | .requires_macos_sdk = true, | 87 | }); |
| 88 | }); | 88 | |
| 89 | 89 | // Try to build and run an Objective-C executable. | |
| 90 | // Try to build and run an Objective-C executable. | 90 | cases.addBuildFile("test/link/macho/objc/build.zig", .{ |
| 91 | cases.addBuildFile("test/link/macho/objc/build.zig", .{ | 91 | .build_modes = true, |
| 92 | .build_modes = true, | 92 | .requires_macos_sdk = true, |
| 93 | .requires_macos_sdk = true, | 93 | }); |
| 94 | }); | 94 | |
| 95 | 95 | // Try to build and run an Objective-C++ executable. | |
| 96 | // Try to build and run an Objective-C++ executable. | 96 | cases.addBuildFile("test/link/macho/objcpp/build.zig", .{ |
| 97 | cases.addBuildFile("test/link/macho/objcpp/build.zig", .{ | 97 | .build_modes = true, |
| 98 | .build_modes = true, | 98 | .requires_macos_sdk = true, |
| 99 | .requires_macos_sdk = true, | 99 | }); |
| 100 | }); | 100 | |
| 101 | 101 | cases.addBuildFile("test/link/macho/stack_size/build.zig", .{ | |
| 102 | cases.addBuildFile("test/link/macho/stack_size/build.zig", .{ | 102 | .build_modes = true, |
| 103 | .build_modes = true, | 103 | }); |
| 104 | }); | 104 | |
| 105 | 105 | cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{ | |
| 106 | cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{ | 106 | .build_modes = true, |
| 107 | .build_modes = true, | 107 | }); |
| 108 | }); | 108 | |
| 109 | 109 | cases.addBuildFile("test/link/macho/headerpad/build.zig", .{ | |
| 110 | cases.addBuildFile("test/link/macho/headerpad/build.zig", .{ | 110 | .build_modes = true, |
| 111 | .build_modes = true, | 111 | .requires_macos_sdk = true, |
| 112 | .requires_macos_sdk = true, | 112 | }); |
| 113 | }); | ||
| 114 | } | ||
| 115 | } | 113 | } |
test/link/macho/dead_strip/build.zig+2-6| ... | @@ -16,9 +16,7 @@ pub fn build(b: *Builder) void { | ... | @@ -16,9 +16,7 @@ pub fn build(b: *Builder) void { |
| 16 | check.checkInSymtab(); | 16 | check.checkInSymtab(); |
| 17 | check.checkNext("{*} (__TEXT,__text) external _iAmUnused"); | 17 | check.checkNext("{*} (__TEXT,__text) external _iAmUnused"); |
| 18 | 18 | ||
| 19 | test_step.dependOn(&check.step); | 19 | const run_cmd = check.runAndCompare(); |
| 20 | |||
| 21 | const run_cmd = exe.run(); | ||
| 22 | run_cmd.expectStdOutEqual("Hello!\n"); | 20 | run_cmd.expectStdOutEqual("Hello!\n"); |
| 23 | test_step.dependOn(&run_cmd.step); | 21 | test_step.dependOn(&run_cmd.step); |
| 24 | } | 22 | } |
| ... | @@ -32,9 +30,7 @@ pub fn build(b: *Builder) void { | ... | @@ -32,9 +30,7 @@ pub fn build(b: *Builder) void { |
| 32 | check.checkInSymtab(); | 30 | check.checkInSymtab(); |
| 33 | check.checkNotPresent("{*} (__TEXT,__text) external _iAmUnused"); | 31 | check.checkNotPresent("{*} (__TEXT,__text) external _iAmUnused"); |
| 34 | 32 | ||
| 35 | test_step.dependOn(&check.step); | 33 | const run_cmd = check.runAndCompare(); |
| 36 | |||
| 37 | const run_cmd = exe.run(); | ||
| 38 | run_cmd.expectStdOutEqual("Hello!\n"); | 34 | run_cmd.expectStdOutEqual("Hello!\n"); |
| 39 | test_step.dependOn(&run_cmd.step); | 35 | test_step.dependOn(&run_cmd.step); |
| 40 | } | 36 | } |
test/link/macho/dylib/build.zig+4-3| ... | @@ -3,12 +3,14 @@ const Builder = std.build.Builder; | ... | @@ -3,12 +3,14 @@ const Builder = std.build.Builder; |
| 3 | 3 | ||
| 4 | pub fn build(b: *Builder) void { | 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 5 | const mode = b.standardReleaseOptions(); |
| 6 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | ||
| 6 | 7 | ||
| 7 | const test_step = b.step("test", "Test"); | 8 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); | 9 | test_step.dependOn(b.getInstallStep()); |
| 9 | 10 | ||
| 10 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); |
| 11 | dylib.setBuildMode(mode); | 12 | dylib.setBuildMode(mode); |
| 13 | dylib.setTarget(target); | ||
| 12 | dylib.addCSourceFile("a.c", &.{}); | 14 | dylib.addCSourceFile("a.c", &.{}); |
| 13 | dylib.linkLibC(); | 15 | dylib.linkLibC(); |
| 14 | dylib.install(); | 16 | dylib.install(); |
| ... | @@ -23,6 +25,7 @@ pub fn build(b: *Builder) void { | ... | @@ -23,6 +25,7 @@ pub fn build(b: *Builder) void { |
| 23 | test_step.dependOn(&check_dylib.step); | 25 | test_step.dependOn(&check_dylib.step); |
| 24 | 26 | ||
| 25 | const exe = b.addExecutable("main", null); | 27 | const exe = b.addExecutable("main", null); |
| 28 | exe.setTarget(target); | ||
| 26 | exe.setBuildMode(mode); | 29 | exe.setBuildMode(mode); |
| 27 | exe.addCSourceFile("main.c", &.{}); | 30 | exe.addCSourceFile("main.c", &.{}); |
| 28 | exe.linkSystemLibrary("a"); | 31 | exe.linkSystemLibrary("a"); |
| ... | @@ -40,9 +43,7 @@ pub fn build(b: *Builder) void { | ... | @@ -40,9 +43,7 @@ pub fn build(b: *Builder) void { |
| 40 | check_exe.checkStart("cmd RPATH"); | 43 | check_exe.checkStart("cmd RPATH"); |
| 41 | check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable); | 44 | check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable); |
| 42 | 45 | ||
| 43 | test_step.dependOn(&check_exe.step); | 46 | const run = check_exe.runAndCompare(); |
| 44 | |||
| 45 | const run = exe.run(); | ||
| 46 | run.cwd = b.pathFromRoot("."); | 47 | run.cwd = b.pathFromRoot("."); |
| 47 | run.expectStdOutEqual("Hello world"); | 48 | run.expectStdOutEqual("Hello world"); |
| 48 | test_step.dependOn(&run.step); | 49 | test_step.dependOn(&run.step); |
test/link/macho/entry/build.zig+2-3| ... | @@ -8,6 +8,7 @@ pub fn build(b: *Builder) void { | ... | @@ -8,6 +8,7 @@ pub fn build(b: *Builder) void { |
| 8 | test_step.dependOn(b.getInstallStep()); | 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | 9 | ||
| 10 | const exe = b.addExecutable("main", null); | 10 | const exe = b.addExecutable("main", null); |
| 11 | exe.setTarget(.{ .os_tag = .macos }); | ||
| 11 | exe.setBuildMode(mode); | 12 | exe.setBuildMode(mode); |
| 12 | exe.addCSourceFile("main.c", &.{}); | 13 | exe.addCSourceFile("main.c", &.{}); |
| 13 | exe.linkLibC(); | 14 | exe.linkLibC(); |
| ... | @@ -26,9 +27,7 @@ pub fn build(b: *Builder) void { | ... | @@ -26,9 +27,7 @@ pub fn build(b: *Builder) void { |
| 26 | 27 | ||
| 27 | check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); | 28 | check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } }); |
| 28 | 29 | ||
| 29 | test_step.dependOn(&check_exe.step); | 30 | const run = check_exe.runAndCompare(); |
| 30 | |||
| 31 | const run = exe.run(); | ||
| 32 | run.expectStdOutEqual("42"); | 31 | run.expectStdOutEqual("42"); |
| 33 | test_step.dependOn(&run.step); | 32 | test_step.dependOn(&run.step); |
| 34 | } | 33 | } |
test/link/macho/needed_library/build.zig+4-2| ... | @@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep; | ... | @@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const mode = b.standardReleaseOptions(); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | ||
| 7 | 8 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 10 | test_step.dependOn(b.getInstallStep()); |
| 10 | 11 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 12 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); |
| 13 | dylib.setTarget(target); | ||
| 12 | dylib.setBuildMode(mode); | 14 | dylib.setBuildMode(mode); |
| 13 | dylib.addCSourceFile("a.c", &.{}); | 15 | dylib.addCSourceFile("a.c", &.{}); |
| 14 | dylib.linkLibC(); | 16 | dylib.linkLibC(); |
| ... | @@ -19,6 +21,7 @@ pub fn build(b: *Builder) void { | ... | @@ -19,6 +21,7 @@ pub fn build(b: *Builder) void { |
| 19 | const exe = b.addExecutable("test", null); | 21 | const exe = b.addExecutable("test", null); |
| 20 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 22 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 21 | exe.setBuildMode(mode); | 23 | exe.setBuildMode(mode); |
| 24 | exe.setTarget(target); | ||
| 22 | exe.linkLibC(); | 25 | exe.linkLibC(); |
| 23 | exe.linkSystemLibraryNeeded("a"); | 26 | exe.linkSystemLibraryNeeded("a"); |
| 24 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); | 27 | exe.addLibraryPath(b.pathFromRoot("zig-out/lib")); |
| ... | @@ -28,8 +31,7 @@ pub fn build(b: *Builder) void { | ... | @@ -28,8 +31,7 @@ pub fn build(b: *Builder) void { |
| 28 | const check = exe.checkObject(.macho); | 31 | const check = exe.checkObject(.macho); |
| 29 | check.checkStart("cmd LOAD_DYLIB"); | 32 | check.checkStart("cmd LOAD_DYLIB"); |
| 30 | check.checkNext("name @rpath/liba.dylib"); | 33 | check.checkNext("name @rpath/liba.dylib"); |
| 31 | test_step.dependOn(&check.step); | ||
| 32 | 34 | ||
| 33 | const run_cmd = exe.run(); | 35 | const run_cmd = check.runAndCompare(); |
| 34 | test_step.dependOn(&run_cmd.step); | 36 | test_step.dependOn(&run_cmd.step); |
| 35 | } | 37 | } |
test/link/macho/objc/build.zig+1-2| ... | @@ -7,7 +7,6 @@ pub fn build(b: *Builder) void { | ... | @@ -7,7 +7,6 @@ pub fn build(b: *Builder) void { |
| 7 | const test_step = b.step("test", "Test the program"); | 7 | const test_step = b.step("test", "Test the program"); |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable("test", null); | 9 | const exe = b.addExecutable("test", null); |
| 10 | b.default_step.dependOn(&exe.step); | ||
| 11 | exe.addIncludePath("."); | 10 | exe.addIncludePath("."); |
| 12 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); | 11 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); |
| 13 | exe.addCSourceFile("test.m", &[0][]const u8{}); | 12 | exe.addCSourceFile("test.m", &[0][]const u8{}); |
| ... | @@ -17,6 +16,6 @@ pub fn build(b: *Builder) void { | ... | @@ -17,6 +16,6 @@ pub fn build(b: *Builder) void { |
| 17 | // populate paths to the sysroot here. | 16 | // populate paths to the sysroot here. |
| 18 | exe.linkFramework("Foundation"); | 17 | exe.linkFramework("Foundation"); |
| 19 | 18 | ||
| 20 | const run_cmd = exe.run(); | 19 | const run_cmd = std.build.EmulatableRunStep.create(b, "run", exe); |
| 21 | test_step.dependOn(&run_cmd.step); | 20 | test_step.dependOn(&run_cmd.step); |
| 22 | } | 21 | } |
test/link/macho/pagezero/build.zig+2| ... | @@ -9,6 +9,7 @@ pub fn build(b: *Builder) void { | ... | @@ -9,6 +9,7 @@ pub fn build(b: *Builder) void { |
| 9 | 9 | ||
| 10 | { | 10 | { |
| 11 | const exe = b.addExecutable("pagezero", null); | 11 | const exe = b.addExecutable("pagezero", null); |
| 12 | exe.setTarget(.{ .os_tag = .macos }); | ||
| 12 | exe.setBuildMode(mode); | 13 | exe.setBuildMode(mode); |
| 13 | exe.addCSourceFile("main.c", &.{}); | 14 | exe.addCSourceFile("main.c", &.{}); |
| 14 | exe.linkLibC(); | 15 | exe.linkLibC(); |
| ... | @@ -28,6 +29,7 @@ pub fn build(b: *Builder) void { | ... | @@ -28,6 +29,7 @@ pub fn build(b: *Builder) void { |
| 28 | 29 | ||
| 29 | { | 30 | { |
| 30 | const exe = b.addExecutable("no_pagezero", null); | 31 | const exe = b.addExecutable("no_pagezero", null); |
| 32 | exe.setTarget(.{ .os_tag = .macos }); | ||
| 31 | exe.setBuildMode(mode); | 33 | exe.setBuildMode(mode); |
| 32 | exe.addCSourceFile("main.c", &.{}); | 34 | exe.addCSourceFile("main.c", &.{}); |
| 33 | exe.linkLibC(); | 35 | exe.linkLibC(); |
test/link/macho/search_strategy/build.zig+6-4| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | const LibExeObjectStep = std.build.LibExeObjStep; | 3 | const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | ||
| 4 | 5 | ||
| 5 | pub fn build(b: *Builder) void { | 6 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 7 | const mode = b.standardReleaseOptions(); |
| ... | @@ -17,9 +18,7 @@ pub fn build(b: *Builder) void { | ... | @@ -17,9 +18,7 @@ pub fn build(b: *Builder) void { |
| 17 | check.checkStart("cmd LOAD_DYLIB"); | 18 | check.checkStart("cmd LOAD_DYLIB"); |
| 18 | check.checkNext("name @rpath/liba.dylib"); | 19 | check.checkNext("name @rpath/liba.dylib"); |
| 19 | 20 | ||
| 20 | test_step.dependOn(&check.step); | 21 | const run = check.runAndCompare(); |
| 21 | |||
| 22 | const run = exe.run(); | ||
| 23 | run.cwd = b.pathFromRoot("."); | 22 | run.cwd = b.pathFromRoot("."); |
| 24 | run.expectStdOutEqual("Hello world"); | 23 | run.expectStdOutEqual("Hello world"); |
| 25 | test_step.dependOn(&run.step); | 24 | test_step.dependOn(&run.step); |
| ... | @@ -30,7 +29,7 @@ pub fn build(b: *Builder) void { | ... | @@ -30,7 +29,7 @@ pub fn build(b: *Builder) void { |
| 30 | const exe = createScenario(b, mode); | 29 | const exe = createScenario(b, mode); |
| 31 | exe.search_strategy = .paths_first; | 30 | exe.search_strategy = .paths_first; |
| 32 | 31 | ||
| 33 | const run = exe.run(); | 32 | const run = std.build.EmulatableRunStep.create(b, "run", exe); |
| 34 | run.cwd = b.pathFromRoot("."); | 33 | run.cwd = b.pathFromRoot("."); |
| 35 | run.expectStdOutEqual("Hello world"); | 34 | run.expectStdOutEqual("Hello world"); |
| 36 | test_step.dependOn(&run.step); | 35 | test_step.dependOn(&run.step); |
| ... | @@ -39,6 +38,7 @@ pub fn build(b: *Builder) void { | ... | @@ -39,6 +38,7 @@ pub fn build(b: *Builder) void { |
| 39 | 38 | ||
| 40 | fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | 39 | fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { |
| 41 | const static = b.addStaticLibrary("a", null); | 40 | const static = b.addStaticLibrary("a", null); |
| 41 | static.setTarget(target); | ||
| 42 | static.setBuildMode(mode); | 42 | static.setBuildMode(mode); |
| 43 | static.addCSourceFile("a.c", &.{}); | 43 | static.addCSourceFile("a.c", &.{}); |
| 44 | static.linkLibC(); | 44 | static.linkLibC(); |
| ... | @@ -48,6 +48,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | ... | @@ -48,6 +48,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { |
| 48 | static.install(); | 48 | static.install(); |
| 49 | 49 | ||
| 50 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 50 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); |
| 51 | dylib.setTarget(target); | ||
| 51 | dylib.setBuildMode(mode); | 52 | dylib.setBuildMode(mode); |
| 52 | dylib.addCSourceFile("a.c", &.{}); | 53 | dylib.addCSourceFile("a.c", &.{}); |
| 53 | dylib.linkLibC(); | 54 | dylib.linkLibC(); |
| ... | @@ -57,6 +58,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { | ... | @@ -57,6 +58,7 @@ fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { |
| 57 | dylib.install(); | 58 | dylib.install(); |
| 58 | 59 | ||
| 59 | const exe = b.addExecutable("main", null); | 60 | const exe = b.addExecutable("main", null); |
| 61 | exe.setTarget(target); | ||
| 60 | exe.setBuildMode(mode); | 62 | exe.setBuildMode(mode); |
| 61 | exe.addCSourceFile("main.c", &.{}); | 63 | exe.addCSourceFile("main.c", &.{}); |
| 62 | exe.linkSystemLibraryName("a"); | 64 | exe.linkSystemLibraryName("a"); |
test/link/macho/stack_size/build.zig+2-3| ... | @@ -8,6 +8,7 @@ pub fn build(b: *Builder) void { | ... | @@ -8,6 +8,7 @@ pub fn build(b: *Builder) void { |
| 8 | test_step.dependOn(b.getInstallStep()); | 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | 9 | ||
| 10 | const exe = b.addExecutable("main", null); | 10 | const exe = b.addExecutable("main", null); |
| 11 | exe.setTarget(.{ .os_tag = .macos }); | ||
| 11 | exe.setBuildMode(mode); | 12 | exe.setBuildMode(mode); |
| 12 | exe.addCSourceFile("main.c", &.{}); | 13 | exe.addCSourceFile("main.c", &.{}); |
| 13 | exe.linkLibC(); | 14 | exe.linkLibC(); |
| ... | @@ -17,8 +18,6 @@ pub fn build(b: *Builder) void { | ... | @@ -17,8 +18,6 @@ pub fn build(b: *Builder) void { |
| 17 | check_exe.checkStart("cmd MAIN"); | 18 | check_exe.checkStart("cmd MAIN"); |
| 18 | check_exe.checkNext("stacksize 100000000"); | 19 | check_exe.checkNext("stacksize 100000000"); |
| 19 | 20 | ||
| 20 | test_step.dependOn(&check_exe.step); | 21 | const run = check_exe.runAndCompare(); |
| 21 | |||
| 22 | const run = exe.run(); | ||
| 23 | test_step.dependOn(&run.step); | 22 | test_step.dependOn(&run.step); |
| 24 | } | 23 | } |
test/link/macho/weak_library/build.zig+4-3| ... | @@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep; | ... | @@ -4,11 +4,13 @@ const LibExeObjectStep = std.build.LibExeObjStep; |
| 4 | 4 | ||
| 5 | pub fn build(b: *Builder) void { | 5 | pub fn build(b: *Builder) void { |
| 6 | const mode = b.standardReleaseOptions(); | 6 | const mode = b.standardReleaseOptions(); |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | ||
| 7 | 8 | ||
| 8 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 9 | test_step.dependOn(b.getInstallStep()); | 10 | test_step.dependOn(b.getInstallStep()); |
| 10 | 11 | ||
| 11 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); | 12 | const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0)); |
| 13 | dylib.setTarget(target); | ||
| 12 | dylib.setBuildMode(mode); | 14 | dylib.setBuildMode(mode); |
| 13 | dylib.addCSourceFile("a.c", &.{}); | 15 | dylib.addCSourceFile("a.c", &.{}); |
| 14 | dylib.linkLibC(); | 16 | dylib.linkLibC(); |
| ... | @@ -16,6 +18,7 @@ pub fn build(b: *Builder) void { | ... | @@ -16,6 +18,7 @@ pub fn build(b: *Builder) void { |
| 16 | 18 | ||
| 17 | const exe = b.addExecutable("test", null); | 19 | const exe = b.addExecutable("test", null); |
| 18 | exe.addCSourceFile("main.c", &[0][]const u8{}); | 20 | exe.addCSourceFile("main.c", &[0][]const u8{}); |
| 21 | exe.setTarget(target); | ||
| 19 | exe.setBuildMode(mode); | 22 | exe.setBuildMode(mode); |
| 20 | exe.linkLibC(); | 23 | exe.linkLibC(); |
| 21 | exe.linkSystemLibraryWeak("a"); | 24 | exe.linkSystemLibraryWeak("a"); |
| ... | @@ -30,9 +33,7 @@ pub fn build(b: *Builder) void { | ... | @@ -30,9 +33,7 @@ pub fn build(b: *Builder) void { |
| 30 | check.checkNext("(undefined) weak external _a (from liba)"); | 33 | check.checkNext("(undefined) weak external _a (from liba)"); |
| 31 | check.checkNext("(undefined) weak external _asStr (from liba)"); | 34 | check.checkNext("(undefined) weak external _asStr (from liba)"); |
| 32 | 35 | ||
| 33 | test_step.dependOn(&check.step); | 36 | const run_cmd = check.runAndCompare(); |
| 34 | |||
| 35 | const run_cmd = exe.run(); | ||
| 36 | run_cmd.expectStdOutEqual("42 42"); | 37 | run_cmd.expectStdOutEqual("42 42"); |
| 37 | test_step.dependOn(&run_cmd.step); | 38 | test_step.dependOn(&run_cmd.step); |
| 38 | } | 39 | } |