feat: build.zig can now install the plugin; removed justfile

This commit is contained in:
LordMZTE 2022-08-26 01:38:02 +02:00
parent bcb37654c4
commit 654c3690e7
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 42 additions and 17 deletions

View file

@ -1,7 +1,7 @@
const std = @import("std");
const pkgs = @import("deps.zig").pkgs;
pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.build.Builder) !void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
@ -16,11 +16,49 @@ pub fn build(b: *std.build.Builder) void {
pkgs.addAllTo(lib);
lib.install();
const main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
b.getInstallStep().dependOn(&(try InstallStep.init(b, lib)).step);
}
const InstallStep = struct {
builder: *std.build.Builder,
step: std.build.Step,
lib: *std.build.LibExeObjStep,
pub fn init(builder: *std.build.Builder, lib: *std.build.LibExeObjStep) !*InstallStep {
const self = try builder.allocator.create(InstallStep);
self.* = .{
.builder = builder,
.lib = lib,
.step = std.build.Step.init(.custom, "install", builder.allocator, make),
};
self.step.dependOn(&lib.step);
return self;
}
fn make(step: *std.build.Step) anyerror!void {
const self = @fieldParentPtr(InstallStep, "step", step);
const plugin_install_dir = std.build.InstallDir{
.custom = "share/zellij/plugins",
};
const plugin_basename = "compact-status.wasm";
const dest_path = self.builder.getInstallPath(
plugin_install_dir,
plugin_basename,
);
try self.builder.updateFile(
self.lib.getOutputSource().getPath(self.builder),
dest_path,
);
// FIXME: the uninstall step doesn't do anything, despite this
self.builder.pushInstalledFile(plugin_install_dir, plugin_basename);
}
};

View file

@ -1,13 +0,0 @@
release:
gyro build -Drelease-fast
run: release
zellij --layout-path plugin.yaml
install: release
cp -f \
zig-out/lib/zellij-compact-status.wasm \
~/.local/share/zellij/plugins/compact-status.wasm
uninstall:
rm ~/.local/share/zellij/plugins/compact-status.wasm

View file

@ -17,6 +17,6 @@ template:
Fixed: 1
run:
plugin:
location: "file:zig-out/lib/zellij-compact-status.wasm"
location: "file:zig-out/share/zellij/plugins/compact-status.wasm"
tabs:
- direction: Vertical