Skip to content
Merged
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
63 changes: 35 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,40 @@ pub fn build(b: *std.Build) void {

// --- Example Setup ---
const examples_path = "examples";
var examples_dir = fs.cwd().openDir(examples_path, .{ .iterate = true }) catch @panic("Can't open 'examples' directory");
defer examples_dir.close();

var dir_iter = examples_dir.iterate();
while (dir_iter.next() catch @panic("Failed to iterate examples")) |entry| {
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;

const exe_name = fs.path.stem(entry.name);
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });

const exe_module = b.createModule(.{
.root_source_file = b.path(exe_path),
.target = target,
.optimize = optimize,
});
exe_module.addImport("chilli", lib_module);

const exe = b.addExecutable(.{
.name = exe_name,
.root_module = exe_module,
});
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
const run_step_name = b.fmt("run-{s}", .{exe_name});
const run_step_desc = b.fmt("Run the {s} example", .{exe_name});
const run_step = b.step(run_step_name, run_step_desc);
run_step.dependOn(&run_cmd.step);
examples_blk: {
// If the examples directory isn't present (common when used as a dependency),
// skip setting up example artifacts instead of panicking.
var examples_dir = fs.cwd().openDir(examples_path, .{ .iterate = true }) catch |err| {
if (err == error.FileNotFound or err == error.NotDir) break :examples_blk;
@panic("Can't open 'examples' directory");
};
defer examples_dir.close();

var dir_iter = examples_dir.iterate();
while (dir_iter.next() catch @panic("Failed to iterate examples")) |entry| {
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;

const exe_name = fs.path.stem(entry.name);
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });

const exe_module = b.createModule(.{
.root_source_file = b.path(exe_path),
.target = target,
.optimize = optimize,
});
exe_module.addImport("chilli", lib_module);

const exe = b.addExecutable(.{
.name = exe_name,
.root_module = exe_module,
});
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
const run_step_name = b.fmt("run-{s}", .{exe_name});
const run_step_desc = b.fmt("Run the {s} example", .{exe_name});
const run_step = b.step(run_step_name, run_step_desc);
run_step.dependOn(&run_cmd.step);
}
}
}
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .chilli,
.version = "0.2.0",
.version = "0.2.1",
.fingerprint = 0x6c259741ae4f5f73, // Changing this has security and trust implications.
.minimum_zig_version = "0.15.1",
.paths = .{
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
name = "chilli"
version = "0.1.0"
description = "Python environment for Chilli"
readme = "README.md"
license = { text = "MIT" }
authors = [
{ name = "Hassan Abedi", email = "hassan.abedi.t@gmail.com" }
]

requires-python = ">=3.10,<4.0"
dependencies = [
Expand Down
Loading