Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -12,6 +12,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 @@ -66,6 +103,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
23 changes: 1 addition & 22 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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 @@ -3254,24 +3254,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