Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run library tests");
const docs_step = b.step("docs", "Generate docs");

const translate_c = b.addTranslateC(.{
.root_source_file = b.path("pydust/src/ffi.h"),
.target = target,
.optimize = optimize,
});
translate_c.defineCMacro("Py_LIMITED_API", "0x030D0000");
translate_c.addIncludePath(.{ .cwd_relative = pythonInc });

// We never build this lib, but we use it to generate docs.
const pydust_lib = b.addLibrary(.{
.linkage = .dynamic,
Expand All @@ -47,7 +39,6 @@ pub fn build(b: *std.Build) void {
});
const pydust_lib_mod = b.createModule(.{ .root_source_file = b.path("./pyconf.dummy.zig") });
pydust_lib_mod.addIncludePath(.{ .cwd_relative = pythonInc });
pydust_lib.root_module.addImport("ffi", translate_c.createModule());
pydust_lib.root_module.addImport("pyconf", pydust_lib_mod);

const pydust_docs = b.addInstallDirectory(.{
Expand All @@ -71,7 +62,6 @@ pub fn build(b: *std.Build) void {
main_tests.addRPath(.{ .cwd_relative = pythonLib });
const main_tests_mod = b.createModule(.{ .root_source_file = b.path("./pyconf.dummy.zig") });
main_tests_mod.addIncludePath(.{ .cwd_relative = pythonInc });
main_tests.root_module.addImport("ffi", translate_c.createModule());
main_tests.root_module.addImport("pyconf", main_tests_mod);

const run_main_tests = b.addRunArtifact(main_tests);
Expand All @@ -93,7 +83,6 @@ pub fn build(b: *std.Build) void {
example_lib.addRPath(.{ .cwd_relative = pythonLib });
const example_lib_mod = b.createModule(.{ .root_source_file = b.path("pydust/src/pydust.zig") });
example_lib_mod.addIncludePath(.{ .cwd_relative = pythonInc });
example_lib.root_module.addImport("ffi", translate_c.createModule());
example_lib.root_module.addImport("pydust", example_lib_mod);
example_lib.root_module.addImport(
"pyconf",
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const std = @import("std");
const py = @import("./pydust.zig");
const pytypes = @import("./pytypes.zig");
const State = @import("./discovery.zig").State;
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const PyError = @import("./errors.zig").PyError;

/// Zig enum for python richcompare op int.
Expand Down
20 changes: 0 additions & 20 deletions pydust/src/ffi.h

This file was deleted.

22 changes: 22 additions & 0 deletions pydust/src/ffi.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// limitations under the License.

// Export the Limited Python C API for use within PyDust.

const pyconf = @import("pyconf");

pub const ffi = @cImport({
if (pyconf.limited_api) {
@cDefine("Py_LIMITED_API", pyconf.hexversion);
}

@cDefine("PY_SSIZE_T_CLEAN", {});

@cInclude("Python.h");

// From 3.12 onwards, structmember.h is fixed to be including in Python.h

// See https://github.com/python/cpython/pull/99014

@cInclude("structmember.h");
});

2 changes: 1 addition & 1 deletion pydust/src/functions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// limitations under the License.

const std = @import("std");
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const py = @import("pydust.zig");
const tramp = @import("trampoline.zig");
const State = @import("discovery.zig").State;
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const std = @import("std");
const mem = std.mem;
const Allocator = std.mem.Allocator;
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const py = @import("./pydust.zig");

pub const PyMemAllocator = struct {
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/modules.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const std = @import("std");
const State = @import("discovery.zig").State;
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const py = @import("pydust.zig");
const PyError = py.PyError;
const Attributes = @import("attributes.zig").Attributes;
Expand Down
24 changes: 2 additions & 22 deletions pydust/src/pydust.build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,9 @@ pub const PydustStep = struct {
}),
});
lib.root_module.addOptions("pyconf", pyconf);
const translate_c = self.addTranslateC(options);
translate_c.addIncludePath(b.path(self.python_include_dir));
const lib_module = b.createModule(.{
.root_source_file = b.path(self.pydust_source_file),
.imports = &.{
.{ .name = "pyconf", .module = pyconf.createModule() },
.{ .name = "ffi", .module = translate_c.createModule() },
},
.imports = &.{.{ .name = "pyconf", .module = pyconf.createModule() }},
});
lib_module.addIncludePath(b.path(self.python_include_dir));
lib.root_module.addImport("pydust", lib_module);
Expand Down Expand Up @@ -225,10 +220,7 @@ pub const PydustStep = struct {
libtest.root_module.addOptions("pyconf", pyconf);
const libtest_module = b.createModule(.{
.root_source_file = b.path(self.pydust_source_file),
.imports = &.{
.{ .name = "pyconf", .module = pyconf.createModule() },
.{ .name = "ffi", .module = translate_c.createModule() },
},
.imports = &.{.{ .name = "pyconf", .module = pyconf.createModule() }},
});
libtest_module.addIncludePath(b.path(self.python_include_dir));
libtest.root_module.addImport("pydust", libtest_module);
Expand Down Expand Up @@ -290,18 +282,6 @@ pub const PydustStep = struct {
fn pythonOutput(self: *PydustStep, code: []const u8) ![]const u8 {
return getPythonOutput(self.allocator, self.python_exe, code);
}

fn addTranslateC(self: PydustStep, options: PythonModuleOptions) *std.Build.Step.TranslateC {
const b = self.owner;
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("pydust/src/ffi.h"),
.target = b.resolveTargetQuery(options.target),
.optimize = options.optimize,
});
if (options.limited_api)
translate_c.defineCMacro("Py_LIMITED_API", self.hexversion);
return translate_c;
}
};

fn getLibpython(allocator: std.mem.Allocator, python_exe: []const u8) ![]const u8 {
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/pydust.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub const ValueError = err.ValueError;
pub const Warning = err.Warning;
pub const WindowsError = err.WindowsError;
pub const ZeroDivisionError = err.ZeroDivisionError;
pub const ffi = @import("ffi");
pub const ffi = @import("ffi.zig").ffi;
pub const PyError = @import("errors.zig").PyError;
pub const allocator: std.mem.Allocator = mem.PyMemAllocator.allocator();

Expand Down
2 changes: 1 addition & 1 deletion pydust/src/pytypes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// https://docs.python.org/3/extending/newtypes_tutorial.html

const std = @import("std");
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const py = @import("pydust.zig");
const discovery = @import("discovery.zig");
const Attributes = @import("attributes.zig").Attributes;
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/trampoline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// Utilities for bouncing CPython calls into Zig functions and back again.
const std = @import("std");
const Type = std.builtin.Type;
const ffi = @import("ffi");
const ffi = @import("ffi.zig").ffi;
const py = @import("pydust.zig");
const State = @import("discovery.zig").State;
const funcs = @import("functions.zig");
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/types/error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const builtin = @import("builtin");
const std = @import("std");
const ffi = @import("ffi");
const ffi = @import("../ffi.zig").ffi;
const py = @import("../pydust.zig");
const PyError = @import("../errors.zig").PyError;
const State = @import("../discovery.zig").State;
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/types/module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const std = @import("std");
const Allocator = @import("std").mem.Allocator;
const mem = @import("../mem.zig");
const ffi = @import("ffi");
const ffi = @import("../ffi.zig").ffi;
const py = @import("../pydust.zig");
const PyObjectMixin = @import("./obj.zig").PyObjectMixin;
const pytypes = @import("../pytypes.zig");
Expand Down
2 changes: 1 addition & 1 deletion pydust/src/types/obj.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// limitations under the License.

const std = @import("std");
const ffi = @import("ffi");
const ffi = @import("../ffi.zig").ffi;
const py = @import("../pydust.zig");
const PyError = @import("../errors.zig").PyError;
const State = @import("../discovery.zig").State;
Expand Down