| ... | @@ -1060,6 +1060,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1060,6 +1060,7 @@ pub const LibExeObjStep = struct { |
| 1060 | /// Add command line arguments with `addArg`. | 1060 | /// Add command line arguments with `addArg`. |
| 1061 | pub fn run(exe: *LibExeObjStep) *RunStep { | 1061 | pub fn run(exe: *LibExeObjStep) *RunStep { |
| 1062 | assert(exe.kind == Kind.Exe); | 1062 | assert(exe.kind == Kind.Exe); |
| | 1063 | assert(exe.target == Target.Native); |
| 1063 | const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name)); | 1064 | const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name)); |
| 1064 | run_step.addArtifactArg(exe); | 1065 | run_step.addArtifactArg(exe); |
| 1065 | return run_step; | 1066 | return run_step; |
| ... | @@ -1276,7 +1277,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1276,7 +1277,7 @@ pub const LibExeObjStep = struct { |
| 1276 | LibExeObjStep.Kind.Lib => { | 1277 | LibExeObjStep.Kind.Lib => { |
| 1277 | if (other.static or self.target.isWindows()) { | 1278 | if (other.static or self.target.isWindows()) { |
| 1278 | try zig_args.append("--object"); | 1279 | try zig_args.append("--object"); |
| 1279 | try zig_args.append(other.getOutputPath()); | 1280 | try zig_args.append(other.getOutputLibPath()); |
| 1280 | } else { | 1281 | } else { |
| 1281 | const full_path_lib = other.getOutputPath(); | 1282 | const full_path_lib = other.getOutputPath(); |
| 1282 | try zig_args.append("--library"); | 1283 | try zig_args.append("--library"); |
| ... | @@ -1495,7 +1496,7 @@ pub const RunStep = struct { | ... | @@ -1495,7 +1496,7 @@ pub const RunStep = struct { |
| 1495 | cwd: ?[]const u8, | 1496 | cwd: ?[]const u8, |
| 1496 | | 1497 | |
| 1497 | /// Override this field to modify the environment, or use setEnvironmentVariable | 1498 | /// Override this field to modify the environment, or use setEnvironmentVariable |
| 1498 | env_map: ?*const BufMap, | 1499 | env_map: ?*BufMap, |
| 1499 | | 1500 | |
| 1500 | pub const Arg = union(enum) { | 1501 | pub const Arg = union(enum) { |
| 1501 | Artifact: *LibExeObjStep, | 1502 | Artifact: *LibExeObjStep, |
| ... | @@ -1529,12 +1530,28 @@ pub const RunStep = struct { | ... | @@ -1529,12 +1530,28 @@ pub const RunStep = struct { |
| 1529 | } | 1530 | } |
| 1530 | } | 1531 | } |
| 1531 | | 1532 | |
| 1532 | pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8) void { | 1533 | pub fn addPathDir(self: *RunStep, search_path: []const u8) void { |
| 1533 | const env_map = self.env_map orelse blk: { | 1534 | const PATH = if (builtin.os == builtin.Os.windows) "Path" else "PATH"; |
| 1534 | const env_map = os.getEnvMap(allocator) catch unreachable; | 1535 | const env_map = self.getEnvMap(); |
| | 1536 | const prev_path = env_map.get(PATH) orelse { |
| | 1537 | env_map.set(PATH, search_path) catch unreachable; |
| | 1538 | return; |
| | 1539 | }; |
| | 1540 | const new_path = self.builder.fmt("{}" ++ [1]u8{os.path.delimiter} ++ "{}", prev_path, search_path); |
| | 1541 | env_map.set(PATH, new_path) catch unreachable; |
| | 1542 | } |
| | 1543 | |
| | 1544 | pub fn getEnvMap(self: *RunStep) *BufMap { |
| | 1545 | return self.env_map orelse { |
| | 1546 | const env_map = self.builder.allocator.create(BufMap) catch unreachable; |
| | 1547 | env_map.* = os.getEnvMap(self.builder.allocator) catch unreachable; |
| 1535 | self.env_map = env_map; | 1548 | self.env_map = env_map; |
| 1536 | break :blk env_map; | 1549 | return env_map; |
| 1537 | }; | 1550 | }; |
| | 1551 | } |
| | 1552 | |
| | 1553 | pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8) void { |
| | 1554 | const env_map = self.getEnvMap(); |
| 1538 | env_map.set(key, value) catch unreachable; | 1555 | env_map.set(key, value) catch unreachable; |
| 1539 | } | 1556 | } |
| 1540 | | 1557 | |
| ... | @@ -1547,12 +1564,32 @@ pub const RunStep = struct { | ... | @@ -1547,12 +1564,32 @@ pub const RunStep = struct { |
| 1547 | for (self.argv.toSlice()) |arg| { | 1564 | for (self.argv.toSlice()) |arg| { |
| 1548 | switch (arg) { | 1565 | switch (arg) { |
| 1549 | Arg.Bytes => |bytes| try argv.append(bytes), | 1566 | Arg.Bytes => |bytes| try argv.append(bytes), |
| 1550 | Arg.Artifact => |artifact| try argv.append(artifact.getOutputPath()), | 1567 | Arg.Artifact => |artifact| { |
| | 1568 | if (artifact.target.isWindows()) { |
| | 1569 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| | 1570 | self.addPathForDynLibs(artifact); |
| | 1571 | } |
| | 1572 | try argv.append(artifact.getOutputPath()); |
| | 1573 | }, |
| 1551 | } | 1574 | } |
| 1552 | } | 1575 | } |
| 1553 | | 1576 | |
| 1554 | return self.builder.spawnChildEnvMap(cwd, self.env_map orelse self.builder.env_map, argv.toSliceConst()); | 1577 | return self.builder.spawnChildEnvMap(cwd, self.env_map orelse self.builder.env_map, argv.toSliceConst()); |
| 1555 | } | 1578 | } |
| | 1579 | |
| | 1580 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { |
| | 1581 | for (artifact.link_objects.toSliceConst()) |link_object| { |
| | 1582 | switch (link_object) { |
| | 1583 | LibExeObjStep.LinkObject.OtherStep => |other| { |
| | 1584 | if (other.target.isWindows() and other.isDynamicLibrary()) { |
| | 1585 | self.addPathDir(os.path.dirname(other.getOutputPath()).?); |
| | 1586 | self.addPathForDynLibs(other); |
| | 1587 | } |
| | 1588 | }, |
| | 1589 | else => {}, |
| | 1590 | } |
| | 1591 | } |
| | 1592 | } |
| 1556 | }; | 1593 | }; |
| 1557 | | 1594 | |
| 1558 | const InstallArtifactStep = struct { | 1595 | const InstallArtifactStep = struct { |