@@ -5,26 +5,13 @@ const paths = @import("paths.zig");
55
66const logger = std .log .scoped (.dll_proxy );
77
8- const dll_names : []const [:0 ]const u8 = &.{ "version" , "winhttp" };
9-
10- const DllName = blk : {
11- var fields : []const std.builtin.Type.EnumField = &.{};
12-
13- for (dll_names , 0.. ) | dll_name , i | {
14- fields = fields ++ .{std.builtin.Type.EnumField {
15- .name = dll_name ,
16- .value = i ,
17- }};
18- }
19-
20- break :blk @Type (.{ .@"enum" = .{
21- .fields = fields ,
22- .decls = &.{},
23- .tag_type = u8 ,
24- .is_exhaustive = true ,
25- } });
8+ const DllName = enum {
9+ version ,
10+ winhttp ,
2611};
2712
13+ const dll_names = std .meta .fieldNames (DllName );
14+
2815fn proxyFunctions (comptime dll_name : []const u8 ) []const []const u8 {
2916 var buf : []const []const u8 = &.{};
3017
@@ -43,45 +30,27 @@ fn proxyFunctions(comptime dll_name: []const u8) []const []const u8 {
4330}
4431
4532const DllIncludes = blk : {
46- var fields : []const std.builtin.Type.StructField = &.{};
47-
48- for (std .meta .fieldNames (ProxyFuncAddrs )) | func_name | {
49- fields = fields ++ .{std.builtin.Type.StructField {
50- .name = func_name ,
51- .type = bool ,
52- .default_value_ptr = & false ,
53- .is_comptime = false ,
54- .alignment = 0 ,
55- }};
56- }
57-
58- break :blk @Type (.{ .@"struct" = .{
59- .layout = .@"packed" ,
60- .fields = fields ,
61- .decls = &.{},
62- .is_tuple = false ,
63- } });
33+ const field_names = std .meta .fieldNames (ProxyFuncAddrs );
34+ const field_types : [field_names .len ]type = @splat (bool );
35+ const field_attrs : [field_names .len ]std.builtin.Type.StructField.Attributes = @splat (.{
36+ .@"comptime" = false ,
37+ .@"align" = null ,
38+ .default_value_ptr = & false ,
39+ });
40+
41+ break :blk @Struct (.@"packed" , null , field_names , & field_types , & field_attrs );
6442};
6543
6644const EachDllIncludes = blk : {
67- var fields : []const std.builtin.Type.StructField = &.{};
68-
69- for (dll_names ) | dll_name | {
70- fields = fields ++ .{std.builtin.Type.StructField {
71- .name = dll_name ,
72- .type = DllIncludes ,
73- .default_value_ptr = & DllIncludes {},
74- .is_comptime = false ,
75- .alignment = @alignOf (DllIncludes ),
76- }};
77- }
78-
79- break :blk @Type (.{ .@"struct" = .{
80- .layout = .auto ,
81- .fields = fields ,
82- .decls = &.{},
83- .is_tuple = false ,
84- } });
45+ const field_types : [dll_names .len ]type = @splat (DllIncludes );
46+ const field_attrs : [dll_names .len ]std.builtin.Type.StructField.Attributes = @splat (.{
47+ .@"comptime" = false ,
48+ // .@"align" = @alignOf(DllIncludes),
49+ .@"align" = null ,
50+ .default_value_ptr = & DllIncludes {},
51+ });
52+
53+ break :blk @Struct (.auto , null , dll_names , & field_types , & field_attrs );
8554};
8655
8756const each_dll_includes = blk : {
@@ -90,8 +59,9 @@ const each_dll_includes = blk: {
9059 var includes : EachDllIncludes = .{};
9160
9261 for (dll_names ) | dll_name | {
62+ const dll_includes = &@field (includes , dll_name );
9363 for (proxyFunctions (dll_name )) | name | {
94- @field (@field ( includes , dll_name ) , name ) = true ;
64+ @field (dll_includes , name ) = true ;
9565 }
9666 }
9767
@@ -101,27 +71,23 @@ const each_dll_includes = blk: {
10171const ProxyFuncAddrs = blk : {
10272 @setEvalBranchQuota (8000 );
10373
104- var fields : []const std.builtin.Type.StructField = &.{};
74+ var field_names : []const [] const u8 = &.{};
10575
10676 for (dll_names ) | dll_name | {
107- for (proxyFunctions (dll_name )) | name | {
108- const FuncAddr = ? * fn () callconv (.c ) void ;
109- fields = fields ++ .{std.builtin.Type.StructField {
110- .name = @ptrCast (name ++ .{0 }),
111- .type = FuncAddr ,
112- .default_value_ptr = @ptrCast (&@as (FuncAddr , null )),
113- .is_comptime = false ,
114- .alignment = @alignOf (FuncAddr ),
115- }};
116- }
77+ field_names = field_names ++ proxyFunctions (dll_name );
11778 }
11879
119- break :blk @Type (.{ .@"struct" = .{
120- .layout = .auto ,
121- .fields = fields ,
122- .decls = &.{},
123- .is_tuple = false ,
124- } });
80+ const FuncAddr = ? * fn () callconv (.c ) void ;
81+
82+ const field_types : [field_names .len ]type = @splat (FuncAddr );
83+ const field_attrs : [field_names .len ]std.builtin.Type.StructField.Attributes = @splat (.{
84+ .@"comptime" = false ,
85+ // .@"align" = @alignOf(FuncAddr),
86+ .@"align" = null ,
87+ .default_value_ptr = @ptrCast (&@as (FuncAddr , null )),
88+ });
89+
90+ break :blk @Struct (.auto , null , field_names , & field_types , & field_attrs );
12591};
12692
12793var proxy_func_addrs : ProxyFuncAddrs = .{};
@@ -146,12 +112,9 @@ comptime {
146112}
147113
148114fn getDllIncludes (dll_name : DllName ) * const DllIncludes {
149- inline for (dll_names ) | other_dll_name | {
150- if (@field (DllName , other_dll_name ) == dll_name ) {
151- return &@field (each_dll_includes , other_dll_name );
152- }
153- }
154- unreachable ;
115+ return switch (dll_name ) {
116+ inline else = > | name | &@field (each_dll_includes , @tagName (name )),
117+ };
155118}
156119
157120fn logUnlinkableFunction (name : []const u8 , path : []const u16 ) void {
0 commit comments