-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.zig
More file actions
57 lines (47 loc) · 2.09 KB
/
build.zig
File metadata and controls
57 lines (47 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Build script for Liburing
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const static_path = "lib/liburing/src/liburing-ffi.a";
// Strip option (can be set via -Dstrip=true or from pyoz CLI)
const strip = b.option(bool, "strip", "Strip debug symbols from the binary") orelse false;
// Get PyOZ dependency
const pyoz_dep = b.dependency("PyOZ", .{ .target = target, .optimize = optimize });
// Create the user's lib module
const user_lib_mod = b.createModule(.{
.root_source_file = b.path("src/liburing/root.zig"),
.optimize = optimize,
.target = target,
.strip = strip,
.imports = &.{.{ .name = "PyOZ", .module = pyoz_dep.module("PyOZ") }},
});
// If not already compiled compile C liburing.
std.fs.cwd().access(static_path, .{}) catch |e| switch (e) {
error.FileNotFound => {
try runCmd(b.allocator, &.{"./configure"}, "lib/liburing");
try runCmd(b.allocator, &.{ "make", "library" }, "lib/liburing");
},
else => return e, // other error
};
user_lib_mod.addObjectFile(b.path(static_path));
user_lib_mod.addIncludePath(b.path("lib/liburing/src/include"));
// Build the Python extension as a dynamic library
const lib = b.addLibrary(.{
.name = "liburing",
.linkage = .dynamic,
.root_module = user_lib_mod,
});
// Link libc (required for Python C API)
lib.root_module.link_libc = true;
// Install the shared library
const install = b.addInstallArtifact(lib, .{ .dest_sub_path = "liburing.so" });
b.getInstallStep().dependOn(&install.step);
}
fn runCmd(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void {
const output = try std.process.Child.run(.{ .allocator = allocator, .argv = argv, .cwd = cwd });
defer allocator.free(output.stderr);
defer allocator.free(output.stdout);
if (output.term.Exited != 0) return error.CommandFailed;
}