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", .{});
|
mod.linkSystemLibrary("gcc_s", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
var threaded: std.Io.Threaded = .init_single_threaded;
|
if (b.pkg_hash.len == 0) {
|
||||||
const io = threaded.io();
|
var threaded: std.Io.Threaded = .init_single_threaded;
|
||||||
|
const io = threaded.io();
|
||||||
|
|
||||||
var buf: [1024]u8 = undefined;
|
var buf: [1024]u8 = undefined;
|
||||||
const exemples = try std.Io.Dir.cwd().openDir(io, "examples", .{ .access_sub_paths = false, .iterate = true });
|
const exemples = try std.Io.Dir.cwd().openDir(io, "examples", .{ .access_sub_paths = false, .iterate = true });
|
||||||
var iter = exemples.iterate();
|
var iter = exemples.iterate();
|
||||||
while (try iter.next(io)) |entry| {
|
while (try iter.next(io)) |entry| {
|
||||||
if (entry.kind != .file) continue;
|
if (entry.kind != .file) continue;
|
||||||
if (!std.mem.eql(u8, entry.name[entry.name.len - 4 ..], ".zig")) continue;
|
if (!std.mem.eql(u8, entry.name[entry.name.len - 4 ..], ".zig")) continue;
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = entry.name[0 .. entry.name.len - 4],
|
.name = entry.name[0 .. entry.name.len - 4],
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path(try std.fmt.bufPrint(&buf, "examples/{s}", .{entry.name})),
|
.root_source_file = b.path(try std.fmt.bufPrint(&buf, "examples/{s}", .{entry.name})),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.imports = &.{},
|
.imports = &.{},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
exe.root_module.addImport("gpu", mod);
|
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_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);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user