Skip to content

Commit

Permalink
add initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
Epikest authored Mar 24, 2022
1 parent d05bcc2 commit dc641e1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zig-cache/
zig-out/
build/
build-*/
docgen_tmp/
.vscode/
33 changes: 33 additions & 0 deletions build.zig
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);
}
42 changes: 42 additions & 0 deletions src/$.zig
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;
};
}

0 comments on commit dc641e1

Please sign in to comment.