This commit is contained in:
Fabien Freling 2024-07-17 11:14:41 +02:00
parent aefe5fa327
commit 9c6bae6963
5 changed files with 37 additions and 8 deletions

View file

@ -30,19 +30,21 @@ pub fn build(b: *Build) !void {
} else {
try buildNative(b, target, optimize, dep_sokol, dep_cimgui);
}
try buildTui(b, target, optimize);
}
fn buildNative(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_sokol: *Dependency, dep_cimgui: *Dependency) !void {
const demo = b.addExecutable(.{
.name = "demo",
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/gui/main.zig"),
.target = target,
.optimize = optimize,
});
demo.root_module.addImport("sokol", dep_sokol.module("sokol"));
demo.root_module.addImport("cimgui", dep_cimgui.module("cimgui"));
b.installArtifact(demo);
b.step("run", "Run demo").dependOn(&b.addRunArtifact(demo).step);
b.step("run-gui", "Run demo").dependOn(&b.addRunArtifact(demo).step);
}
fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_sokol: *Dependency, dep_cimgui: *Dependency) !void {
@ -50,7 +52,7 @@ fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_soko
// needs to be linked in a separate build step with the Emscripten linker
const demo = b.addStaticLibrary(.{
.name = "demo",
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/gui/main.zig"),
.target = target,
.optimize = optimize,
});
@ -86,5 +88,17 @@ fn buildWasm(b: *Build, target: ResolvedTarget, optimize: OptimizeMode, dep_soko
// ...and a special run step to start the web build output via 'emrun'
const run = sokol.emRunStep(b, .{ .name = "demo", .emsdk = dep_emsdk });
run.step.dependOn(&link_step.step);
b.step("run", "Run demo").dependOn(&run.step);
b.step("run-gui", "Run demo").dependOn(&run.step);
}
fn buildTui(b: *Build, target: ResolvedTarget, optimize: OptimizeMode) !void {
const tui = b.addExecutable(.{
.name = "demo",
.root_source_file = b.path("src/tui/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(tui);
b.step("run-tui", "Run TUI").dependOn(&b.addRunArtifact(tui).step);
}

View file

@ -12,8 +12,10 @@
zls
];
buildInputs = [
alsa-lib
lldb
# GUI
alsa-lib
xorg.libX11
xorg.libXcursor
xorg.libXi

View file

@ -2,6 +2,8 @@ alias b := build
build:
zig build
alias r := run
run:
zig build run
gui:
zig build run-gui
tui:
zig build run-tui

11
src/tui/main.zig Normal file
View file

@ -0,0 +1,11 @@
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Can spawn process: {}\n", .{std.process.can_spawn});
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
var lldb_child = std.process.Child.init(&[_][]const u8{"lldb-vscode"}, alloc);
_ = try lldb_child.spawnAndWait();
}