-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
zig-cache/ | ||
zig-out/ | ||
build/ | ||
build-*/ | ||
docgen_tmp/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.build.Builder) void { | ||
// Standard target options allows the person running `zig build` to choose | ||
// what target to build for. Here we do not override the defaults, which | ||
// means any target is allowed, and the default is native. Other options | ||
// for restricting supported target set are available. | ||
const target = b.standardTargetOptions(.{}); | ||
|
||
// Standard release options allow the person running `zig build` to select | ||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. | ||
const mode = b.standardReleaseOptions(); | ||
|
||
const exe = b.addExecutable("zig", "src/$.zig"); | ||
exe.setTarget(target); | ||
exe.setBuildMode(mode); | ||
exe.install(); | ||
|
||
const run_cmd = exe.run(); | ||
run_cmd.step.dependOn(b.getInstallStep()); | ||
if (b.args) |args| { | ||
run_cmd.addArgs(args); | ||
} | ||
|
||
const run_step = b.step("run", "Run the app"); | ||
run_step.dependOn(&run_cmd.step); | ||
|
||
const exe_tests = b.addTest("src/$.zig"); | ||
exe_tests.setBuildMode(mode); | ||
|
||
const test_step = b.step("test", "Run unit tests"); | ||
test_step.dependOn(&exe_tests.step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const std = @import("std"); | ||
const string = []const u8; | ||
|
||
const shell = "bash"; // zsh, fish, etc. | ||
|
||
pub fn main() !void { | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer _ = gpa.deinit(); | ||
var allocator = gpa.allocator(); | ||
|
||
var iterator = try std.process.argsWithAllocator(allocator); | ||
defer iterator.deinit(); | ||
|
||
_ = iterator.skip(); // Skip the program name | ||
var command: []const u8 = ""; | ||
var arena = std.heap.ArenaAllocator.init(allocator); | ||
defer arena.deinit(); | ||
var loopAllocator = arena.allocator(); | ||
while (iterator.next()) |next| { | ||
var t = std.mem.concat(loopAllocator, u8, &.{ command, " ", next }) catch { | ||
std.log.err("Failed to allocate the string", .{}); | ||
return; | ||
}; | ||
command = loopAllocator.dupe(u8, t) catch { | ||
std.log.err("Failed to copy the string", .{}); | ||
return; | ||
}; | ||
} | ||
command = std.mem.concat(loopAllocator, u8, &.{ command }) catch { | ||
std.log.err("Failed to allocate the string", .{}); | ||
return; | ||
}; | ||
var process = std.ChildProcess.init(&.{ "wsl", "-e", shell, "-li", "-c", command }, allocator) catch { | ||
std.log.err("Failed to start child process", .{}); | ||
return; | ||
}; | ||
defer process.deinit(); | ||
_ = process.spawnAndWait() catch { | ||
std.log.err("Failed to spawn the child process", .{}); | ||
return; | ||
}; | ||
} |