Skip to content

Commit 0937e81

Browse files
authored
Update Zig, Adopt 0.11 Package Manager (mitchellh#52)
This updates Zig to nearly 0.11 (likely one or two days away). This also enforces the Zig package manager as the one true way.
2 parents a3e5c9b + ab31ced commit 0937e81

File tree

4 files changed

+77
-45
lines changed

4 files changed

+77
-45
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ int main(void) {
183183
</tr>
184184
</table>
185185

186+
## Installation (Zig)
187+
188+
**These instructions are for Zig downstream users only.** If you are
189+
using the C API to libxev, see the "Build" section.
190+
191+
This package works with Zig package manager introduces in Zig 0.11.
192+
Create a `build.zig.zon` file like this:
193+
194+
```zig
195+
.{
196+
.name = "my-project",
197+
.version = "0.0.0",
198+
.dependencies = .{
199+
.libxev = .{
200+
.url = "https://github.com/mitchellh/libxev/archive/<git-ref-here>.tar.gz",
201+
.hash = "12208070233b17de6be05e32af096a6760682b48598323234824def41789e993432c",
202+
},
203+
},
204+
}
205+
```
206+
207+
And in your `build.zig`:
208+
209+
```zig
210+
const xev = b.dependency("libxev", .{ .target = target, .optimize = optimize });
211+
exe.addModule("xev", xev.module("xev"));
212+
```
213+
186214
## Documentation
187215

188216
🚧 Documentation is a work-in-progress. 🚧

build.zig

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,12 @@ const std = @import("std");
22
const LibExeObjStep = std.build.LibExeObjStep;
33
const ScdocStep = @import("src/build/ScdocStep.zig");
44

5-
/// DEPRECATED: This is the old std.build.Pkg for older versions of Zig.
6-
/// I won't keep this around too long but there is no harm in exposing it
7-
/// for now since our code works with older versions just fine (for now).
8-
pub const pkg = std.build.Pkg{
9-
.name = "xev",
10-
.source = .{ .path = thisDir() ++ "/src/main.zig" },
11-
};
12-
13-
/// Returns the module for libxev. The recommended approach is to depend
14-
/// on libxev in your build.zig.zon file, then use
15-
/// `b.dependency("libxev").module("xev")`. But if you're not using
16-
/// a build.zig.zon yet this will work.
17-
pub fn module(b: *std.Build) *std.Build.Module {
18-
return b.createModule(.{
19-
.source_file = .{ .path = (comptime thisDir()) ++ "/src/main.zig" },
20-
});
21-
}
22-
235
pub fn build(b: *std.Build) !void {
24-
// Modules available to downstream dependencies
25-
_ = b.addModule("xev", .{
26-
.source_file = .{ .path = (comptime thisDir()) ++ "/src/main.zig" },
27-
});
28-
296
const target = b.standardTargetOptions(.{});
307
const optimize = b.standardOptimizeOption(.{});
318

9+
_ = b.addModule("xev", .{ .source_file = .{ .path = "src/main.zig" } });
10+
3211
const man_pages = b.option(
3312
bool,
3413
"man-pages",
@@ -111,8 +90,11 @@ pub fn build(b: *std.Build) !void {
11190
.optimize = optimize,
11291
});
11392
static_binding_test.linkLibC();
114-
static_binding_test.addIncludePath("include");
115-
static_binding_test.addCSourceFile("examples/_basic.c", &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99", "-D_POSIX_C_SOURCE=199309L" });
93+
static_binding_test.addIncludePath(.{ .path = "include" });
94+
static_binding_test.addCSourceFile(.{
95+
.file = .{ .path = "examples/_basic.c" },
96+
.flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99", "-D_POSIX_C_SOURCE=199309L" },
97+
});
11698
static_binding_test.linkLibrary(static_lib);
11799
if (test_install) b.installArtifact(static_binding_test);
118100

@@ -145,8 +127,11 @@ pub fn build(b: *std.Build) !void {
145127
.optimize = optimize,
146128
});
147129
dynamic_binding_test.linkLibC();
148-
dynamic_binding_test.addIncludePath("include");
149-
dynamic_binding_test.addCSourceFile("examples/_basic.c", &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" });
130+
dynamic_binding_test.addIncludePath(.{ .path = "include" });
131+
dynamic_binding_test.addCSourceFile(.{
132+
.file = .{ .path = "examples/_basic.c" },
133+
.flags = &[_][]const u8{ "-Wall", "-Wextra", "-pedantic", "-std=c99" },
134+
});
150135
dynamic_binding_test.linkLibrary(dynamic_lib);
151136
if (test_install) b.installArtifact(dynamic_binding_test);
152137

@@ -239,9 +224,13 @@ fn benchTargets(
239224
.target = target,
240225
.optimize = .ReleaseFast, // benchmarks are always release fast
241226
});
242-
c_exe.addModule("xev", module(b));
243-
c_exe.override_dest_dir = std.Build.InstallDir{ .custom = "bench" };
244-
if (install) b.installArtifact(c_exe);
227+
c_exe.addModule("xev", b.modules.get("xev").?);
228+
if (install) {
229+
const install_step = b.addInstallArtifact(c_exe, .{
230+
.dest_dir = .{ .override = .{ .custom = "bench" } },
231+
});
232+
b.getInstallStep().dependOn(&install_step.step);
233+
}
245234

246235
// Store the mapping
247236
try map.put(try b.allocator.dupe(u8, name), c_exe);
@@ -293,9 +282,13 @@ fn exampleTargets(
293282
.target = target,
294283
.optimize = optimize,
295284
});
296-
c_exe.addModule("xev", module(b));
297-
c_exe.override_dest_dir = std.Build.InstallDir{ .custom = "example" };
298-
if (install) b.installArtifact(c_exe);
285+
c_exe.addModule("xev", b.modules.get("xev").?);
286+
if (install) {
287+
const install_step = b.addInstallArtifact(c_exe, .{
288+
.dest_dir = .{ .override = .{ .custom = "example" } },
289+
});
290+
b.getInstallStep().dependOn(&install_step.step);
291+
}
299292
} else {
300293
const c_lib = c_lib_ orelse return error.UnsupportedPlatform;
301294
const c_exe = b.addExecutable(.{
@@ -304,17 +297,24 @@ fn exampleTargets(
304297
.optimize = optimize,
305298
});
306299
c_exe.linkLibC();
307-
c_exe.addIncludePath("include");
308-
c_exe.addCSourceFile(path, &[_][]const u8{
309-
"-Wall",
310-
"-Wextra",
311-
"-pedantic",
312-
"-std=c99",
313-
"-D_POSIX_C_SOURCE=199309L",
300+
c_exe.addIncludePath(.{ .path = "include" });
301+
c_exe.addCSourceFile(.{
302+
.file = .{ .path = path },
303+
.flags = &[_][]const u8{
304+
"-Wall",
305+
"-Wextra",
306+
"-pedantic",
307+
"-std=c99",
308+
"-D_POSIX_C_SOURCE=199309L",
309+
},
314310
});
315311
c_exe.linkLibrary(c_lib);
316-
c_exe.override_dest_dir = std.Build.InstallDir{ .custom = "example" };
317-
if (install) b.installArtifact(c_exe);
312+
if (install) {
313+
const install_step = b.addInstallArtifact(c_exe, .{
314+
.dest_dir = .{ .override = .{ .custom = "example" } },
315+
});
316+
b.getInstallStep().dependOn(&install_step.step);
317+
}
318318
}
319319

320320
// If we have specified a specific name, only install that one.

build.zig.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.{
2+
.name = "libxev",
3+
.version = "0.0.0",
4+
}

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)