Skip to content

Commit 6d7a976

Browse files
committed
Update to Zig 0.12.0-dev.2236+32e88251e
1 parent abdbc0a commit 6d7a976

20 files changed

+92
-81
lines changed

build.zig

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ pub fn build(b: *std.Build) !void {
1717
const zigwin32_dep = b.dependency("zigwin32", .{});
1818
const nanovg_dep = b.dependency("nanovg", .{ .target = target, .optimize = optimize });
1919

20-
// const nanovg = b.createModule(.{ .source_file = .{ .path = "deps/nanovg-zig/src/nanovg.zig" } });
21-
const nanovg = nanovg_dep.module("nanovg");
22-
const gui = b.createModule(.{ .source_file = .{ .path = "src/gui/gui.zig" }, .dependencies = &.{.{ .name = "nanovg", .module = nanovg }} });
20+
const nanovg_mod = nanovg_dep.module("nanovg");
21+
const gui_mod = b.createModule(.{ .root_source_file = .{ .path = "src/gui/gui.zig" } });
22+
gui_mod.addImport("nanovg", nanovg_mod);
23+
const data_mod = b.createModule(.{ .root_source_file = .{ .path = "data/data.zig" } });
24+
2325

2426
const exe = b.addExecutable(.{
2527
.name = "minipixel",
2628
.root_source_file = .{ .path = "src/main.zig" },
27-
.main_mod_path = .{ .path = "." },
2829
.target = target,
2930
.optimize = optimize,
3031
});
3132

3233
const exe_options = b.addOptions();
33-
exe.addOptions("build_options", exe_options);
34+
exe.root_module.addOptions("build_options", exe_options);
3435
exe_options.addOption(bool, "automated_testing", automated_testing);
3536

3637
exe.addIncludePath(.{ .path = "lib/gl2/include" });
37-
if (exe.target.isWindows()) {
38-
exe.addVcpkgPaths(.dynamic) catch @panic("vcpkg not installed");
39-
if (exe.vcpkg_bin_path) |bin_path| {
40-
for (&[_][]const u8{ "libpng16.dll", "zlib1.dll" }) |dll| {
41-
const src_dll = try std.fs.path.join(b.allocator, &.{ bin_path, dll });
42-
b.installBinFile(src_dll, dll);
43-
}
44-
}
38+
if (target.result.os.tag == .windows) {
39+
// exe.addVcpkgPaths(.dynamic) catch @panic("vcpkg not installed");
40+
// if (exe.vcpkg_bin_path) |bin_path| {
41+
// for (&[_][]const u8{ "libpng16.dll", "zlib1.dll" }) |dll| {
42+
// const src_dll = try std.fs.path.join(b.allocator, &.{ bin_path, dll });
43+
// b.installBinFile(src_dll, dll);
44+
// }
45+
// }
4546
exe.subsystem = .Windows;
4647
exe.linkSystemLibrary("shell32");
4748
std.fs.cwd().access("minipixel.o", .{}) catch {
@@ -50,7 +51,7 @@ pub fn build(b: *std.Build) !void {
5051
return error.FileNotFound;
5152
};
5253
exe.addObjectFile(.{ .path = "minipixel.o" }); // add icon
53-
} else if (exe.target.isDarwin()) {
54+
} else if (target.result.os.tag == .macos) {
5455
exe.addCSourceFile(.{ .file = .{ .path = "src/c/sdl_hacks.m" }, .flags = &.{} });
5556
}
5657
const c_flags: []const []const u8 = if (optimize == .Debug)
@@ -59,28 +60,27 @@ pub fn build(b: *std.Build) !void {
5960
&.{ "-std=c99", "-D_CRT_SECURE_NO_WARNINGS" };
6061
exe.addCSourceFile(.{ .file = .{ .path = "src/c/png_image.c" }, .flags = &.{"-std=c99"} });
6162
exe.addCSourceFile(.{ .file = .{ .path = "lib/gl2/src/glad.c" }, .flags = c_flags });
62-
exe.addModule("win32", zigwin32_dep.module("zigwin32"));
63-
exe.addModule("nfd", nfd_dep.module("nfd"));
64-
exe.addModule("nanovg", nanovg);
65-
exe.addModule("gui", gui);
66-
exe.linkLibrary(nanovg_dep.artifact("nanovg"));
67-
exe.linkLibrary(nfd_dep.artifact("nfd"));
63+
exe.root_module.addImport("win32", zigwin32_dep.module("zigwin32"));
64+
exe.root_module.addImport("nfd", nfd_dep.module("nfd"));
65+
exe.root_module.addImport("nanovg", nanovg_mod);
66+
exe.root_module.addImport("gui", gui_mod);
67+
exe.root_module.addImport("data", data_mod);
6868
exe.linkLibrary(sdl_dep.artifact("SDL2"));
69-
if (exe.target.isWindows()) {
69+
if (target.result.os.tag == .windows) {
7070
// Workaround for CI: Zig detects pkg-config and resolves -lpng16 which doesn't exist
71-
exe.linkSystemLibraryName("libpng16");
72-
} else if (exe.target.isDarwin()) {
71+
exe.linkSystemLibrary("libpng16");
72+
} else if (target.result.os.tag == .macos) {
7373
exe.addIncludePath(.{ .path = "/opt/homebrew/include" });
7474
exe.addLibraryPath(.{ .path = "/opt/homebrew/lib" });
7575
exe.linkSystemLibrary("png");
7676
} else {
7777
exe.linkSystemLibrary("libpng16");
7878
}
79-
if (exe.target.isDarwin()) {
79+
if (target.result.os.tag == .macos) {
8080
exe.linkFramework("OpenGL");
81-
} else if (exe.target.isWindows()) {
81+
} else if (target.result.os.tag == .windows) {
8282
exe.linkSystemLibrary("opengl32");
83-
} else if (exe.target.isLinux()) {
83+
} else if (target.result.os.tag == .linux) {
8484
exe.linkSystemLibrary("gl");
8585
exe.linkSystemLibrary("X11");
8686
}

build.zig.zon

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
},
1212
.dependencies = .{
1313
.nfd = .{
14-
.url = "https://github.com/fabioarnold/nfd-zig/archive/4701d11cf52866828bd682c19ddddf60f8152960.tar.gz",
15-
.hash = "12207996dc990674491c5cebe0c78026f8f99608a4cd5187bfeb0b3df910a04dc907",
14+
.url = "https://github.com/fabioarnold/nfd-zig/archive/91b199d3cbb314c52c630b7bf6050c4d665c0628.tar.gz",
15+
.hash = "122020466a938b490e0d4963eae2157d976990aa0acc53a1e32f9ac39d63a14cf977",
1616
},
1717
.sdl = .{
18-
.url = "https://github.com/fabioarnold/SDL/archive/ea82c623a1321b81c64fc89c76579168b2ac835d.tar.gz",
19-
.hash = "1220484b1a29fcae7fd69b66b0089827a424b3c1b217dd9848a70878df7182977ac2",
18+
.url = "https://github.com/andrewrk/SDL/archive/db4a162db2f6f59f737d03f441455dc9524d5793.tar.gz",
19+
.hash = "1220c5360c9c71c215baa41b46ec18d0711059b48416a2b1cf96c7c2d87b2e8e4cf6",
2020
},
2121
.zigwin32 = .{
2222
.url = "https://github.com/marlersoft/zigwin32/archive/6777f1db221d0cb50322842f558f03e3c3a4099f.tar.gz",
2323
.hash = "1220f8d5028adceac0c6fc8ef554d82efef49ca48913393e9c2f5d73a66b58c8aaad",
2424
},
2525
.nanovg = .{
26-
.url = "https://github.com/fabioarnold/nanovg-zig/archive/de997980351481b6e1bbb6e1aceddde963d5e32b.tar.gz",
27-
.hash = "1220b8d6ff0b689f46824fc9f4d179ced85b82c733c361ab69b6634a85bd88e88ba7",
26+
.url = "https://github.com/fabioarnold/nanovg-zig/archive/b3396d4e65da5862c6ff088f64b3301aa50f3a9f.tar.gz",
27+
.hash = "1220908cb7b3e907526744c1ab23d21d312a6062e3813dc1facc6f03980fdd3c04f6",
2828
},
2929
},
3030
}

data/data.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub const fonts = struct {
2+
pub const roboto_regular = @embedFile("fonts/Roboto-Regular.ttf");
3+
pub const roboto_bold = @embedFile("fonts/Roboto-Bold.ttf");
4+
};
5+
6+
pub const images = struct {
7+
pub const blendmodealpha = @embedFile("images/blendmodealpha.png");
8+
pub const blendmodereplace = @embedFile("images/blendmodereplace.png");
9+
};
10+
11+
pub const palettes = struct {
12+
pub const arne16 = @embedFile("palettes/arne16.pal");
13+
};
File renamed without changes.
File renamed without changes.

src/AboutDialogWidget.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn onMouseDown(widget: *gui.Widget, mouse_event: *gui.MouseEvent) void {
6969
}
7070

7171
fn onMouseMove(widget: *gui.Widget, mouse_event: *gui.MouseEvent) void {
72-
var self = @fieldParentPtr(Self, "widget", widget);
72+
const self = @fieldParentPtr(Self, "widget", widget);
7373
_ = self;
7474
const link_itchio_rect = Rect(f32).make(
7575
link_itchio_bounds[0],

src/BlendModeWidget.zig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ const Allocator = std.mem.Allocator;
33

44
const gui = @import("gui");
55
const nvg = @import("nanovg");
6+
const data = @import("data");
67
const Rect = gui.geometry.Rect;
78
const Point = gui.geometry.Point;
89
const BlendMode = @import("color.zig").BlendMode;
910

10-
const image_alpha_data = @embedFile("../data/blendmodealpha.png");
11-
const image_replace_data = @embedFile("../data/blendmodereplace.png");
12-
1311
widget: gui.Widget,
1412
allocator: Allocator,
1513

@@ -34,8 +32,8 @@ pub fn init(allocator: Allocator, rect: Rect(f32), vg: nvg) !*Self {
3432
Rect(f32).make(pad + 1, 33 - 27, rect.w - 2 * pad - 2, 27),
3533
Rect(f32).make(pad + 1, 33, rect.w - 2 * pad - 2, 27),
3634
},
37-
.image_alpha = vg.createImageMem(image_alpha_data, .{ .nearest = true }),
38-
.image_replace = vg.createImageMem(image_replace_data, .{ .nearest = true }),
35+
.image_alpha = vg.createImageMem(data.images.blendmodealpha, .{ .nearest = true }),
36+
.image_replace = vg.createImageMem(data.images.blendmodereplace, .{ .nearest = true }),
3937
};
4038

4139
self.widget.onMouseDownFn = onMouseDown;

src/ClipboardWin32.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn setImage(allocator: std.mem.Allocator, image: Image) !void {
6262

6363
if (c.EmptyClipboard() == 0) return error.EmptyClipboardFailed;
6464

65-
var png_data = try image.writeToMemory(allocator);
65+
const png_data = try image.writeToMemory(allocator);
6666
defer allocator.free(png_data);
6767

6868
// copy to global memory
@@ -73,7 +73,7 @@ pub fn setImage(allocator: std.mem.Allocator, image: Image) !void {
7373
if (c.GlobalLock(global_handle)) |local_mem| {
7474
defer _ = c.GlobalUnlock(global_handle);
7575
const data = @as([*]u8, @ptrCast(local_mem));
76-
std.mem.copy(u8, data[0..png_data.len], png_data);
76+
@memcpy(data[0..png_data.len], png_data);
7777

7878
_ = c.SetClipboardData(png_format, global_handle);
7979
}

src/ColorForegroundBackgroundWidget.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn getRgba(self: Self, color_layer: ColorLayer) [4]u8 {
8888
pub fn setRgba(self: *Self, color_layer: ColorLayer, color: []const u8) void {
8989
const i = @intFromEnum(color_layer);
9090
if (!std.mem.eql(u8, &self.colors[i], color)) {
91-
std.mem.copy(u8, &self.colors[i], color);
91+
@memcpy(&self.colors[i], color);
9292
self.notifyChanged(.color);
9393
}
9494
}

src/ColorPaletteWidget.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
33

44
const gui = @import("gui");
55
const nvg = @import("nanovg");
6+
const data = @import("data");
67
const Rect = gui.geometry.Rect;
78
const col = @import("color.zig");
89

@@ -18,7 +19,7 @@ onSelectionChangedFn: ?*const fn (*Self) void = null,
1819

1920
const Self = @This();
2021

21-
const default_pal_contents = @embedFile("../data/palettes/arne16.pal");
22+
const default_pal_contents = data.palettes.arne16;
2223

2324
pub fn init(allocator: Allocator, rect: Rect(f32)) !*Self {
2425
var self = try allocator.create(Self);
@@ -97,7 +98,7 @@ pub fn loadPalContents(self: *Self, contents: []const u8) !void {
9798
self.colors[4 * i + 3] = alpha;
9899
}
99100
while (i < 256) : (i += 1) {
100-
std.mem.copy(u8, self.colors[4 * i ..][0..4], &col.black);
101+
@memcpy(self.colors[4 * i ..][0..4], &col.black);
101102
}
102103
}
103104

0 commit comments

Comments
 (0)