From f29b775b27658e0d046b797cca3619115f58d5cd Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 4 Mar 2024 23:25:36 -0700 Subject: [PATCH] mach-core moves back into the main repository Helps hexops/mach#1165 Signed-off-by: Stephen Gutekanst --- .github/ISSUE_TEMPLATE/dev_zig_nomination.md | 1 - .gitignore | 2 + build.zig | 464 +++++++++++++++++-- build.zig.zon | 28 +- src/engine.zig | 7 +- src/gfx/Sprite.zig | 8 +- src/main.zig | 2 +- 7 files changed, 472 insertions(+), 40 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/dev_zig_nomination.md b/.github/ISSUE_TEMPLATE/dev_zig_nomination.md index 3831f281..937f4af9 100644 --- a/.github/ISSUE_TEMPLATE/dev_zig_nomination.md +++ b/.github/ISSUE_TEMPLATE/dev_zig_nomination.md @@ -142,6 +142,5 @@ These projects have dependencies on other projects. We update them in the exact * mach-freetype * [ ] mach-editor, which depends on: * mach - * mach-sysgpu * spirv-cross * spirv-tools diff --git a/.gitignore b/.gitignore index feda423c..50e7fd85 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ zig-out/ /build/ /build-*/ /docgen_tmp/ + +src/core/examples/libs/ diff --git a/build.zig b/build.zig index 00610d31..81340d88 100644 --- a/build.zig +++ b/build.zig @@ -1,7 +1,8 @@ const std = @import("std"); const builtin = @import("builtin"); const glfw = @import("mach_glfw"); -const core = @import("mach_core"); +const gpu = @import("mach_gpu"); +const sysgpu = @import("mach_sysgpu"); pub const SysgpuBackend = enum { default, @@ -49,8 +50,9 @@ pub fn build(b: *std.Build) !void { const sysaudio_deps = b.option(bool, "sysaudio", "build sysaudio specifically"); const sysgpu_deps = b.option(bool, "sysgpu", "build sysgpu specifically"); const sysgpu_backend = b.option(SysgpuBackend, "sysgpu_backend", "sysgpu API backend") orelse .default; + const core_platform = b.option(CoreApp.Platform, "core_platform", "mach core platform to use") orelse CoreApp.Platform.fromTarget(target.result); - const want_mach = core_deps != null or sysaudio_deps != null or sysgpu_deps != null; + const want_mach = core_deps == null and sysaudio_deps == null and sysgpu_deps == null; const want_core = want_mach or (core_deps orelse false); const want_sysaudio = want_mach or (sysaudio_deps orelse false); const want_sysgpu = want_mach or want_core or (sysgpu_deps orelse false); @@ -61,9 +63,10 @@ pub fn build(b: *std.Build) !void { build_options.addOption(bool, "want_sysaudio", want_sysaudio); build_options.addOption(bool, "want_sysgpu", want_sysgpu); build_options.addOption(SysgpuBackend, "sysgpu_backend", sysgpu_backend); + build_options.addOption(CoreApp.Platform, "core_platform", core_platform); const module = b.addModule("mach", .{ - .root_source_file = .{ .path = sdkPath("/src/main.zig") }, + .root_source_file = .{ .path = "src/main.zig" }, .optimize = optimize, .target = target, }); @@ -73,10 +76,6 @@ pub fn build(b: *std.Build) !void { if (target.result.os.tag == .linux) module.link_libc = true; // TODO(Zig 2024.03): use b.lazyDependency - const mach_core_dep = b.dependency("mach_core", .{ - .target = target, - .optimize = optimize, - }); const mach_basisu_dep = b.dependency("mach_basisu", .{ .target = target, .optimize = optimize, @@ -91,13 +90,45 @@ pub fn build(b: *std.Build) !void { }); const font_assets_dep = b.dependency("font_assets", .{}); - module.addImport("mach-core", mach_core_dep.module("mach-core")); module.addImport("mach-basisu", mach_basisu_dep.module("mach-basisu")); module.addImport("mach-freetype", mach_freetype_dep.module("mach-freetype")); module.addImport("mach-harfbuzz", mach_freetype_dep.module("mach-harfbuzz")); module.addImport("mach-sysjs", mach_sysjs_dep.module("mach-sysjs")); module.addImport("font-assets", font_assets_dep.module("font-assets")); } + if (want_core) { + const mach_gpu_dep = b.dependency("mach_gpu", .{ + .target = target, + .optimize = optimize, + }); + module.addImport("mach-gpu", mach_gpu_dep.module("mach-gpu")); + + if (target.result.cpu.arch == .wasm32) { + const sysjs_dep = b.dependency("mach_sysjs", .{ + .target = target, + .optimize = optimize, + }); + module.addImport("mach-sysjs", sysjs_dep.module("mach-sysjs")); + } else { + const mach_glfw_dep = b.dependency("mach_glfw", .{ + .target = target, + .optimize = optimize, + }); + const x11_headers_dep = b.dependency("x11_headers", .{ + .target = target, + .optimize = optimize, + }); + const wayland_headers_dep = b.dependency("wayland_headers", .{ + .target = target, + .optimize = optimize, + }); + module.addImport("mach-glfw", mach_glfw_dep.module("mach-glfw")); + module.linkLibrary(x11_headers_dep.artifact("x11-headers")); + module.linkLibrary(wayland_headers_dep.artifact("wayland-headers")); + module.addCSourceFile(.{ .file = .{ .path = "src/core/platform/wayland/wayland.c" } }); + } + try buildCoreExamples(b, optimize, target, module, core_platform); + } if (want_sysaudio) { // Can build sysaudio examples if desired, then. inline for ([_][]const u8{ @@ -228,17 +259,6 @@ pub fn build(b: *std.Build) !void { const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_unit_tests.step); - // TODO: autodoc segfaults the build if we have this enabled - // https://github.com/hexops/mach/issues/1145 - // - // const install_docs = b.addInstallDirectory(.{ - // .source_dir = unit_tests.getEmittedDocs(), - // .install_dir = .prefix, // default build output prefix, ./zig-out - // .install_subdir = "docs", - // }); - // const docs_step = b.step("docs", "Generate API docs"); - // docs_step.dependOn(&install_docs.step); - if (want_sysgpu) linkSysgpu(b, &unit_tests.root_module); } } @@ -250,8 +270,8 @@ pub const App = struct { compile: *std.Build.Step.Compile, install: *std.Build.Step.InstallArtifact, run: *std.Build.Step.Run, - platform: core.App.Platform, - core: core.App, + platform: CoreApp.Platform, + core: CoreApp, pub fn init( app_builder: *std.Build, @@ -281,11 +301,7 @@ pub const App = struct { if (options.deps) |v| try deps.appendSlice(v); try deps.append(.{ .name = "mach", .module = mach_mod }); - const mach_core_dep = mach_builder.dependency("mach_core", .{ - .target = options.target, - .optimize = options.optimize, - }); - const app = try core.App.init(app_builder, mach_core_dep.builder, .{ + const app = try CoreApp.init(app_builder, mach_builder.builder, .{ .name = options.name, .src = options.src, .target = options.target, @@ -294,7 +310,7 @@ pub const App = struct { .deps = deps.items, .res_dirs = options.res_dirs, .watch_paths = options.watch_paths, - .mach_core_mod = mach_core_dep.module("mach-core"), + .mach_mod = mach_mod, }); return .{ .core = app, @@ -320,6 +336,154 @@ pub const App = struct { } }; +pub const CoreApp = struct { + b: *std.Build, + name: []const u8, + compile: *std.Build.Step.Compile, + install: *std.Build.Step.InstallArtifact, + run: *std.Build.Step.Run, + platform: Platform, + res_dirs: ?[]const []const u8, + watch_paths: ?[]const []const u8, + + pub const Platform = enum { + glfw, + x11, + wayland, + web, + + pub fn fromTarget(target: std.Target) Platform { + if (target.cpu.arch == .wasm32) return .web; + return .glfw; + } + }; + + pub fn init( + app_builder: *std.Build, + core_builder: *std.Build, + options: struct { + name: []const u8, + src: []const u8, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + custom_entrypoint: ?[]const u8 = null, + deps: ?[]const std.Build.Module.Import = null, + res_dirs: ?[]const []const u8 = null, + watch_paths: ?[]const []const u8 = null, + mach_mod: ?*std.Build.Module = null, + platform: ?Platform, + }, + ) !CoreApp { + const target = options.target.result; + const platform = options.platform orelse Platform.fromTarget(target); + + var imports = std.ArrayList(std.Build.Module.Import).init(app_builder.allocator); + + const mach_mod = options.mach_mod orelse app_builder.dependency("mach", .{ + .target = options.target, + .optimize = options.optimize, + }).module("mach"); + try imports.append(.{ + .name = "mach", + .module = mach_mod, + }); + + if (options.deps) |app_deps| try imports.appendSlice(app_deps); + + const app_module = app_builder.createModule(.{ + .root_source_file = .{ .path = options.src }, + .imports = try imports.toOwnedSlice(), + }); + + // Tell mach about the chosen platform + const platform_options = app_builder.addOptions(); + platform_options.addOption(Platform, "platform", platform); + mach_mod.addOptions("platform_options", platform_options); + + const compile = blk: { + if (platform == .web) { + // wasm libraries should go into zig-out/www/ + app_builder.lib_dir = app_builder.fmt("{s}/www", .{app_builder.install_path}); + + const lib = app_builder.addStaticLibrary(.{ + .name = options.name, + .root_source_file = .{ .path = options.custom_entrypoint orelse sdkPath("/src/core/platform/wasm/entrypoint.zig") }, + .target = options.target, + .optimize = options.optimize, + }); + lib.rdynamic = true; + + break :blk lib; + } else { + const exe = app_builder.addExecutable(.{ + .name = options.name, + .root_source_file = .{ .path = options.custom_entrypoint orelse sdkPath("/src/core/platform/native_entrypoint.zig") }, + .target = options.target, + .optimize = options.optimize, + }); + // TODO(core): figure out why we need to disable LTO: https://github.com/hexops/mach/issues/597 + exe.want_lto = false; + + break :blk exe; + } + }; + + compile.root_module.addImport("mach", mach_mod); + compile.root_module.addImport("app", app_module); + + // Installation step + app_builder.installArtifact(compile); + const install = app_builder.addInstallArtifact(compile, .{}); + if (options.res_dirs) |res_dirs| { + for (res_dirs) |res| { + const install_res = app_builder.addInstallDirectory(.{ + .source_dir = .{ .path = res }, + .install_dir = install.dest_dir.?, + .install_subdir = std.fs.path.basename(res), + .exclude_extensions = &.{}, + }); + install.step.dependOn(&install_res.step); + } + } + if (platform == .web) { + inline for (.{ sdkPath("/src/core/platform/wasm/mach.js"), @import("mach_sysjs").getJSPath() }) |js| { + const install_js = app_builder.addInstallFileWithDir( + .{ .path = js }, + std.Build.InstallDir{ .custom = "www" }, + std.fs.path.basename(js), + ); + install.step.dependOn(&install_js.step); + } + } + + // Link dependencies + if (platform != .web) { + link(core_builder, compile, &compile.root_module); + } + + const run = app_builder.addRunArtifact(compile); + run.step.dependOn(&install.step); + return .{ + .b = app_builder, + .compile = compile, + .install = install, + .run = run, + .name = options.name, + .platform = platform, + .res_dirs = options.res_dirs, + .watch_paths = options.watch_paths, + }; + } +}; + +// TODO(sysgpu): remove this once we switch to sysgpu fully +pub fn link(core_builder: *std.Build, step: *std.Build.Step.Compile, mod: *std.Build.Module) void { + gpu.link(core_builder.dependency("mach_gpu", .{ + .target = step.root_module.resolved_target orelse core_builder.host, + .optimize = step.root_module.optimize.?, + }).builder, step, mod, .{}) catch unreachable; +} + fn linkSysgpu(b: *std.Build, module: *std.Build.Module) void { module.link_libc = true; @@ -375,3 +539,249 @@ comptime { @compileError(std.fmt.comptimePrint("unsupported Zig version ({}). Required Zig version 2024.1.0-mach: https://machengine.org/about/nominated-zig/#202410-mach", .{builtin.zig_version})); } } + +fn buildCoreExamples( + b: *std.Build, + optimize: std.builtin.OptimizeMode, + target: std.Build.ResolvedTarget, + mach_mod: *std.Build.Module, + platform: CoreApp.Platform, +) !void { + try ensureDependencies(b.allocator); + + const Dependency = enum { + zigimg, + model3d, + assets, + + pub fn dependency( + dep: @This(), + b2: *std.Build, + target2: std.Build.ResolvedTarget, + optimize2: std.builtin.OptimizeMode, + ) std.Build.Module.Import { + const path = switch (dep) { + .zigimg => "src/core/examples/libs/zigimg/zigimg.zig", + .assets => return std.Build.Module.Import{ + .name = "assets", + .module = b2.dependency("mach_core_example_assets", .{ + .target = target2, + .optimize = optimize2, + }).module("mach-core-example-assets"), + }, + .model3d => return std.Build.Module.Import{ + .name = "model3d", + .module = b2.dependency("mach_model3d", .{ + .target = target2, + .optimize = optimize2, + }).module("mach-model3d"), + }, + }; + return std.Build.Module.Import{ + .name = @tagName(dep), + .module = b2.createModule(.{ .root_source_file = .{ .path = path } }), + }; + } + }; + + inline for ([_]struct { + name: []const u8, + deps: []const Dependency = &.{}, + std_platform_only: bool = false, + sysgpu: bool = false, + }{ + .{ .name = "wasm-test" }, + .{ .name = "triangle" }, + .{ .name = "triangle-msaa" }, + .{ .name = "clear-color" }, + .{ .name = "procedural-primitives" }, + .{ .name = "boids" }, + .{ .name = "rotating-cube" }, + .{ .name = "pixel-post-process" }, + .{ .name = "two-cubes" }, + .{ .name = "instanced-cube" }, + .{ .name = "gen-texture-light" }, + .{ .name = "fractal-cube" }, + .{ .name = "map-async" }, + .{ .name = "rgb-quad" }, + .{ + .name = "pbr-basic", + .deps = &.{ .model3d, .assets }, + .std_platform_only = true, + }, + .{ + .name = "deferred-rendering", + .deps = &.{ .model3d, .assets }, + .std_platform_only = true, + }, + .{ .name = "textured-cube", .deps = &.{ .zigimg, .assets } }, + .{ .name = "textured-quad", .deps = &.{ .zigimg, .assets } }, + .{ .name = "sprite2d", .deps = &.{ .zigimg, .assets } }, + .{ .name = "image", .deps = &.{ .zigimg, .assets } }, + .{ .name = "image-blur", .deps = &.{ .zigimg, .assets } }, + .{ .name = "cubemap", .deps = &.{ .zigimg, .assets } }, + + // sysgpu + .{ .name = "boids", .sysgpu = true }, + .{ .name = "clear-color", .sysgpu = true }, + .{ .name = "cubemap", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "deferred-rendering", .deps = &.{ .model3d, .assets }, .std_platform_only = true, .sysgpu = true }, + .{ .name = "fractal-cube", .sysgpu = true }, + .{ .name = "gen-texture-light", .sysgpu = true }, + .{ .name = "image-blur", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "instanced-cube", .sysgpu = true }, + .{ .name = "map-async", .sysgpu = true }, + .{ .name = "pbr-basic", .deps = &.{ .model3d, .assets }, .std_platform_only = true, .sysgpu = true }, + .{ .name = "pixel-post-process", .sysgpu = true }, + .{ .name = "procedural-primitives", .sysgpu = true }, + .{ .name = "rotating-cube", .sysgpu = true }, + .{ .name = "sprite2d", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "image", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "textured-cube", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "textured-quad", .deps = &.{ .zigimg, .assets }, .sysgpu = true }, + .{ .name = "triangle", .sysgpu = true }, + .{ .name = "triangle-msaa", .sysgpu = true }, + .{ .name = "two-cubes", .sysgpu = true }, + .{ .name = "rgb-quad", .sysgpu = true }, + }) |example| { + // FIXME: this is workaround for a problem that some examples + // (having the std_platform_only=true field) as well as zigimg + // uses IO and depends on gpu-dawn which is not supported + // in freestanding environments. So break out of this loop + // as soon as any such examples is found. This does means that any + // example which works on wasm should be placed before those who dont. + if (example.std_platform_only) + if (target.result.cpu.arch == .wasm32) + break; + + var deps = std.ArrayList(std.Build.Module.Import).init(b.allocator); + try deps.append(std.Build.Module.Import{ + .name = "zmath", + .module = b.createModule(.{ + .root_source_file = .{ .path = "src/core/examples/zmath.zig" }, + }), + }); + for (example.deps) |d| try deps.append(d.dependency(b, target, optimize)); + const cmd_name = if (example.sysgpu) "sysgpu-" ++ example.name else example.name; + const app = try CoreApp.init( + b, + b, + .{ + .name = "core-" ++ cmd_name, + .src = if (example.sysgpu) + "src/core/examples/sysgpu/" ++ example.name ++ "/main.zig" + else + "src/core/examples/" ++ example.name ++ "/main.zig", + .target = target, + .optimize = optimize, + .deps = deps.items, + .watch_paths = if (example.sysgpu) + &.{"src/core/examples/sysgpu/" ++ example.name} + else + &.{"src/core/examples/" ++ example.name}, + .mach_mod = mach_mod, + .platform = platform, + }, + ); + + for (example.deps) |dep| switch (dep) { + .model3d => app.compile.linkLibrary(b.dependency("mach_model3d", .{ + .target = target, + .optimize = optimize, + }).artifact("mach-model3d")), + else => {}, + }; + + const install_step = b.step("core-" ++ cmd_name, "Install core-" ++ cmd_name); + install_step.dependOn(&app.install.step); + b.getInstallStep().dependOn(install_step); + + const run_step = b.step("run-core-" ++ cmd_name, "Run core-" ++ cmd_name); + run_step.dependOn(&app.run.step); + } +} + +// TODO(Zig 2024.03): use b.lazyDependency +fn ensureDependencies(allocator: std.mem.Allocator) !void { + try optional_dependency.ensureGitRepoCloned( + allocator, + "https://github.com/slimsag/zigimg", + "ad6ad042662856f55a4d67499f1c4606c9951031", + sdkPath("/src/core/examples/libs/zigimg"), + ); +} + +// TODO(Zig 2024.03): use b.lazyDependency +const optional_dependency = struct { + fn ensureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, dir: []const u8) !void { + if (xIsEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or xIsEnvVarTruthy(allocator, "NO_ENSURE_GIT")) { + return; + } + + xEnsureGit(allocator); + + if (std.fs.openDirAbsolute(dir, .{})) |_| { + const current_revision = try xGetCurrentGitRevision(allocator, dir); + if (!std.mem.eql(u8, current_revision, revision)) { + // Reset to the desired revision + xExec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| std.debug.print("warning: failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) }); + try xExec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); + try xExec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); + } + return; + } else |err| return switch (err) { + error.FileNotFound => { + std.log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); + + try xExec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, "."); + try xExec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); + try xExec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); + return; + }, + else => err, + }; + } + + fn xExec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void { + var child = std.ChildProcess.init(argv, allocator); + child.cwd = cwd; + _ = try child.spawnAndWait(); + } + + fn xGetCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { + const result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd }); + allocator.free(result.stderr); + if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline + return result.stdout; + } + + fn xEnsureGit(allocator: std.mem.Allocator) void { + const argv = &[_][]const u8{ "git", "--version" }; + const result = std.ChildProcess.run(.{ + .allocator = allocator, + .argv = argv, + .cwd = ".", + }) catch { // e.g. FileNotFound + std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); + std.process.exit(1); + }; + defer { + allocator.free(result.stderr); + allocator.free(result.stdout); + } + if (result.term.Exited != 0) { + std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{}); + std.process.exit(1); + } + } + + fn xIsEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { + if (std.process.getEnvVarOwned(allocator, name)) |truthy| { + defer allocator.free(truthy); + if (std.mem.eql(u8, truthy, "true")) return true; + return false; + } else |_| { + return false; + } + } +}; diff --git a/build.zig.zon b/build.zig.zon index f877640d..e3efdc91 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -11,10 +11,6 @@ "README.md", }, .dependencies = .{ - .mach_core = .{ - .url = "https://pkg.machengine.org/mach-core/6a62bcc90e0d072d632788a6575d77942bd09a19.tar.gz", - .hash = "12209d39954fcda0be158461c10f64d14d5c7d097bd6d26785b332d75ffefa7dd7a0", - }, .mach_basisu = .{ .url = "https://pkg.machengine.org/mach-basisu/5a68105a5e503c7183aab481b7ec6ae16b996943.tar.gz", .hash = "12204098c8d8d15a687068a3c0b15fe95d20f8fe074531e34e78f9dfe518cf86a67c", @@ -63,5 +59,29 @@ .url = "https://pkg.machengine.org/SPIRV-Tools/23092f85a721e5297f0f704d95bbd263d5a7a771.tar.gz", .hash = "1220ec815dfda171b5bf65f6078932d79e034508e9ecef51be660f6a89cc7c70aef9", }, + .mach_gpu = .{ + .url = "https://pkg.machengine.org/mach-gpu/47244d1e216284a3389bd42af431f59f39a8f67e.tar.gz", + .hash = "1220e77a3e8386f57f73685026e43a17385ec8b3fb6e9873c9c793defd30651cfa09", + }, + .mach_glfw = .{ + .url = "https://pkg.machengine.org/mach-glfw/63da35e57c3695a787b927e69e4140eb74ffc234.tar.gz", + .hash = "1220fda87b59df6353864651cdd3943f1159d8d517a45cd67bed493fe6c0a0c78c17", + }, + .x11_headers = .{ + .url = "https://pkg.machengine.org/x11-headers/39d69153febf15537a33b425c57a3831e4a0ab2a.tar.gz", + .hash = "1220e83ec1e5addab76d30aad3adbbb02ee44fef30d90425c898670e48b495e42027", + }, + .wayland_headers = .{ + .url = "https://pkg.machengine.org/wayland-headers/7be286aec43c92bf3a88dad33fe63ce05c65aa28.tar.gz", + .hash = "1220228ca2235b82b3cf5d58995e34ac862afd18f1390c09b69a03f2a5ec06ff7701", + }, + .mach_core_example_assets = .{ + .url = "https://pkg.machengine.org/mach-core-example-assets/4beb172383b0012b256a26c59bf7bb97426436b8.tar.gz", + .hash = "122038828e74ad3854361cefbceab0a1d7c2db80c9864772693b8b47ebc6c82d3ccb", + }, + .mach_model3d = .{ + .url = "https://pkg.machengine.org/mach-model3d/04a493eb6c1a46b7f06f862b5e4d6bfcebad4cb5.tar.gz", + .hash = "12204725f8a000dc5e27e5d7e68dc2d26a9db904639f18e8866d5d540edae629d149", + }, }, } diff --git a/src/engine.zig b/src/engine.zig index c89532af..4bb83c20 100644 --- a/src/engine.zig +++ b/src/engine.zig @@ -1,7 +1,8 @@ -const core = @import("mach-core"); -const gpu = @import("mach-core").gpu; const std = @import("std"); -const ecs = @import("../main.zig").ecs; +const mach = @import("../main.zig"); +const core = mach.core; +const gpu = mach.core.gpu; +const ecs = mach.ecs; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); diff --git a/src/gfx/Sprite.zig b/src/gfx/Sprite.zig index 6f2e91a9..ea31516c 100644 --- a/src/gfx/Sprite.zig +++ b/src/gfx/Sprite.zig @@ -1,9 +1,9 @@ const std = @import("std"); -const core = @import("mach-core"); -const gpu = core.gpu; -const ecs = @import("../main.zig").ecs; -const Engine = @import("../engine.zig").Engine; const mach = @import("../main.zig"); +const core = mach.core; +const gpu = mach.core.gpu; +const ecs = mach.ecs; +const Engine = mach.Engine; const math = mach.math; const vec2 = math.vec2; diff --git a/src/main.zig b/src/main.zig index 18b416f0..e63f502c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,7 +2,7 @@ const build_options = @import("build-options"); const builtin = @import("builtin"); // Core -pub const core = if (build_options.want_core) @import("mach-core") else struct {}; +pub const core = if (build_options.want_core) @import("core/main.zig") else struct {}; pub const Timer = if (build_options.want_core) core.Timer else struct {}; pub const gpu = if (build_options.want_core) core.gpu else struct {}; pub const sysjs = if (build_options.want_core) @import("mach-sysjs") else struct {};