Commit graph

15 commits

Author SHA1 Message Date
Emi
b14f8e69ee build: add @import("mach").addExecutable helper
This adds a helper that can be used people's `build.zig` code, called `@import("mach").addExecutable`,
a direct replacement for `b.addExecutable`.

The benefits of using this method are:

1. Your `build.zig` code does not need to be aware of platform-specifics that may be required to build an executable,
   for example setting a Windows manifest to ensure your app is DPI-aware.
2. You do not need to write `main.zig` entrypoint code, which although simple today is expected to become more complex
   over time as we add support for more platforms. For example, WASM and other platforms require different entrypoints
   and this can account for that without your `build.zig` containing that logic.

Steps to use:

1. Delete your `main.zig` file.
2. Define your `Modules` as a public const in your `App.zig` file, e.g.:

```zig
// The set of Mach modules our application may use.
pub const Modules = mach.Modules(.{
    mach.Core,
    App,
});
```

3. Update your `build.zig` code to use `@import("mach").addExecutable` like so:

```zig
const std = @import("std");

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

    const app_mod = b.createModule(.{
        .root_source_file = b.path("src/App.zig"),
        .optimize = optimize,
        .target = target,
    });

    // Add Mach to our library and executable
    const mach_dep = b.dependency("mach", .{
        .target = target,
        .optimize = optimize,
    });
    app_mod.addImport("mach", mach_dep.module("mach"));

    // Use the Mach entrypoint to write main for us
    const exe = @import("mach").addExecutable(mach_dep.builder, .{
        .name = "hello-world",
        .app = app_mod,
        .target = target,
        .optimize = optimize,
    });
    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const app_unit_tests = b.addTest(.{
        .root_module = app_mod,
    });
    const run_app_unit_tests = b.addRunArtifact(app_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_app_unit_tests.step);
}
```

Signed-off-by: Emi <emi@hexops.com>
2025-02-17 20:57:14 -07:00
foxnne
19040cae25 darwin: temporarily set window background to be transparent. examples: Add core-transparent-window and remove input from core-triangle 2024-12-08 10:22:42 -07:00
foxnne
ad5700cf48 core: Remove main_window in favor of users creating their own windows. Added event window_open which is called when the platform has finished initializing the window 2024-12-01 18:32:15 -07:00
Stephen Gutekanst
281884e9b0 examples: core-triangle: cleanup width/height input handler
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-01 13:55:30 -07:00
foxnne
06aec428de core: windows: Get triangle showing, still freezing on run. Comment out more windows, set value of window back on presentFrame. 2024-12-01 12:19:50 -07:00
Colton Franklin
1fe47b2b19
obj: Move Platform and InitOptions fields into core.windows (#1309)
* obj: Make field tracking use a single bitset

* obj: module: fix comment

* obj: Move `Platform` state and `InitOptions` fields into `core.windows`, initial push, only triangle example working on macos currently

* obj: `get` and `getValue` (renamed `getAll`) now do not return optionals, comment revisions, `device` is no longer optional, `native` is optional

* core: Lots of cleanup of unnecessary comments

* core: `Event`s now all contain `window_id`, darwin/windows: event functions now send window id

* core: comments, examples: fix `core-custom-entrypoint`
2024-11-30 15:13:14 -07:00
foxnne
319f2d8fb8 triangle: Remove input keys to change window size, this was just a test 2024-11-27 18:30:53 -07:00
foxnne
0476999dc4 core: Allow tracking of individual struct fields for changes 2024-11-27 18:30:53 -07:00
Stephen Gutekanst
714f200bc1 module: implement cross-Object-pool graph relations
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Stephen Gutekanst
9d134dc72d module: object recycling
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Stephen Gutekanst
8054d03b4d unify mach.Call and mach.Runner into one type
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Stephen Gutekanst
14ccd5a93c settle module state initialization
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Stephen Gutekanst
0e12857154 examples/core: building without ECS
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Stephen Gutekanst
2a13c07d9e module: remove the ability to send "standard" arguments to systems
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-11-23 21:20:04 -07:00
Ronald M Zielaznicki
910e8f6e82 build: examples run independently & sysaudio examples renamed as tests 2024-10-29 21:55:40 -07:00