Prevent building example when use as module
This commit is contained in:
parent
d503ce7dea
commit
e61c5f775d
46
build.zig
46
build.zig
@ -29,31 +29,33 @@ pub fn build(b: *std.Build) !void {
|
||||
mod.linkSystemLibrary("gcc_s", .{});
|
||||
}
|
||||
|
||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
if (b.pkg_hash.len == 0) {
|
||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
|
||||
var buf: [1024]u8 = undefined;
|
||||
const exemples = try std.Io.Dir.cwd().openDir(io, "examples", .{ .access_sub_paths = false, .iterate = true });
|
||||
var iter = exemples.iterate();
|
||||
while (try iter.next(io)) |entry| {
|
||||
if (entry.kind != .file) continue;
|
||||
if (!std.mem.eql(u8, entry.name[entry.name.len - 4 ..], ".zig")) continue;
|
||||
var buf: [1024]u8 = undefined;
|
||||
const exemples = try std.Io.Dir.cwd().openDir(io, "examples", .{ .access_sub_paths = false, .iterate = true });
|
||||
var iter = exemples.iterate();
|
||||
while (try iter.next(io)) |entry| {
|
||||
if (entry.kind != .file) continue;
|
||||
if (!std.mem.eql(u8, entry.name[entry.name.len - 4 ..], ".zig")) continue;
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = entry.name[0 .. entry.name.len - 4],
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path(try std.fmt.bufPrint(&buf, "examples/{s}", .{entry.name})),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{},
|
||||
}),
|
||||
});
|
||||
exe.root_module.addImport("gpu", mod);
|
||||
const exe = b.addExecutable(.{
|
||||
.name = entry.name[0 .. entry.name.len - 4],
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path(try std.fmt.bufPrint(&buf, "examples/{s}", .{entry.name})),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{},
|
||||
}),
|
||||
});
|
||||
exe.root_module.addImport("gpu", mod);
|
||||
|
||||
b.installArtifact(exe);
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_step = b.step(entry.name[0 .. entry.name.len - 4], try std.fmt.bufPrint(&buf, "Run {s} demo", .{entry.name}));
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
const run_step = b.step(entry.name[0 .. entry.name.len - 4], try std.fmt.bufPrint(&buf, "Run {s} demo", .{entry.name}));
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user