Skip to content

Commit 1a85b6c

Browse files
committed
reorganize everything
1 parent 718640f commit 1a85b6c

5 files changed

Lines changed: 613 additions & 23 deletions

File tree

build.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ pub fn build(b: *Build) !void {
6565
break :blk out_file;
6666
};
6767

68+
const newpass1_out_dir = blk: {
69+
const exe = b.addExecutable(.{
70+
.name = "newpass1",
71+
.root_source_file = b.path("src/newpass1.zig"),
72+
.optimize = optimize,
73+
.target = b.host,
74+
});
75+
const run = b.addRunArtifact(exe);
76+
run.addDirectoryArg(win32json_dep.path(""));
77+
const out_dir = run.addOutputDirectoryArg("newpass1");
78+
b.step("newpass1", "Reorganize metadata by DLL").dependOn(&run.step);
79+
break :blk out_dir;
80+
};
81+
_ = newpass1_out_dir;
82+
6883
const gen_out_dir = blk: {
6984
const exe = b.addExecutable(.{
7085
.name = "genzig",

src/common.zig

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ pub fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
1212
std.process.exit(0xff);
1313
}
1414

15+
const NativeType = enum {
16+
Boolean,
17+
SByte,
18+
Byte,
19+
Int16,
20+
UInt16,
21+
Int32,
22+
UInt32,
23+
Int64,
24+
UInt64,
25+
Char,
26+
Single,
27+
Double,
28+
String,
29+
IntPtr,
30+
UIntPtr,
31+
Guid,
32+
};
33+
pub const native_type_map = std.StaticStringMap(NativeType).initComptime(.{
34+
.{ "Boolean", .Boolean },
35+
.{ "SByte", .SByte },
36+
.{ "Byte", .Byte },
37+
.{ "Int16", .Int16 },
38+
.{ "UInt16", .UInt16 },
39+
.{ "Int32", .Int32 },
40+
.{ "UInt32", .UInt32 },
41+
.{ "Int64", .Int64 },
42+
.{ "UInt64", .UInt64 },
43+
.{ "Char", .Char },
44+
.{ "Single", .Single },
45+
.{ "Double", .Double },
46+
.{ "String", .String },
47+
.{ "IntPtr", .IntPtr },
48+
.{ "UIntPtr", .UIntPtr },
49+
.{ "Guid", .Guid },
50+
});
51+
1552
pub fn getcwd(a: std.mem.Allocator) ![]u8 {
1653
var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
1754
const path = try std.os.getcwd(&path_buf);
@@ -66,6 +103,27 @@ pub fn formatSliceT(comptime T: type, comptime spec: []const u8, slice: []const
66103
// return .{ .slice = slice };
67104
//}
68105

106+
pub fn cleanDir(dir: std.fs.Dir, sub_path: []const u8) !void {
107+
std.log.info("cleandir '{s}'", .{sub_path});
108+
try dir.deleteTree(sub_path);
109+
const MAX_ATTEMPTS = 30;
110+
var attempt: u32 = 1;
111+
while (true) : (attempt += 1) {
112+
if (attempt > MAX_ATTEMPTS)
113+
fatal("failed to delete '{s}' after {} attempts", .{ sub_path, MAX_ATTEMPTS });
114+
115+
// ERROR: windows.OpenFile is not handling error.Unexpected NTSTATUS=0xc0000056
116+
dir.makeDir(sub_path) catch |e| switch (e) {
117+
else => {
118+
std.debug.print("[DEBUG] makedir failed with {}\n", .{e});
119+
//std.process.exit(0xff);
120+
continue;
121+
},
122+
};
123+
break;
124+
}
125+
}
126+
69127
pub fn jsonPanic() noreturn {
70128
@panic("an assumption about the json format was violated");
71129
}

src/genzig.zig

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub fn main() !u8 {
292292
// no need to free
293293
try readComOverloads(&global_com_overloads, com_overloads_filename);
294294

295-
try cleanDir(std.fs.cwd(), zigwin32_out_path);
295+
try common.cleanDir(std.fs.cwd(), zigwin32_out_path);
296296
var out_dir = try std.fs.cwd().openDir(zigwin32_out_path, .{});
297297
defer out_dir.close();
298298
try out_dir.makeDir("win32");
@@ -3254,24 +3254,3 @@ fn removeCr(comptime s: []const u8) [withoutCrLen(s):0]u8 {
32543254
return without_cr;
32553255
}
32563256
}
3257-
3258-
fn cleanDir(dir: std.fs.Dir, sub_path: []const u8) !void {
3259-
std.log.info("cleandir '{s}'", .{sub_path});
3260-
try dir.deleteTree(sub_path);
3261-
const MAX_ATTEMPTS = 30;
3262-
var attempt: u32 = 1;
3263-
while (true) : (attempt += 1) {
3264-
if (attempt > MAX_ATTEMPTS)
3265-
fatal("failed to delete '{s}' after {} attempts", .{ sub_path, MAX_ATTEMPTS });
3266-
3267-
// ERROR: windows.OpenFile is not handling error.Unexpected NTSTATUS=0xc0000056
3268-
dir.makeDir(sub_path) catch |e| switch (e) {
3269-
else => {
3270-
std.debug.print("[DEBUG] makedir failed with {}\n", .{e});
3271-
//std.process.exit(0xff);
3272-
continue;
3273-
},
3274-
};
3275-
break;
3276-
}
3277-
}

0 commit comments

Comments
 (0)