Compare commits

...

4 Commits

Author SHA1 Message Date
074db7f4f6
build: update for zig-0.12.0-dev.2208+4debd4338
I may move this commit to a separate branch, since there are a variety
of improvements that I think I want to get applied to the
0.11.x-compatible codebase still. However, I have also not been
motivated to work on those fixes, since this codebase is kind of
crusty due to being the first thing I ever wrote in zig. Doing a
bigger rewrite might supply the motivation to make those improvements.
I will have to think about it. For now, I am going to focus elsewhere.
2024-01-15 22:45:59 -08:00
b77a1f59c2
command: coerce field names to null-terminated strings
ziglang/zig@a02bd81760 changed
builtin.StructField to necessitate this, but this should also be
backwards compatible since these should decay to plain slices just
fine.
2024-01-15 22:42:26 -08:00
03a4404a17
parser: stray var -> const
Surprised there wasn't more of this in here, to be honest.
2024-01-15 22:41:01 -08:00
6e1199afa9
meta: fix redundant qualifiers and improve tuple field generation 2024-01-15 22:40:26 -08:00
5 changed files with 25 additions and 13 deletions

View File

@ -1,11 +1,11 @@
const std = @import("std");
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 noclip = b.addModule("noclip", .{
.source_file = .{ .path = "source/noclip.zig" },
.root_source_file = .{ .path = "source/noclip.zig" },
});
demo(b, noclip, target, optimize);
@ -24,7 +24,7 @@ pub fn build(b: *std.Build) void {
fn demo(
b: *std.Build,
noclip: *std.Build.Module,
target: std.zig.CrossTarget,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
) void {
const demo_step = b.step("demo", "Build and install CLI demo program");
@ -35,7 +35,7 @@ fn demo(
.target = target,
.optimize = optimize,
});
exe.addModule("noclip", noclip);
exe.root_module.addImport("noclip", noclip);
const install_demo = b.addInstallArtifact(exe, .{});
demo_step.dependOn(&install_demo.step);

11
build.zig.zon Normal file
View File

@ -0,0 +1,11 @@
.{
.name = "NOCLIP",
.version = "0.1.0-pre",
.dependencies = .{},
.paths = .{
"source",
"build.zig",
"build.zig.zon",
"license",
},
}

View File

@ -372,7 +372,9 @@ pub fn CommandBuilder(comptime UserContext: type) type {
// global tags and env_vars would conflict, which is less common.
if (param.short_tag) |short|
tag_fields = tag_fields ++ &[_]StructField{.{
.name = short,
// this goofy construct coerces the comptime []const u8 to
// [:0]const u8.
.name = short ++ "",
.type = void,
.default_value = null,
.is_comptime = false,
@ -381,7 +383,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (param.long_tag) |long|
tag_fields = tag_fields ++ &[_]StructField{.{
.name = long,
.name = long ++ "",
.type = void,
.default_value = null,
.is_comptime = false,
@ -390,7 +392,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (param.env_var) |env_var|
env_var_fields = env_var_fields ++ &[_]StructField{.{
.name = env_var,
.name = env_var ++ "",
.type = void,
.default_value = null,
.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);
fields = fields ++ &[_]StructField{.{
.name = param.name,
.name = param.name ++ "",
.type = FieldType,
.default_value = @ptrCast(default),
.is_comptime = false,
@ -505,7 +507,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
?PType.G.IntermediateType();
fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{
.name = param.name,
.name = param.name ++ "",
.type = FieldType,
.default_value = @ptrCast(&@as(
FieldType,

View File

@ -210,7 +210,7 @@ pub fn MutatingZSplitter(comptime T: type) type {
pub fn copyStruct(comptime T: type, source: T, field_overrides: anytype) T {
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);
};
@ -254,9 +254,8 @@ pub const TupleBuilder = struct {
comptime {
var fields: [self.types.len]StructField = undefined;
for (self.types, 0..) |Type, idx| {
var num_buf: [128]u8 = undefined;
fields[idx] = .{
.name = std.fmt.bufPrint(&num_buf, "{d}", .{idx}) catch @compileError("failed to write field"),
.name = std.fmt.comptimePrint("{d}", .{idx}),
.type = Type,
.default_value = null,
// TODO: is this the right thing to do?

View File

@ -160,7 +160,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
pub fn execute(self: *@This(), context: UserContext) anyerror!void {
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;