Skip to content

Commit

Permalink
Update to zig 2024.10.0-mach and latest mach (#69)
Browse files Browse the repository at this point in the history
* initial attempt to update to latest mach

* CI: update zig version

* why cant i change this to uppercase

* now renamed

* more filename woes

* Finally think we have it all sorted now

* remove shadows, update framebuffer

* Add ability to pinch to zoom, correct scaling

* fine tune pinch to zoom sensitivity

* theme: Set titlebar color when theme is set

* theme: `set` -> `push` and `unset` -> `pop`

* `Pixi` -> `PixiFile`

* `magnify` -> `zoom_gesture`

* artboard: Remove button border on logo screen

* explorer: sidebar: framebuffer size -> window size

* enable seeing debug messages

* internal: Send correct elem_size

* camera: Make zooming keep mouse position consistent

* camera: Fix zooming translations on pinch to zoom and releasing key

* camera: Reduce sensitivity of pinch to zoom

* camera: Better zoom handling, apply camera locking within `processPanZoom` such that moving towards the mouse is correctly locked when zoom stops

* Update to latest mach
  • Loading branch information
foxnne authored Dec 25, 2024
1 parent fbfe861 commit 3b62255
Show file tree
Hide file tree
Showing 59 changed files with 688 additions and 588 deletions.
48 changes: 24 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 2024.5.0-mach
version: 2024.10.0-mach
mirror: 'https://pkg.machengine.org/zig'
- name: Get GTK3
run: sudo apt install libgtk-3-dev
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 2024.5.0-mach
version: 2024.10.0-mach
mirror: 'https://pkg.machengine.org/zig'
- name: Build
run: zig build
Expand All @@ -72,32 +72,32 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 2024.5.0-mach
version: 2024.10.0-mach
mirror: 'https://pkg.machengine.org/zig'
- name: build
run: zig build -Duse_sysgpu=true
run: zig build
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: arm64-macos
path: zig-out/bin
x86_64-macos:
runs-on: macos-12
# We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# to the branch.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 2024.5.0-mach
mirror: 'https://pkg.machengine.org/zig'
- name: Build
run: zig build -Duse_sysgpu=true
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: x86_64-macos
path: zig-out/bin
# x86_64-macos:
# runs-on: macos-12
# # We want to run on external PRs, but not on our own internal PRs as they'll be run by the push
# # to the branch.
# if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Setup Zig
# uses: mlugg/setup-zig@v1
# with:
# version: 2024.5.0-mach
# mirror: 'https://pkg.machengine.org/zig'
# - name: Build
# run: zig build -Duse_sysgpu=true
# - name: Upload Artifacts
# uses: actions/upload-artifact@v4
# with:
# name: x86_64-macos
# path: zig-out/bin
26 changes: 7 additions & 19 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
},
{
"label": "Build and Run Project (dawn)",
"label": "Build and Run Project",
"type": "shell",
"command": "zig build run",
"group": {
Expand All @@ -38,9 +38,9 @@
}
},
{
"label": "Build and Run Project (sysgpu)",
"label": "Build and Run Project (release-fast)",
"type": "shell",
"command": "zig build run -Duse_sysgpu=true",
"command": "zig build run -Doptimize=ReleaseFast",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -50,9 +50,9 @@
}
},
{
"label": "Build and Run Project (sysgpu/release-fast)",
"label": "Build and Run Project (release-small)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseFast -Duse_sysgpu=true",
"command": "zig build run -Doptimize=ReleaseSmall",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -62,21 +62,9 @@
}
},
{
"label": "Build and Run Project (sysgpu/release-small)",
"label": "Build and Run Project (release-safe)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseSmall -Duse_sysgpu=true",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"clear": true
}
},
{
"label": "Build and Run Project (sysgpu/release-safe)",
"type": "shell",
"command": "zig build run -Doptimize=ReleaseSafe -Duse_sysgpu=true",
"command": "zig build run -Doptimize=ReleaseSafe",
"group": {
"kind": "build",
"isDefault": true
Expand Down
Binary file modified assets/src/cursors.pixi
Binary file not shown.
86 changes: 31 additions & 55 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ const std = @import("std");
const builtin = @import("builtin");

const mach = @import("mach");
const mach_gpu_dawn = @import("mach_gpu_dawn");

const nfd = @import("src/deps/nfd-zig/build.zig");
const zip = @import("src/deps/zip/build.zig");

const content_dir = "assets/";
const src_path = "src/pixi.zig";
const src_path = "src/main.zig";

const ProcessAssetsStep = @import("src/tools/process_assets.zig").ProcessAssetsStep;

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const use_sysgpu = b.option(bool, "use_sysgpu", "Use sysgpu") orelse false;

const zstbi = b.dependency("zstbi", .{ .target = target, .optimize = optimize });
const zmath = b.dependency("zmath", .{ .target = target, .optimize = optimize });

Expand All @@ -26,6 +23,7 @@ pub fn build(b: *std.Build) !void {
const mach_dep = b.dependency("mach", .{
.target = target,
.optimize = optimize,
.core = true,
});

const zig_imgui_dep = b.dependency("zig_imgui", .{ .target = target, .optimize = optimize });
Expand All @@ -37,82 +35,60 @@ pub fn build(b: *std.Build) !void {
},
});

const build_options = b.addOptions();
build_options.addOption(bool, "use_sysgpu", use_sysgpu);

const app = try mach.CoreApp.init(b, mach_dep.builder, .{
.name = "pixi",
.src = src_path,
.target = target,
.deps = &.{
.{ .name = "zstbi", .module = zstbi.module("root") },
.{ .name = "zmath", .module = zmath.module("root") },
.{ .name = "nfd", .module = nfd.getModule(b) },
.{ .name = "zip", .module = zip_pkg.module },
.{ .name = "zig-imgui", .module = imgui_module },
.{ .name = "build-options", .module = build_options.createModule() },
},
.optimize = optimize,
});

switch (target.result.os.tag) {
.windows => app.compile.subsystem = .Windows,
else => app.compile.subsystem = .Posix,
}

const install_step = b.step("pixi", "Install pixi");
install_step.dependOn(&app.install.step);
b.getInstallStep().dependOn(install_step);

const run_step = b.step("run", "Run pixi");
run_step.dependOn(&app.run.step);

const unit_tests = b.addTest(.{
const exe = b.addExecutable(.{
.name = "Pixi",
.root_source_file = b.path(src_path),
.target = target,
.optimize = optimize,
});

unit_tests.root_module.addImport("zstbi", zstbi.module("root"));
unit_tests.root_module.addImport("zmath", zmath.module("root"));
unit_tests.root_module.addImport("nfd", nfd.getModule(b));
unit_tests.root_module.addImport("zip", zip_pkg.module);
if (optimize != .Debug) {
switch (target.result.os.tag) {
.windows => exe.subsystem = .Windows,
else => exe.subsystem = .Posix,
}
}

const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
const run_step = b.step("run", "Run the example");
run_step.dependOn(&b.addRunArtifact(exe).step);

app.compile.root_module.addImport("zstbi", zstbi.module("root"));
app.compile.root_module.addImport("zmath", zmath.module("root"));
app.compile.root_module.addImport("nfd", nfd.getModule(b));
app.compile.root_module.addImport("zip", zip_pkg.module);
app.compile.root_module.addImport("zig-imgui", imgui_module);
exe.root_module.addImport("mach", mach_dep.module("mach"));
exe.root_module.addImport("zstbi", zstbi.module("root"));
exe.root_module.addImport("zmath", zmath.module("root"));
exe.root_module.addImport("nfd", nfd.getModule(b));
exe.root_module.addImport("zip", zip_pkg.module);
exe.root_module.addImport("zig-imgui", imgui_module);

const nfd_lib = nfd.makeLib(b, target, optimize);
app.compile.root_module.addImport("nfd", nfd_lib);
exe.root_module.addImport("nfd", nfd_lib);
if (target.result.isDarwin()) {
// // MacOS: this must be defined for macOS 13.3 and older.
// // Critically, this MUST NOT be included as a -D__kernel_ptr_semantics flag. If it is,
// // then this macro will not be defined even if `defineCMacro` was also called!
nfd_lib.addCMacro("__kernel_ptr_semantics", "");
// xcode_frameworks.addPaths(nfd_lib);
mach.addPaths(nfd_lib);
//mach.addPaths(nfd_lib);

}
app.compile.linkLibrary(zig_imgui_dep.artifact("imgui"));
app.compile.linkLibrary(zstbi.artifact("zstbi"));
zip.link(app.compile);

exe.linkLibCpp();

exe.linkLibrary(zig_imgui_dep.artifact("imgui"));
exe.linkLibrary(zstbi.artifact("zstbi"));
zip.link(exe);

const assets = ProcessAssetsStep.init(b, "assets", "src/assets.zig", "src/animations.zig");
var process_assets_step = b.step("process-assets", "generates struct for all assets");
process_assets_step.dependOn(&assets.step);
app.compile.step.dependOn(process_assets_step);
exe.step.dependOn(process_assets_step);

const install_content_step = b.addInstallDirectory(.{
.source_dir = .{ .cwd_relative = thisDir() ++ "/" ++ content_dir },
.install_dir = .{ .custom = "" },
.install_subdir = "bin/" ++ content_dir,
});
app.compile.step.dependOn(&install_content_step.step);
exe.step.dependOn(&install_content_step.step);

b.installArtifact(exe);
}

inline fn thisDir() []const u8 {
Expand Down
14 changes: 7 additions & 7 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
"assets",
},
.name = "pixi",
.version = "0.0.1",
.version = "0.0.2",
.dependencies = .{
.mach = .{
.url = "https://pkg.machengine.org/mach/b72f0e11b6d292c2b60789359a61f7ee6d7dc371.tar.gz",
.hash = "122015e1dac4afaf275f7f2adde3814e6a27f5799cbef96bb487ee305f7e33f4dca3",
.url = "https://pkg.machengine.org/mach/df3091bfd5b56dcfd82de49758acbb05eca3e3e7.tar.gz",
.hash = "1220209945bf9c4a1e08aba79ed2cf628c9a4ec28bbdc7ed6e8a9d7f246dfeaf50b2",
},
.zig_imgui = .{
.url = "https://github.com/foxnne/zig-imgui/archive/d5790495da5ec0282aa65e7eecf541f951afb44f.tar.gz",
.hash = "1220b58e522bd5c9995ababaf50771bab62cd9e1a3908dcb1b25ec42510770854cc1",
.url = "https://github.com/foxnne/zig-imgui/archive/c2798fc5706b2f34d436f1b835bb0f6bd5e36964.tar.gz",
.hash = "1220bbf119eb552d648ccf17601e91fa0dd73e39ed6fd61fae1c6710c5a5ab729752",
},
.zstbi = .{
.url = "https://github.com/foxnne/zstbi/archive/d9a0947365b1ee8131fcf518feac8dfe896cfcfa.tar.gz",
.hash = "1220ce381d38f9ce6db428405b7884d139cab8173d3bf7d950582991d941c868423a",
},
.zmath = .{
.url = "https://github.com/foxnne/zmath/archive/fbaa671892f8562742356a6d6135a209b4ad05a0.tar.gz",
.hash = "1220a0e58646047a1322c89b4ff29829623290a6875d363cd35b377757c66510132c",
.url = "https://github.com/foxnne/zmath/archive/9620a611a8c039711dc780bf296d8dc100d16d3a.tar.gz",
.hash = "12201b9f28adb918c2ffaf75b57a4b714a864038f8ba3e2d9f730187d0a852b952e1",
},
},
}
2 changes: 1 addition & 1 deletion src/Colors.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const pixi = @import("pixi.zig");
const pixi = @import("Pixi.zig");

const Self = @This();

Expand Down
Loading

0 comments on commit 3b62255

Please sign in to comment.