Compare commits
4 Commits
70c6cea591
...
074db7f4f6
Author | SHA1 | Date | |
---|---|---|---|
074db7f4f6 | |||
b77a1f59c2 | |||
03a4404a17 | |||
6e1199afa9 |
@ -1,11 +1,11 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const target: std.zig.CrossTarget = b.standardTargetOptions(.{});
|
const target: std.Build.ResolvedTarget = b.standardTargetOptions(.{});
|
||||||
const optimize: std.builtin.Mode = b.standardOptimizeOption(.{});
|
const optimize: std.builtin.Mode = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const noclip = b.addModule("noclip", .{
|
const noclip = b.addModule("noclip", .{
|
||||||
.source_file = .{ .path = "source/noclip.zig" },
|
.root_source_file = .{ .path = "source/noclip.zig" },
|
||||||
});
|
});
|
||||||
|
|
||||||
demo(b, noclip, target, optimize);
|
demo(b, noclip, target, optimize);
|
||||||
@ -24,7 +24,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
fn demo(
|
fn demo(
|
||||||
b: *std.Build,
|
b: *std.Build,
|
||||||
noclip: *std.Build.Module,
|
noclip: *std.Build.Module,
|
||||||
target: std.zig.CrossTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.Mode,
|
optimize: std.builtin.Mode,
|
||||||
) void {
|
) void {
|
||||||
const demo_step = b.step("demo", "Build and install CLI demo program");
|
const demo_step = b.step("demo", "Build and install CLI demo program");
|
||||||
@ -35,7 +35,7 @@ fn demo(
|
|||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
exe.addModule("noclip", noclip);
|
exe.root_module.addImport("noclip", noclip);
|
||||||
const install_demo = b.addInstallArtifact(exe, .{});
|
const install_demo = b.addInstallArtifact(exe, .{});
|
||||||
|
|
||||||
demo_step.dependOn(&install_demo.step);
|
demo_step.dependOn(&install_demo.step);
|
||||||
|
11
build.zig.zon
Normal file
11
build.zig.zon
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
.{
|
||||||
|
.name = "NOCLIP",
|
||||||
|
.version = "0.1.0-pre",
|
||||||
|
.dependencies = .{},
|
||||||
|
.paths = .{
|
||||||
|
"source",
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
|
"license",
|
||||||
|
},
|
||||||
|
}
|
@ -372,7 +372,9 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
// global tags and env_vars would conflict, which is less common.
|
// global tags and env_vars would conflict, which is less common.
|
||||||
if (param.short_tag) |short|
|
if (param.short_tag) |short|
|
||||||
tag_fields = tag_fields ++ &[_]StructField{.{
|
tag_fields = tag_fields ++ &[_]StructField{.{
|
||||||
.name = short,
|
// this goofy construct coerces the comptime []const u8 to
|
||||||
|
// [:0]const u8.
|
||||||
|
.name = short ++ "",
|
||||||
.type = void,
|
.type = void,
|
||||||
.default_value = null,
|
.default_value = null,
|
||||||
.is_comptime = false,
|
.is_comptime = false,
|
||||||
@ -381,7 +383,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
|
|
||||||
if (param.long_tag) |long|
|
if (param.long_tag) |long|
|
||||||
tag_fields = tag_fields ++ &[_]StructField{.{
|
tag_fields = tag_fields ++ &[_]StructField{.{
|
||||||
.name = long,
|
.name = long ++ "",
|
||||||
.type = void,
|
.type = void,
|
||||||
.default_value = null,
|
.default_value = null,
|
||||||
.is_comptime = false,
|
.is_comptime = false,
|
||||||
@ -390,7 +392,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
|
|
||||||
if (param.env_var) |env_var|
|
if (param.env_var) |env_var|
|
||||||
env_var_fields = env_var_fields ++ &[_]StructField{.{
|
env_var_fields = env_var_fields ++ &[_]StructField{.{
|
||||||
.name = env_var,
|
.name = env_var ++ "",
|
||||||
.type = void,
|
.type = void,
|
||||||
.default_value = null,
|
.default_value = null,
|
||||||
.is_comptime = false,
|
.is_comptime = false,
|
||||||
@ -435,7 +437,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
const default = if (param.default) |def| &@as(FieldType, def) else @as(?*const anyopaque, null);
|
const default = if (param.default) |def| &@as(FieldType, def) else @as(?*const anyopaque, null);
|
||||||
|
|
||||||
fields = fields ++ &[_]StructField{.{
|
fields = fields ++ &[_]StructField{.{
|
||||||
.name = param.name,
|
.name = param.name ++ "",
|
||||||
.type = FieldType,
|
.type = FieldType,
|
||||||
.default_value = @ptrCast(default),
|
.default_value = @ptrCast(default),
|
||||||
.is_comptime = false,
|
.is_comptime = false,
|
||||||
@ -505,7 +507,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
?PType.G.IntermediateType();
|
?PType.G.IntermediateType();
|
||||||
|
|
||||||
fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{
|
fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{
|
||||||
.name = param.name,
|
.name = param.name ++ "",
|
||||||
.type = FieldType,
|
.type = FieldType,
|
||||||
.default_value = @ptrCast(&@as(
|
.default_value = @ptrCast(&@as(
|
||||||
FieldType,
|
FieldType,
|
||||||
|
@ -210,7 +210,7 @@ pub fn MutatingZSplitter(comptime T: type) type {
|
|||||||
pub fn copyStruct(comptime T: type, source: T, field_overrides: anytype) T {
|
pub fn copyStruct(comptime T: type, source: T, field_overrides: anytype) T {
|
||||||
var result: T = undefined;
|
var result: T = undefined;
|
||||||
|
|
||||||
comptime inline for (@typeInfo(@TypeOf(field_overrides)).Struct.fields) |field| {
|
comptime for (@typeInfo(@TypeOf(field_overrides)).Struct.fields) |field| {
|
||||||
if (!@hasField(T, field.name)) @compileError("override contains bad field" ++ field);
|
if (!@hasField(T, field.name)) @compileError("override contains bad field" ++ field);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -254,9 +254,8 @@ pub const TupleBuilder = struct {
|
|||||||
comptime {
|
comptime {
|
||||||
var fields: [self.types.len]StructField = undefined;
|
var fields: [self.types.len]StructField = undefined;
|
||||||
for (self.types, 0..) |Type, idx| {
|
for (self.types, 0..) |Type, idx| {
|
||||||
var num_buf: [128]u8 = undefined;
|
|
||||||
fields[idx] = .{
|
fields[idx] = .{
|
||||||
.name = std.fmt.bufPrint(&num_buf, "{d}", .{idx}) catch @compileError("failed to write field"),
|
.name = std.fmt.comptimePrint("{d}", .{idx}),
|
||||||
.type = Type,
|
.type = Type,
|
||||||
.default_value = null,
|
.default_value = null,
|
||||||
// TODO: is this the right thing to do?
|
// TODO: is this the right thing to do?
|
||||||
|
@ -160,7 +160,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
|
|||||||
|
|
||||||
pub fn execute(self: *@This(), context: UserContext) anyerror!void {
|
pub fn execute(self: *@This(), context: UserContext) anyerror!void {
|
||||||
const args = try std.process.argsAlloc(self.allocator);
|
const args = try std.process.argsAlloc(self.allocator);
|
||||||
var env = try std.process.getEnvMap(self.allocator);
|
const env = try std.process.getEnvMap(self.allocator);
|
||||||
|
|
||||||
if (args.len < 1) return ParseError.EmptyArgs;
|
if (args.len < 1) return ParseError.EmptyArgs;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user