Skip to content

Commit 8f4401b

Browse files
authored
Fix the missing examples dir bug (#10)
1 parent 8de383b commit 8f4401b

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

build.zig

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,40 @@ pub fn build(b: *std.Build) void {
6262

6363
// --- Example Setup ---
6464
const examples_path = "examples";
65-
var examples_dir = fs.cwd().openDir(examples_path, .{ .iterate = true }) catch @panic("Can't open 'examples' directory");
66-
defer examples_dir.close();
67-
68-
var dir_iter = examples_dir.iterate();
69-
while (dir_iter.next() catch @panic("Failed to iterate examples")) |entry| {
70-
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;
71-
72-
const exe_name = fs.path.stem(entry.name);
73-
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });
74-
75-
const exe_module = b.createModule(.{
76-
.root_source_file = b.path(exe_path),
77-
.target = target,
78-
.optimize = optimize,
79-
});
80-
exe_module.addImport("chilli", lib_module);
81-
82-
const exe = b.addExecutable(.{
83-
.name = exe_name,
84-
.root_module = exe_module,
85-
});
86-
b.installArtifact(exe);
87-
88-
const run_cmd = b.addRunArtifact(exe);
89-
const run_step_name = b.fmt("run-{s}", .{exe_name});
90-
const run_step_desc = b.fmt("Run the {s} example", .{exe_name});
91-
const run_step = b.step(run_step_name, run_step_desc);
92-
run_step.dependOn(&run_cmd.step);
65+
examples_blk: {
66+
// If the examples directory isn't present (common when used as a dependency),
67+
// skip setting up example artifacts instead of panicking.
68+
var examples_dir = fs.cwd().openDir(examples_path, .{ .iterate = true }) catch |err| {
69+
if (err == error.FileNotFound or err == error.NotDir) break :examples_blk;
70+
@panic("Can't open 'examples' directory");
71+
};
72+
defer examples_dir.close();
73+
74+
var dir_iter = examples_dir.iterate();
75+
while (dir_iter.next() catch @panic("Failed to iterate examples")) |entry| {
76+
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;
77+
78+
const exe_name = fs.path.stem(entry.name);
79+
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });
80+
81+
const exe_module = b.createModule(.{
82+
.root_source_file = b.path(exe_path),
83+
.target = target,
84+
.optimize = optimize,
85+
});
86+
exe_module.addImport("chilli", lib_module);
87+
88+
const exe = b.addExecutable(.{
89+
.name = exe_name,
90+
.root_module = exe_module,
91+
});
92+
b.installArtifact(exe);
93+
94+
const run_cmd = b.addRunArtifact(exe);
95+
const run_step_name = b.fmt("run-{s}", .{exe_name});
96+
const run_step_desc = b.fmt("Run the {s} example", .{exe_name});
97+
const run_step = b.step(run_step_name, run_step_desc);
98+
run_step.dependOn(&run_cmd.step);
99+
}
93100
}
94101
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .chilli,
3-
.version = "0.2.0",
3+
.version = "0.2.1",
44
.fingerprint = 0x6c259741ae4f5f73, // Changing this has security and trust implications.
55
.minimum_zig_version = "0.15.1",
66
.paths = .{

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
name = "chilli"
33
version = "0.1.0"
44
description = "Python environment for Chilli"
5-
readme = "README.md"
6-
license = { text = "MIT" }
7-
authors = [
8-
{ name = "Hassan Abedi", email = "[email protected]" }
9-
]
105

116
requires-python = ">=3.10,<4.0"
127
dependencies = [

0 commit comments

Comments
 (0)