Skip to content

Commit cc54293

Browse files
committed
Update Zig to 0.15.0-dev.1092+d772c0627
1 parent 3f24dfa commit cc54293

File tree

11 files changed

+50
-71
lines changed

11 files changed

+50
-71
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
version: 1.0
4242
- uses: mlugg/setup-zig@v1
4343
with:
44-
version: 0.15.0-dev.386+2e35fdd03
44+
version: 0.15.0-dev.1092+d772c0627
4545
- name: "Build"
4646
run: |
4747
zig build build-all -Doptimize=$OPTIMIZE

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
.fingerprint = 0x6002b2b610072fc5,
77

8-
.minimum_zig_version = "0.15.0-dev.386+2e35fdd03",
8+
.minimum_zig_version = "0.15.0-dev.1092+d772c0627",
99

1010
.dependencies = .{
1111
.plthook = .{

src/Config.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const std = @import("std");
44
const root = @import("root.zig");
55
const alloc = root.alloc;
66
const logger = root.logger;
7+
const fmtString = root.util.fmtString;
78
const os_char = root.util.os_char;
89

910
/// Path to a managed assembly to invoke.
@@ -61,10 +62,7 @@ inline fn getEnvBool(comptime key: []const u8) bool {
6162

6263
fn invalidEnvValue(key: []const u8, value: [:0]const os_char) noreturn {
6364
@branchHint(.cold);
64-
std.debug.panic("Invalid value for environment variable {s}: {s}", .{ key, switch (builtin.os.tag) {
65-
.windows => std.unicode.fmtUtf16Le(value),
66-
else => value,
67-
} });
65+
std.debug.panic("Invalid value for environment variable {s}: {f}", .{ key, fmtString(value) });
6866
}
6967

7068
fn getEnvBoolOs(key: EnvKey) bool {

src/bootstrap.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
6161
util.setEnv("DOORSTOP_MANAGED_FOLDER_DIR", norm_assembly_dir.str);
6262
}
6363

64-
logger.debug("Opening assembly: {}", .{util.fmtString(config.target_assembly.?)});
64+
logger.debug("Opening assembly: {f}", .{util.fmtString(config.target_assembly.?)});
6565

6666
const dll_path = util.narrow(true, true, config.target_assembly.?);
6767
defer dll_path.deinit();
@@ -70,7 +70,7 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
7070
var s = mono.ImageOpenFileStatus.ok;
7171
const image = mono.image_open_from_file_with_name(config.target_assembly.?, &s, 0, dll_path.str);
7272
if (s != .ok or image == null) {
73-
logger.err("Failed to open assembly: {s}. Got result: {}", .{ util.fmtString(config.target_assembly.?), s });
73+
logger.err("Failed to open assembly: {f}. Got result: {}", .{ util.fmtString(config.target_assembly.?), s });
7474
return;
7575
}
7676
break :blk image.?;
@@ -81,7 +81,7 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
8181
var s = mono.ImageOpenStatus.ok;
8282
_ = mono.addrs.assembly_load_from_full.?(image, dll_path.str, &s, 0);
8383
if (s != .ok) {
84-
logger.err("Failed to load assembly: {s}. Got result: {}", .{ util.fmtString(config.target_assembly.?), s });
84+
logger.err("Failed to load assembly: {f}. Got result: {}", .{ util.fmtString(config.target_assembly.?), s });
8585
return;
8686
}
8787

@@ -98,7 +98,7 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
9898
std.debug.panic("Method has {} parameters; expected 0", .{params});
9999
}
100100

101-
logger.debug("Invoking method {}", .{util.fmtAddress(method)});
101+
logger.debug("Invoking method {f}", .{util.fmtAddress(method)});
102102
var exc: ?*mono.Object = null;
103103
_ = mono.addrs.runtime_invoke.?(method, null, null, &exc);
104104
if (exc) |e| {
@@ -174,8 +174,8 @@ fn il2cpp_doorstop_bootstrap() void {
174174
@panic("CoreCLR paths not set");
175175
};
176176

177-
logger.debug("CoreCLR runtime path: {}", .{util.fmtString(clr_runtime_coreclr_path)});
178-
logger.debug("CoreCLR corlib dir: {}", .{util.fmtString(clr_corlib_dir)});
177+
logger.debug("CoreCLR runtime path: {f}", .{util.fmtString(clr_runtime_coreclr_path)});
178+
logger.debug("CoreCLR corlib dir: {f}", .{util.fmtString(clr_corlib_dir)});
179179

180180
if (!util.paths.exists(clr_runtime_coreclr_path, .file) or
181181
!util.paths.exists(clr_corlib_dir, .directory))
@@ -188,7 +188,7 @@ fn il2cpp_doorstop_bootstrap() void {
188188
.windows => std.os.windows.LoadLibraryW(clr_runtime_coreclr_path) catch @panic("Failed to load CoreCLR runtime"),
189189
else => std.c.dlopen(clr_runtime_coreclr_path, .{ .LAZY = true }) orelse @panic("Failed to load CoreCLR runtime"),
190190
};
191-
logger.debug("Loaded coreclr.dll: {}", .{util.fmtAddress(coreclr_module)});
191+
logger.debug("Loaded coreclr.dll: {f}", .{util.fmtAddress(coreclr_module)});
192192

193193
coreclr.load(coreclr_module);
194194

@@ -209,9 +209,9 @@ fn il2cpp_doorstop_bootstrap() void {
209209
const app_paths_env_n = util.narrow(true, true, app_paths_env);
210210
defer app_paths_env_n.deinit();
211211

212-
logger.debug("App path: {}", .{util.fmtString(app_path)});
213-
logger.debug("Target dir: {}", .{util.fmtString(target_dir)});
214-
logger.debug("Target name: {}", .{util.fmtString(target_name)});
212+
logger.debug("App path: {f}", .{util.fmtString(app_path)});
213+
logger.debug("Target dir: {f}", .{util.fmtString(target_dir)});
214+
logger.debug("Target name: {f}", .{util.fmtString(target_name)});
215215
logger.debug("APP_PATHS: {s}", .{app_paths_env_n.str});
216216

217217
const props = "APP_PATHS";
@@ -282,11 +282,11 @@ pub fn hook_mono_jit_parse_options(argc: c_int, argv: [*][*:0]u8) callconv(.c) v
282282
else => s,
283283
} else "127.0.0.1:10000";
284284

285-
debug_options = std.fmt.allocPrintZ(alloc, "--debugger-agent=transport=dt_socket,server=y,address={s}{s}{s}", .{
285+
debug_options = std.fmt.allocPrintSentinel(alloc, "--debugger-agent=transport=dt_socket,server=y,address={s}{s}{s}", .{
286286
mono_debug_address,
287287
if (config.mono_debug_suspend) "" else ",suspend=n",
288288
if (config.mono_debug_suspend or !mono_is_net35) "" else ",defer=y",
289-
}) catch @panic("Out of memory");
289+
}, 0) catch @panic("Out of memory");
290290
}
291291

292292
logger.debug("Debug options: {s}", .{debug_options.?});

src/debug/env.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ pub fn dumpProgramPath() void {
1010
var program_path_buf: util.paths.ProgramPathBuf = undefined;
1111
const app_path = program_path_buf.get();
1212
const app_dir = util.paths.getFolderName(util.os_char, app_path);
13-
logger.debug("Executable path: {}", .{util.fmtString(app_path)});
14-
logger.debug("Application dir: {}", .{util.fmtString(app_dir)});
13+
logger.debug("Executable path: {f}", .{util.fmtString(app_path)});
14+
logger.debug("Application dir: {f}", .{util.fmtString(app_dir)});
1515
}
1616

1717
pub fn dumpWorkingDir() void {
1818
const working_dir = util.paths.getWorkingDir() catch |e| std.debug.panic("Failed to determine current working directory path: {}", .{e});
1919
defer alloc.free(working_dir);
20-
logger.debug("Working dir: {}", .{util.fmtString(working_dir)});
20+
logger.debug("Working dir: {f}", .{util.fmtString(working_dir)});
2121
}
2222

2323
pub fn dumpDoorstopPath(module: if (builtin.os.tag == .windows) std.os.windows.HMODULE else void) void {
@@ -28,5 +28,5 @@ pub fn dumpDoorstopPath(module: if (builtin.os.tag == .windows) std.os.windows.H
2828
else => &dumpDoorstopPath,
2929
}).?;
3030

31-
logger.debug("Doorstop library path: {}", .{util.fmtString(doorstop_path)});
31+
logger.debug("Doorstop library path: {f}", .{util.fmtString(doorstop_path)});
3232
}

src/hooks.zig

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ fn hookBootConfigCommon() ?[*:0]const os_char {
2525
const program_path = program_path_buf.get();
2626
const app_folder = util.paths.getFolderName(u8, util.paths.getFolderName(u8, program_path));
2727

28-
break :blk std.fmt.allocPrintZ(
28+
break :blk std.fmt.allocPrintSentinel(
2929
alloc,
3030
"{s}/Resources/Data/boot.config",
3131
.{app_folder},
32+
0,
3233
) catch @panic("Out of memory");
3334
},
3435
else => blk: {
@@ -45,8 +46,8 @@ fn hookBootConfigCommon() ?[*:0]const os_char {
4546
defer alloc.free(path);
4647

4748
defaultBootConfig = util.file_identity.getFileIdentity(null, path) catch |e| {
48-
std.debug.panic("Failed to get identity of default boot.config file at \"{s}\": {}", .{
49-
if (builtin.os.tag == .windows) std.unicode.fmtUtf16Le(path) else path,
49+
std.debug.panic("Failed to get identity of default boot.config file at \"{f}\": {}", .{
50+
util.fmtString(path),
5051
e,
5152
});
5253
};
@@ -183,7 +184,7 @@ fn redirectInit(
183184
if (std.mem.eql(u8, name, args.name)) {
184185
if (!initialized) {
185186
initialized = true;
186-
logger.debug("Intercepted {s} from {}", .{ args.name, util.fmtAddress(handle) });
187+
logger.debug("Intercepted {s} from {f}", .{ args.name, util.fmtAddress(handle) });
187188
// the old code had the next two bits swapped on nix. Test and see if it matters.
188189
if (args.should_capture_mono_path) {
189190
// Resolve dlsym so that it can be passed to capture_mono_path.
@@ -197,7 +198,7 @@ fn redirectInit(
197198
const path = buf.get(switch (builtin.os.tag) {
198199
.windows => handle,
199200
else => std.c.dlsym(handle, name),
200-
}) orelse std.debug.panic("Failed to resolve path to module {}", .{util.fmtAddress(handle)});
201+
}) orelse std.debug.panic("Failed to resolve path to module {f}", .{util.fmtAddress(handle)});
201202
util.setEnv("DOORSTOP_MONO_LIB_PATH", path);
202203
}
203204
args.init_func(handle);
@@ -217,14 +218,14 @@ fn dlsym_hook(handle: util.Module(false), name_ptr: [*:0]const u8) callconv(if (
217218
// Documented that if the "HIWORD" is 0, the name_ptr actually specifies an
218219
// ordinal. On 64-bit, this seems to be implemented more like a cast,
219220
// checking if the upper 48 bits are 0 rather than just the upper 16.
220-
logger.debug("dlsym({}, {})", .{ util.fmtAddress(handle), ordinal });
221+
logger.debug("dlsym({f}, {})", .{ util.fmtAddress(handle), ordinal });
221222
return std.os.windows.kernel32.GetProcAddress(handle, name_ptr);
222223
}
223224
}
224225

225226
const name = std.mem.span(name_ptr);
226227

227-
logger.debug("dlsym({}, \"{s}\")", .{ util.fmtAddress(handle), name });
228+
logger.debug("dlsym({f}, \"{f}\")", .{ util.fmtAddress(handle), std.zig.fmtString(name) });
228229

229230
for ([_]RedirectInitArgs{
230231
.{ .name = "il2cpp_init", .init_func = &runtimes.il2cpp.load, .target = &bootstrap.init_il2cpp, .should_capture_mono_path = false },

src/runtimes/mono.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn image_open_from_file_with_name(
157157
.windows => blk1: {
158158
const cwd = std.fs.cwd();
159159
logger.debug("got cwd", .{});
160-
logger.debug("opening {}", .{std.unicode.fmtUtf16Le(path)});
160+
logger.debug("opening {f}", .{std.unicode.fmtUtf16Le(path)});
161161
const prefixed_path = std.os.windows.wToPrefixedFileW(cwd.fd, path) catch |e| break :blk1 e;
162162
break :blk1 cwd.openFileW(prefixed_path.span(), .{});
163163
},

src/util.zig

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,30 @@ pub fn empty(comptime T: type) *[0:0]T {
2626
pub const FmtAddress = struct {
2727
addr: usize,
2828

29-
pub fn format(
30-
self: @This(),
31-
comptime fmt: []const u8,
32-
_: std.fmt.FormatOptions,
33-
writer: anytype,
34-
) !void {
35-
if (fmt.len == 0) {
36-
return writer.print(std.fmt.comptimePrint("0x{{?x:0>{}}}", .{@sizeOf(*anyopaque) * 2}), .{self.addr});
37-
} else {
38-
@compileError("unknown format string: '" ++ fmt ++ "'");
39-
}
29+
pub fn format(self: @This(), writer: *std.io.Writer) !void {
30+
return writer.print(std.fmt.comptimePrint("0x{{x:0>{}}}", .{@sizeOf(*anyopaque) * 2}), .{self.addr});
4031
}
4132
};
4233

4334
pub fn fmtAddress(ptr: anytype) FmtAddress {
4435
return .{ .addr = @intFromPtr(ptr) };
4536
}
4637

47-
pub const FmtString = struct {
48-
str: []const os_char,
38+
pub fn FmtString(comptime char: type) type {
39+
return struct {
40+
str: []const char,
4941

50-
pub fn format(
51-
self: @This(),
52-
comptime fmt: []const u8,
53-
options: std.fmt.FormatOptions,
54-
writer: anytype,
55-
) !void {
56-
if (builtin.os.tag == .windows) {
57-
return std.unicode.fmtUtf16Le(self.str).format(fmt, options, writer);
58-
} else {
59-
if (comptime fmt.len == 0 or std.mem.eql(u8, fmt, "s")) {
60-
return writer.writeAll(self.str);
42+
pub fn format(self: @This(), writer: *std.io.Writer) !void {
43+
if (char == u16) {
44+
return std.unicode.fmtUtf16Le(self.str).format(writer);
6145
} else {
62-
@compileError("unknown format string: '" ++ fmt ++ "'");
46+
return writer.writeAll(self.str);
6347
}
6448
}
65-
}
66-
};
49+
};
50+
}
6751

68-
pub fn fmtString(str: []const os_char) FmtString {
52+
pub fn fmtString(str: []const os_char) FmtString(os_char) {
6953
return .{ .str = str };
7054
}
7155

src/util/logging.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ pub fn log(
1313
) void {
1414
const level_txt = comptime @tagName(message_level);
1515
const scope_txt = comptime @tagName(scope);
16-
const stderr = std.io.getStdErr().writer();
17-
var bw = std.io.bufferedWriter(stderr);
18-
const writer = bw.writer();
16+
var buf: [4096]u8 = undefined;
17+
var writer = std.fs.File.stderr().writer(&buf);
1918

2019
std.debug.lockStdErr();
2120
defer std.debug.unlockStdErr();
2221
nosuspend {
23-
writer.print(
22+
writer.interface.print(
2423
level_txt ++ " " ++ scope_txt ++ " " ++ format ++ "\n",
2524
args,
2625
) catch return;
27-
bw.flush() catch return;
26+
writer.interface.flush() catch return;
2827
}
2928
}

src/windows/hooks.zig

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const std = @import("std");
33
const root = @import("../root.zig");
44

55
const alloc = root.alloc;
6+
const util = root.util;
67
const os_char = root.util.os_char;
78

89
pub var stdout_handle: ?std.os.windows.HANDLE = null;
@@ -64,18 +65,14 @@ fn genCreateFileHook(comptime char: type, comptime real_fn: CreateFileFn(char))
6465
}
6566

6667
const id = root.util.file_identity.getFileIdentity(handle, &.{}) catch |e| {
67-
root.logger.err("Failed to get identity of file \"{s}\": {}", .{ switch (char) {
68-
u8 => lpFileName,
69-
u16 => std.unicode.fmtUtf16Le(std.mem.span(lpFileName)),
70-
else => @compileError("Unsupported char type " ++ @typeName(char)),
71-
}, e });
68+
root.logger.err("Failed to get identity of file \"{f}\": {}", .{ util.FmtString(char){ .str = std.mem.span(lpFileName) }, e });
7269
return handle;
7370
};
7471

7572
if (root.util.file_identity.are_same(id, root.hooks.defaultBootConfig)) {
7673
std.os.windows.CloseHandle(handle);
7774
const boot_config_override = root.config.boot_config_override.?;
78-
root.logger.debug("Overriding boot.config to \"{s}\"", .{std.unicode.fmtUtf16Le(boot_config_override)});
75+
root.logger.debug("Overriding boot.config to \"{f}\"", .{std.unicode.fmtUtf16Le(boot_config_override)});
7976
// caller can handle the error
8077
return std.os.windows.kernel32.CreateFileW(
8178
boot_config_override,

0 commit comments

Comments
 (0)