Skip to content

Commit dab6c19

Browse files
committed
fix zig 0.15.0-dev.1092 issues
1 parent a538924 commit dab6c19

File tree

9 files changed

+326
-299
lines changed

9 files changed

+326
-299
lines changed

examples/minimal/src/android-bind.zig

Lines changed: 254 additions & 254 deletions
Large diffs are not rendered by default.

examples/minimal/src/minimal.zig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ comptime {
8181
}
8282

8383
/// Android entry point
84-
fn NativeActivity_onCreate(activity: *androidbind.ANativeActivity, rawSavedState: ?[*]u8, rawSavedStateSize: usize) callconv(.C) void {
84+
fn NativeActivity_onCreate(activity: *androidbind.ANativeActivity, rawSavedState: ?[*]u8, rawSavedStateSize: usize) callconv(.c) void {
8585
const savedState: []const u8 = if (rawSavedState) |s|
8686
s[0..rawSavedStateSize]
8787
else
@@ -147,7 +147,7 @@ fn makeNativeActivityGlue(comptime App: type) androidbind.ANativeActivityCallbac
147147
}
148148

149149
// return value must be created with malloc(), so we pass the c_allocator to App.onSaveInstanceState
150-
fn onSaveInstanceState(activity: *androidbind.ANativeActivity, outSize: *usize) callconv(.C) ?[*]u8 {
150+
fn onSaveInstanceState(activity: *androidbind.ANativeActivity, outSize: *usize) callconv(.c) ?[*]u8 {
151151
outSize.* = 0;
152152
if (!@hasDecl(App, "onSaveInstanceState")) {
153153
log.debug("ANativeActivity callback onSaveInstanceState not available on {s}", .{@typeName(App)});
@@ -162,52 +162,52 @@ fn makeNativeActivityGlue(comptime App: type) androidbind.ANativeActivityCallbac
162162
return null;
163163
}
164164

165-
fn onDestroy(activity: *androidbind.ANativeActivity) callconv(.C) void {
165+
fn onDestroy(activity: *androidbind.ANativeActivity) callconv(.c) void {
166166
const instance = activity.instance orelse return;
167167
const app: *App = @ptrCast(@alignCast(instance));
168168
app.deinit();
169169
std.heap.c_allocator.destroy(app);
170170
}
171-
fn onStart(activity: *androidbind.ANativeActivity) callconv(.C) void {
171+
fn onStart(activity: *androidbind.ANativeActivity) callconv(.c) void {
172172
invoke(activity, "onStart", .{});
173173
}
174-
fn onResume(activity: *androidbind.ANativeActivity) callconv(.C) void {
174+
fn onResume(activity: *androidbind.ANativeActivity) callconv(.c) void {
175175
invoke(activity, "onResume", .{});
176176
}
177-
fn onPause(activity: *androidbind.ANativeActivity) callconv(.C) void {
177+
fn onPause(activity: *androidbind.ANativeActivity) callconv(.c) void {
178178
invoke(activity, "onPause", .{});
179179
}
180-
fn onStop(activity: *androidbind.ANativeActivity) callconv(.C) void {
180+
fn onStop(activity: *androidbind.ANativeActivity) callconv(.c) void {
181181
invoke(activity, "onStop", .{});
182182
}
183-
fn onConfigurationChanged(activity: *androidbind.ANativeActivity) callconv(.C) void {
183+
fn onConfigurationChanged(activity: *androidbind.ANativeActivity) callconv(.c) void {
184184
invoke(activity, "onConfigurationChanged", .{});
185185
}
186-
fn onLowMemory(activity: *androidbind.ANativeActivity) callconv(.C) void {
186+
fn onLowMemory(activity: *androidbind.ANativeActivity) callconv(.c) void {
187187
invoke(activity, "onLowMemory", .{});
188188
}
189-
fn onWindowFocusChanged(activity: *androidbind.ANativeActivity, hasFocus: c_int) callconv(.C) void {
189+
fn onWindowFocusChanged(activity: *androidbind.ANativeActivity, hasFocus: c_int) callconv(.c) void {
190190
invoke(activity, "onWindowFocusChanged", .{(hasFocus != 0)});
191191
}
192-
fn onNativeWindowCreated(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.C) void {
192+
fn onNativeWindowCreated(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.c) void {
193193
invoke(activity, "onNativeWindowCreated", .{window});
194194
}
195-
fn onNativeWindowResized(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.C) void {
195+
fn onNativeWindowResized(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.c) void {
196196
invoke(activity, "onNativeWindowResized", .{window});
197197
}
198-
fn onNativeWindowRedrawNeeded(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.C) void {
198+
fn onNativeWindowRedrawNeeded(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.c) void {
199199
invoke(activity, "onNativeWindowRedrawNeeded", .{window});
200200
}
201-
fn onNativeWindowDestroyed(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.C) void {
201+
fn onNativeWindowDestroyed(activity: *androidbind.ANativeActivity, window: *androidbind.ANativeWindow) callconv(.c) void {
202202
invoke(activity, "onNativeWindowDestroyed", .{window});
203203
}
204-
fn onInputQueueCreated(activity: *androidbind.ANativeActivity, input_queue: *androidbind.AInputQueue) callconv(.C) void {
204+
fn onInputQueueCreated(activity: *androidbind.ANativeActivity, input_queue: *androidbind.AInputQueue) callconv(.c) void {
205205
invoke(activity, "onInputQueueCreated", .{input_queue});
206206
}
207-
fn onInputQueueDestroyed(activity: *androidbind.ANativeActivity, input_queue: *androidbind.AInputQueue) callconv(.C) void {
207+
fn onInputQueueDestroyed(activity: *androidbind.ANativeActivity, input_queue: *androidbind.AInputQueue) callconv(.c) void {
208208
invoke(activity, "onInputQueueDestroyed", .{input_queue});
209209
}
210-
fn onContentRectChanged(activity: *androidbind.ANativeActivity, rect: *const androidbind.ARect) callconv(.C) void {
210+
fn onContentRectChanged(activity: *androidbind.ANativeActivity, rect: *const androidbind.ARect) callconv(.c) void {
211211
invoke(activity, "onContentRectChanged", .{rect});
212212
}
213213
};

examples/sdl2/src/sdl-zig-demo.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub const std_options: std.Options = if (builtin.abi.isAndroid())
1414
else
1515
.{};
1616

17-
/// custom panic handler for Android
18-
pub const panic = if (builtin.abi.isAndroid())
19-
android.panic
20-
else
21-
std.debug.FullPanic(std.debug.defaultPanic);
17+
// custom panic handler for Android
18+
// pub const panic = if (builtin.abi.isAndroid())
19+
// android.panic
20+
// else
21+
// std.debug.FullPanic(std.debug.defaultPanic);
2222

2323
comptime {
2424
if (builtin.abi.isAndroid()) {
@@ -27,7 +27,7 @@ comptime {
2727
}
2828

2929
/// This needs to be exported for Android builds
30-
fn SDL_main() callconv(.C) void {
30+
fn SDL_main() callconv(.c) void {
3131
if (comptime builtin.abi.isAndroid()) {
3232
_ = std.start.callMain();
3333
} else {

examples/sdl2/third-party/sdl2/build.zig

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ pub fn build(b: *std.Build) !void {
1010
const sdl_include_path = sdl_path.path(b, "include");
1111

1212
const is_shared_library = target.result.abi.isAndroid(); // NOTE(jae): 2024-09-22: Android uses shared library as SDL2 loads it as part of SDLActivity.java
13-
const lib = if (!is_shared_library) b.addStaticLibrary(.{
13+
const lib = b.addLibrary(.{
1414
.name = "SDL2",
15-
.target = target,
16-
.optimize = optimize,
17-
.link_libc = true,
18-
}) else b.addSharedLibrary(.{
19-
.name = "SDL2",
20-
.target = target,
21-
.optimize = optimize,
22-
.link_libc = true,
15+
.root_module = b.createModule(.{
16+
.target = target,
17+
.optimize = optimize,
18+
.link_libc = true,
19+
}),
20+
.linkage = if (is_shared_library) .dynamic else .static,
2321
});
2422

2523
lib.addCSourceFiles(.{

src/android/android.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ const LogWriter = struct {
103103
line_len: usize = 0,
104104

105105
const Error = error{};
106-
const Writer = std.io.Writer(*@This(), Error, write);
106+
const Writer = if (builtin.zig_version.major == 0 and builtin.zig_version.minor == 14)
107+
std.io.Writer(*@This(), Error, write)
108+
else
109+
std.io.GenericWriter(*@This(), Error, write);
107110

108111
fn write(self: *@This(), buffer: []const u8) Error!usize {
109112
for (buffer) |char| {
@@ -342,14 +345,16 @@ const Panic = struct {
342345
const writeCurrentStackTrace = std.debug.writeCurrentStackTrace;
343346
fn dumpCurrentStackTrace(start_addr: ?usize) void {
344347
nosuspend {
348+
const stderr = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14)
349+
std.io.getStdErr().writer()
350+
else
351+
std.fs.File.stderr().deprecatedWriter();
345352
if (comptime builtin.target.cpu.arch.isWasm()) {
346353
if (native_os == .wasi) {
347-
const stderr = io.getStdErr().writer();
348354
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
349355
}
350356
return;
351357
}
352-
const stderr = io.getStdErr().writer();
353358
if (builtin.strip_debug_info) {
354359
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
355360
return;

src/androidbuild/androidbuild.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,25 @@ pub fn runNameContext(comptime name: []const u8) []const u8 {
100100
pub fn printErrorsAndExit(message: []const u8, errors: []const []const u8) noreturn {
101101
nosuspend {
102102
log.err("{s}", .{message});
103-
const stderr = std.io.getStdErr().writer();
103+
const stderr = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14)
104+
std.io.getStdErr().writer()
105+
else
106+
std.fs.File.stderr();
104107
std.debug.lockStdErr();
105108
defer std.debug.unlockStdErr();
106109
for (errors) |err| {
107110
var it = std.mem.splitScalar(u8, err, '\n');
108111
const headline = it.next() orelse continue;
109112
stderr.writeAll("- ") catch {};
110113
stderr.writeAll(headline) catch {};
111-
stderr.writeByte('\n') catch {};
114+
stderr.writeAll("\n") catch {};
112115
while (it.next()) |line| {
113116
stderr.writeAll(" ") catch {};
114117
stderr.writeAll(line) catch {};
115-
stderr.writeByte('\n') catch {};
118+
stderr.writeAll("\n") catch {};
116119
}
117120
}
118-
stderr.writeByte('\n') catch {};
121+
stderr.writeAll("\n") catch {};
119122
}
120123
std.process.exit(1);
121124
}

src/androidbuild/apk.zig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ fn applyLibLinkCppWorkaroundIssue19(apk: *Apk, artifact: *Step.Compile) void {
786786
const b = apk.b;
787787

788788
const should_apply_fix = (artifact.root_module.link_libcpp == true or
789-
artifact.dependsOnSystemLibrary("c++abi_zig_workaround"));
789+
dependsOnSystemLibrary(artifact, "c++abi_zig_workaround"));
790790
if (!should_apply_fix) {
791791
return;
792792
}
@@ -821,6 +821,22 @@ fn applyLibLinkCppWorkaroundIssue19(apk: *Apk, artifact: *Step.Compile) void {
821821
}
822822
}
823823

824+
/// Copy-paste of "dependsOnSystemLibrary" that only checks if that system library is included to
825+
/// workaround a bug with in Zig 0.15.0-dev.1092+d772c0627
826+
fn dependsOnSystemLibrary(compile: *Step.Compile, name: []const u8) bool {
827+
for (compile.getCompileDependencies(true)) |some_compile| {
828+
for (some_compile.root_module.getGraph().modules) |mod| {
829+
for (mod.link_objects.items) |lo| {
830+
switch (lo) {
831+
.system_lib => |lib| if (std.mem.eql(u8, lib.name, name)) return true,
832+
else => {},
833+
}
834+
}
835+
}
836+
}
837+
return false;
838+
}
839+
824840
fn updateSharedLibraryOptions(artifact: *std.Build.Step.Compile) void {
825841
if (artifact.linkage) |linkage| {
826842
if (linkage != .dynamic) {

src/androidbuild/builtin_options_update.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ fn make(step: *Step, _: Build.Step.MakeOptions) !void {
4141
const builtin_options_update: *BuiltinOptionsUpdate = @fieldParentPtr("step", step);
4242
const options = builtin_options_update.options;
4343

44-
const package_name_path = builtin_options_update.package_name_stdout.getPath2(b, step);
44+
const package_name_path = builtin_options_update.package_name_stdout.getPath3(b, step);
4545

46-
const file = try fs.openFileAbsolute(package_name_path, .{});
46+
// NOTE(jae): 2025-07-23
47+
// As of Zig 0.15.0-dev.1092+d772c0627, package_name_path.openFile("") is not possible as it assumes you're appending *something*
48+
const file = try package_name_path.root_dir.handle.openFile(package_name_path.sub_path, .{});
4749

4850
// Read package name from stdout and strip line feed / carriage return
4951
// ie. "com.zig.sdl2\n\r"

src/androidbuild/d8glob.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn make(step: *Step, _: Build.Step.MakeOptions) !void {
4848
const glob: *@This() = @fieldParentPtr("step", step);
4949
const d8 = glob.run;
5050

51-
const search_dir = glob.dir.getPath2(b, step);
51+
const search_dir = glob.dir.getPath3(b, step);
5252

5353
// NOTE(jae): 2024-09-22
5454
// Change current working directory to where the Java classes are
@@ -62,8 +62,11 @@ fn make(step: *Step, _: Build.Step.MakeOptions) !void {
6262
// - If "d8" has the ability to pass a file of command line parameters, that would work too but I haven't seen any in the docs
6363
d8.setCwd(glob.dir);
6464

65-
var dir = try fs.openDirAbsolute(search_dir, .{ .iterate = true });
65+
// NOTE(jae): 2025-07-23
66+
// As of Zig 0.15.0-dev.1092+d772c0627, package_name_path.openDir("") is not possible as it assumes you're appending a sub-path
67+
var dir = try search_dir.root_dir.handle.openDir(search_dir.sub_path, .{ .iterate = true });
6668
defer dir.close();
69+
6770
var walker = try dir.walk(arena);
6871
defer walker.deinit();
6972
while (try walker.next()) |entry| {
@@ -83,7 +86,7 @@ fn make(step: *Step, _: Build.Step.MakeOptions) !void {
8386
// This is to avoid the Java error "command line too long" that can occur with d8
8487
d8.addArg(entry.path);
8588
d8.addFileInput(LazyPath{
86-
.cwd_relative = try fs.path.resolve(arena, &.{ search_dir, entry.path }),
89+
.cwd_relative = try search_dir.root_dir.join(b.allocator, &.{ search_dir.sub_path, entry.path }),
8790
});
8891
}
8992
}

0 commit comments

Comments
 (0)