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

Add support for Zig 1.13 & update Raylib to latest #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AtishaRibeiro
Copy link

@AtishaRibeiro AtishaRibeiro commented Jun 12, 2024

Continued on #41

Changes:

  • update raylib
  • add .zig-cache to .gititnore
  • add build.zig.zon to readme, this is now needed with the latest raylib
  • use LazyPath's
  • ComptimeStringMap to StaticStringMap

These changes do mean that this is not backwards compatible with zig 0.12

@SortexGuy
Copy link

Hey, this gives me an error compiling with 0.13.0, with all the instructions from the pr readme

/home/sortextg/CodeProjects/Zig/ttd-try/raylib-zig/build.zig:90:30: error: no module named 'raylib' available within module root
.@dependencies.12209a3f18311ae936972e404a8e4129d2d4da4898acf769582c0432b47bab69c347
const raylib_build = @import("raylib");
                             ^~~~~~~~
referenced by:
    addTo__anon_14251: /home/sortextg/CodeProjects/Zig/ttd-try/raylib-zig/build.zig:114:24
    build: /home/sortextg/CodeProjects/Zig/ttd-try/build.zig:41:17
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

I noticed the pr didn't have a build.zig.zon itself, maybe i'm doing something wrong but it doesn't build out of the box

@AtishaRibeiro
Copy link
Author

I can't tell from your snippet but your zig.zon needs to be in the root of your project, not of raylib.zig
So it would look like:

project
- `build.zig.zon`
- `raylib-zig`
  - `raylib`

There's probably a better way of doing this where you put the zon file in raylib-zig but I couldn't figure it out

@WeijieH
Copy link

WeijieH commented Jul 1, 2024

Still not working. Here is what I done.

  1. make a new folder.
    $ mkdir zig_ray
    $ cd zig_ray

  2. git init

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>

  1. Add your git repo git submodule add https://github.com/AtishaRibeiro/raylib.zig raylib
Cloning into '/mnt/zig_ray/raylib'...
remote: Enumerating objects: 717, done.
remote: Counting objects: 100% (244/244), done.
remote: Compressing objects: 100% (82/82), done.
remote: Total 717 (delta 193), reused 184 (delta 162), pack-reused 473
Receiving objects: 100% (717/717), 1.48 MiB | 7.63 MiB/s, done.
Resolving deltas: 100% (534/534), done.
  1. Update git git submodule update --init --recursive
Submodule 'raylib' (https://github.com/raysan5/raylib) registered for path 'raylib/raylib'
Cloning into '/mnt/zig_ray/raylib/raylib'...
Submodule path 'raylib/raylib': checked out '735c0160b5cc5fa2a2cdd60843d61afa25551991'
  1. Using zig init to generate the base file structure zig init
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
  1. Edit the files as you have mentioned.
    build.zig
const std = @import("std");
const raylib = @import("raylib/build.zig");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const exe = b.addExecutable(.{
        .name = "zig_ray",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    raylib.addTo(b, exe, target, optimize, .{});
}

build.zig.zon

.{
    // This is the default name used by packages depending on this one. For
    // example, when a user runs `zig fetch --save <url>`, this field is used
    // as the key in the `dependencies` table. Although the user can choose a
    // different name, most users will stick with this provided value.
    //
    // It is redundant to include "zig" in this name because it is already
    // within the Zig package namespace.
    .name = "zig_ray",

    // This is a [Semantic Version](https://semver.org/).
    // In a future version of Zig it will be used for package deduplication.
    .version = "0.0.0",

    // This field is optional.
    // This is currently advisory only; Zig does not yet do anything
    // with this value.
    //.minimum_zig_version = "0.11.0",

    // This field is optional.
    // Each dependency must either provide a `url` and `hash`, or a `path`.
    // `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
    // Once all dependencies are fetched, `zig build` no longer requires
    // internet connectivity.
    .dependencies = .{
        .raylib = .{
            // Path to the raylib submodule inside of this repo
            .path = "raylib",
        },
        // Only needed when using raygui
        // .raygui = .{
        //     .path = "path/to/raygui",
        // },
    },

    // Specifies the set of files and directories that are included in this package.
    // Only files and directories listed here are included in the `hash` that
    // is computed for this package. Only files listed here will remain on disk
    // when using the zig package manager. As a rule of thumb, one should list
    // files required for compilation plus any license(s).
    // Paths are relative to the build root. Use the empty string (`""`) to refer to
    // the build root itself.
    // A directory listed here means that all files within, recursively, are included.
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
        // For example...
        //"LICENSE",
        //"README.md",
    },
}
  1. Run zig build
/mnt/zig_ray/raylib/build.zig:1:1: error: file exists in multiple modules
/mnt/zig_ray/raylib/build.zig:1:1: note: root of module root.@dependencies.12202097d817adcf30a420dfb63266dd3402de94a1012736204749fdd76f41d37bd0
/mnt/zig_ray/build.zig:2:24: note: imported from module root.@build
const raylib = @import("raylib/build.zig");
  1. My zig version is 0.13.0
  2. Here is the result of tree -L 2
.
├── build.zig
├── build.zig.zon
├── raylib
│   ├── LICENSE
│   ├── README.md
│   ├── bindings.json
│   ├── build.zig
│   ├── emscripten
│   ├── generate.zig
│   ├── gui_icons.h
│   ├── inject.c
│   ├── inject.h
│   ├── inject.zig
│   ├── intermediate.zig
│   ├── logo.png
│   ├── marshal.c
│   ├── marshal.h
│   ├── raylib
│   ├── raylib.json
│   ├── raylib.zig
│   ├── raylib_parser.zig
│   ├── raymath.json
│   ├── rlgl.json
│   └── type_mapping.zig
└── src
    ├── main.zig
    └── root.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.

None yet

3 participants