diff --git a/build.zig b/build.zig index 1a59c706..8aaf7022 100644 --- a/build.zig +++ b/build.zig @@ -10,6 +10,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +const builtin = @import("builtin"); const std = @import("std"); pub fn build(b: *std.Build) void { @@ -91,7 +92,7 @@ fn getPythonIncludePath( python_exe: []const u8, allocator: std.mem.Allocator, ) ![]const u8 { - const includeResult = try std.process.Child.exec(.{ + const includeResult = try runProcess(.{ .allocator = allocator, .argv = &.{ python_exe, "-c", "import sysconfig; print(sysconfig.get_path('include'), end='')" }, }); @@ -100,7 +101,7 @@ fn getPythonIncludePath( } fn getPythonLibraryPath(python_exe: []const u8, allocator: std.mem.Allocator) ![]const u8 { - const includeResult = try std.process.Child.exec(.{ + const includeResult = try runProcess(.{ .allocator = allocator, .argv = &.{ python_exe, "-c", "import sysconfig; print(sysconfig.get_config_var('LIBDIR'), end='')" }, }); @@ -109,10 +110,12 @@ fn getPythonLibraryPath(python_exe: []const u8, allocator: std.mem.Allocator) ![ } fn getPythonLDVersion(python_exe: []const u8, allocator: std.mem.Allocator) ![]const u8 { - const includeResult = try std.process.Child.exec(.{ + const includeResult = try runProcess(.{ .allocator = allocator, .argv = &.{ python_exe, "-c", "import sysconfig; print(sysconfig.get_config_var('LDVERSION'), end='')" }, }); defer allocator.free(includeResult.stderr); return includeResult.stdout; } + +const runProcess = if (builtin.zig_version.minor >= 12) std.process.Child.run else std.process.Child.exec; diff --git a/pydust/src/pydust.build.zig b/pydust/src/pydust.build.zig index 2236d05b..75a2e1cb 100644 --- a/pydust/src/pydust.build.zig +++ b/pydust/src/pydust.build.zig @@ -9,6 +9,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +const builtin = @import("builtin"); const std = @import("std"); const Step = std.Build.Step; const LazyPath = std.Build.LazyPath; @@ -295,7 +296,7 @@ fn getLibpython(allocator: std.mem.Allocator, python_exe: []const u8) ![]const u } fn getPythonOutput(allocator: std.mem.Allocator, python_exe: []const u8, code: []const u8) ![]const u8 { - const result = try std.process.Child.exec(.{ + const result = try runProcess(.{ .allocator = allocator, .argv = &.{ python_exe, "-c", code }, }); @@ -308,7 +309,7 @@ fn getPythonOutput(allocator: std.mem.Allocator, python_exe: []const u8, code: [ } fn getStdOutput(allocator: std.mem.Allocator, argv: []const []const u8) ![]const u8 { - const result = try std.process.Child.exec(.{ .allocator = allocator, .argv = argv }); + const result = try runProcess(.{ .allocator = allocator, .argv = argv }); if (result.term.Exited != 0) { std.debug.print("Failed to execute {any}:\n{s}\n", .{ argv, result.stderr }); std.process.exit(1); @@ -316,3 +317,5 @@ fn getStdOutput(allocator: std.mem.Allocator, argv: []const []const u8) ![]const allocator.free(result.stderr); return result.stdout; } + +const runProcess = if (builtin.zig_version.minor >= 12) std.process.Child.run else std.process.Child.exec;