Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EMSDK and add Emmaloc #1

Merged
merged 9 commits into from
Feb 3, 2025
Merged

Conversation

ckrowland
Copy link
Contributor

My best attempt at incorporating deins zig-gamedev/zig-gamedev#309 (comment) pull request to allow for emscripten builds.

My shell_minimal.html file is what I use to size canvas to the browser size. We should add the basic emscripten html file as well.

@ckrowland ckrowland changed the title Update EMSDK and add basic html file Update EMSDK Dec 14, 2024
@ckrowland ckrowland changed the title Update EMSDK Update EMSDK and add Emmaloc Dec 14, 2024
Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just some nitpicks

@ckrowland
Copy link
Contributor Author

ckrowland commented Dec 16, 2024

Will get to this soon. Just a note to myself, update the EMSDK zig-gamedev .zon package to 3.1.73 when this is approved.

build.zig Outdated
pub const emsdk_version = emsdk_ver_major ++ "." ++ emsdk_ver_minor ++ "." ++ emsdk_ver_tiny;

pub fn build(b: *std.Build) void {
_ = b.addModule("root", .{ .root_source_file = b.path("src/zemscripten.zig") });
_ = b.addModule("dummy", .{ .root_source_file = b.path("src/dummy.zig") });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is dummy.zig for?

Copy link
Contributor Author

@ckrowland ckrowland Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you run natively, @import("zemscripten") imports the dummy.zig instead of zemscripten.zig, so you can run both natively and emscripten in the same program. There might be a better way to do this. We could make it so that importing zemscripten means only a emscripten build could run. I forgot to add to the README, when you build like this it would look like

const zemscripten = b.dependency("zemscripten", .{});
if (target.result.os.tag != .emscripten) {
    exe.root_module.addImport("zemscripten", zemscripten.module("dummy"));
} else {
    exe.root_module.addImport("zemscripten", zemscripten.module("root"));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple main files is the strategy I use in personal projects. I also intend to refactor the zig-gamedev samples to be like sdl2_demo (https://github.com/zig-gamedev/zig-gamedev/tree/main/samples/sdl2_demo/src).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah I do the same thing. So safe to remove dummy.zig?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think so. We could put it back if it is useful to someone later.

Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@hazeycode hazeycode merged commit 8a4dd0c into zig-gamedev:main Feb 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants