Skip to content

Commit

Permalink
reorganize everything
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 committed Jul 19, 2024
1 parent 7f1ed24 commit fa02d00
Show file tree
Hide file tree
Showing 5 changed files with 615 additions and 59 deletions.
15 changes: 15 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ pub fn build(b: *Build) !void {
break :blk out_file;
};

const newpass1_out_dir = blk: {
const exe = b.addExecutable(.{
.name = "newpass1",
.root_source_file = b.path("src/newpass1.zig"),
.optimize = optimize,
.target = b.host,
});
const run = b.addRunArtifact(exe);
run.addDirectoryArg(win32json_dep.path(""));
const out_dir = run.addOutputDirectoryArg("newpass1");
b.step("newpass1", "Reorganize metadata by DLL").dependOn(&run.step);
break :blk out_dir;
};
_ = newpass1_out_dir;

const gen_out_dir = blk: {
const exe = b.addExecutable(.{
.name = "genzig",
Expand Down
58 changes: 58 additions & 0 deletions src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,43 @@ pub fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
std.process.exit(0xff);
}

const NativeType = enum {
Boolean,
SByte,
Byte,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
Char,
Single,
Double,
String,
IntPtr,
UIntPtr,
Guid,
};
pub const native_type_map = std.StaticStringMap(NativeType).initComptime(.{
.{ "Boolean", .Boolean },
.{ "SByte", .SByte },
.{ "Byte", .Byte },
.{ "Int16", .Int16 },
.{ "UInt16", .UInt16 },
.{ "Int32", .Int32 },
.{ "UInt32", .UInt32 },
.{ "Int64", .Int64 },
.{ "UInt64", .UInt64 },
.{ "Char", .Char },
.{ "Single", .Single },
.{ "Double", .Double },
.{ "String", .String },
.{ "IntPtr", .IntPtr },
.{ "UIntPtr", .UIntPtr },
.{ "Guid", .Guid },
});

pub fn getcwd(a: std.mem.Allocator) ![]u8 {
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const path = try std.os.getcwd(&path_buf);
Expand Down Expand Up @@ -61,6 +98,27 @@ pub fn formatSliceT(comptime T: type, comptime spec: []const u8, slice: []const
// return .{ .slice = slice };
//}

pub fn cleanDir(dir: std.fs.Dir, sub_path: []const u8) !void {
std.log.info("cleandir '{s}'", .{sub_path});
try dir.deleteTree(sub_path);
const MAX_ATTEMPTS = 30;
var attempt: u32 = 1;
while (true) : (attempt += 1) {
if (attempt > MAX_ATTEMPTS)
fatal("failed to delete '{s}' after {} attempts", .{ sub_path, MAX_ATTEMPTS });

// ERROR: windows.OpenFile is not handling error.Unexpected NTSTATUS=0xc0000056
dir.makeDir(sub_path) catch |e| switch (e) {
else => {
std.debug.print("[DEBUG] makedir failed with {}\n", .{e});
//std.process.exit(0xff);
continue;
},
};
break;
}
}

pub fn jsonPanic() noreturn {
@panic("an assumption about the json format was violated");
}
Expand Down
61 changes: 3 additions & 58 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -93,42 +93,8 @@ const pass1_type_kind_info = std.StaticStringMap(Pass1TypeKindCategory).initComp
.{ "FunctionPointer", .ptr },
});

const NativeType = enum {
Boolean,
SByte,
Byte,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
Char,
Single,
Double,
String,
IntPtr,
UIntPtr,
Guid,
};
const global_native_type_map = std.StaticStringMap(NativeType).initComptime(.{
.{ "Boolean", NativeType.Boolean },
.{ "SByte", NativeType.SByte },
.{ "Byte", NativeType.Byte },
.{ "Int16", NativeType.Int16 },
.{ "UInt16", NativeType.UInt16 },
.{ "Int32", NativeType.Int32 },
.{ "UInt32", NativeType.UInt32 },
.{ "Int64", NativeType.Int64 },
.{ "UInt64", NativeType.UInt64 },
.{ "Char", NativeType.Char },
.{ "Single", NativeType.Single },
.{ "Double", NativeType.Double },
.{ "String", NativeType.String },
.{ "IntPtr", NativeType.IntPtr },
.{ "UIntPtr", NativeType.UIntPtr },
.{ "Guid", NativeType.Guid },
});
const NativeType = common.NativeType;
const global_native_type_map = common.native_type_map;
fn nativeTypeToZigType(t: NativeType) []const u8 {
return switch (t) {
.Boolean => return "bool",
Expand Down Expand Up @@ -324,7 +290,7 @@ pub fn main() !u8 {
// no need to free
try readComOverloads(&global_com_overloads, com_overloads_filename);

try cleanDir(std.fs.cwd(), zigwin32_out_path);
try common.cleanDir(std.fs.cwd(), zigwin32_out_path);
var out_dir = try std.fs.cwd().openDir(zigwin32_out_path, .{});
defer out_dir.close();
try out_dir.makeDir("win32");
Expand Down Expand Up @@ -3401,24 +3367,3 @@ fn removeCr(comptime s: []const u8) [withoutCrLen(s):0]u8 {
return without_cr;
}
}

fn cleanDir(dir: std.fs.Dir, sub_path: []const u8) !void {
std.log.info("cleandir '{s}'", .{sub_path});
try dir.deleteTree(sub_path);
const MAX_ATTEMPTS = 30;
var attempt: u32 = 1;
while (true) : (attempt += 1) {
if (attempt > MAX_ATTEMPTS)
fatal("failed to delete '{s}' after {} attempts", .{ sub_path, MAX_ATTEMPTS });

// ERROR: windows.OpenFile is not handling error.Unexpected NTSTATUS=0xc0000056
dir.makeDir(sub_path) catch |e| switch (e) {
else => {
std.debug.print("[DEBUG] makedir failed with {}\n", .{e});
//std.process.exit(0xff);
continue;
},
};
break;
}
}
Loading

0 comments on commit fa02d00

Please sign in to comment.