Skip to content

Commit

Permalink
Support Zig master (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn authored Oct 30, 2023
1 parent 1ae977b commit 948486f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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='')" },
});
Expand All @@ -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='')" },
});
Expand All @@ -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;
7 changes: 5 additions & 2 deletions pydust/src/pydust.build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 },
});
Expand All @@ -308,11 +309,13 @@ 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);
}
allocator.free(result.stderr);
return result.stdout;
}

const runProcess = if (builtin.zig_version.minor >= 12) std.process.Child.run else std.process.Child.exec;

0 comments on commit 948486f

Please sign in to comment.