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

Use Zig package manager #38

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

jmrico01
Copy link

@jmrico01 jmrico01 commented Jan 28, 2024

This is my attempt/take on reworking the build script to support the new Zig package manager and ditch git submodules. Supporting a native build was pretty easy, but I read through the comments on #15 and figured I'd try to also add a more ergonomic way of building a raylib project for the WASM+emscripten target.

I've wrapped everything under a function setup, which takes over the creation of the compile step, but still returns it back so you can customize things further (e.g. adding custom module imports). Taking over the compile step is necessary because of the fancier build/link step required for emscripten.

I set up a minimal example project here - hopefully it's clear enough: https://github.com/kapricorn-media/raylib-sample

Closes #14
Tested with zig version 0.12.0-dev.2063+804cee3b9

NOTE: Seems like the marshal.h/marshal.c files were meant as a workaround to some WASM build issues, and ideally wouldn't be necessary? Zig seems to be compiling marshal.c just fine and the resulting emscripten sample runs correctly, so maybe this is worth revisiting. That seemed too ambitious to attempt in this same PR though.

@jmrico01 jmrico01 changed the title Package manager Use Zig package manager Jan 28, 2024
@jmrico01 jmrico01 marked this pull request as ready for review January 28, 2024 05:20
std.log.info("include '{s}' to {s}", .{ cwd, lib.name });
return lib;
}
fn emscriptenRunStep(b: *std.Build) !*std.Build.Step.Run {
Copy link
Author

Choose a reason for hiding this comment

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

I snatched these emscripten utility functions from https://github.com/Not-Nik/raylib-zig/blob/devel/build.zig

@schmee
Copy link

schmee commented Jan 28, 2024

Excited for this! 🎉 I'll take it for a spin and report back any issues.

EDIT: just tried it out on a small test project of mine by following the new README and everything worked out of the box 👌

@CashWasabi
Copy link

Super awesome PR! I was recently trying to do this myself but struggled a bit to get it working.
I'm not sure if it is important but would it make sense to also add the reason why you probably picked the support for 0.12.0-dev.2063+804cee3b9 to have compatibility with zig-gamedev and mach? https://github.com/zig-gamedev/zig-gamedev

@mobiuscog
Copy link

This PR helped me use the new package managment. I added the zon entry via:
zig fetch --save 'https://github.com/ryupold/raylib.zig/archive/44360a577aec4916e32337f9a900cd407aca4e13.tar.gz'

The main stalling points where that the build.zig changed obliterate the default flow, and it would be nice to just have the dependency be 'added' rather than needing to replace all of the default build options. Also I was missing various system dependencies, but that's likely another topic.

Overall, I think this PR brings value towards a much more streamlined package for the latest zig updates, and with a few changed could really simplify usage.

@schmee
Copy link

schmee commented Feb 25, 2024

I'm also using it for https://github.com/schmee/zig-raylib-imgui-template/.

@Ev1lT3rm1nal
Copy link
Contributor

@ryupold what about this?

@deevus deevus mentioned this pull request Apr 2, 2024
3 tasks
@apotema
Copy link
Contributor

apotema commented Jun 4, 2024

@ryupold can we approve this?

@tkgalk
Copy link

tkgalk commented Jun 6, 2024

There are open issues for months now. Last commit is also from 5 months ago. Might be the original maintainer's available time/goals changed.

@jmrico01
Copy link
Author

Hi all, thank you for all the comments! FYI, I've decided to move to using raylib's C APIs directly instead of using any Zig bindings. 2 reasons:

  • raylib now comes with a well testedbuild.zig and work nicely out of the box with the latest zig & package manager.
  • I needed to import and use some more niche/low-level functions in raylib, so the bindings were getting in my way.

Still happy to address any comments needed to merge this PR if they come up, but probably won't need to use these bindings anymore, and will just write my own small glue code as needed.

@apotema
Copy link
Contributor

apotema commented Jun 22, 2024

Hi @jmrico01
Having an example of how you do this direct integration would be nice.

@jmrico01
Copy link
Author

Hi @jmrico01 Having an example of how you do this direct integration would be nice.

Sure! This is pretty much what I'm using as a baseline. Very simple and minimal setup:
https://github.com/kapricorn-media/sample-raylib-zig

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.

Update to support official Zig package manager
7 participants