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

@christiannicola
Copy link

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>
3. 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.
4. 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'
5. 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
6. 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",
    },
}
7. 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");
8. My zig version is `0.13.0`

9. 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

The path for the dependecy in build.zig.zon needs to be updated, it is mentioned in the README.

.dependencies = .{
        .raylib = .{
            // Path to the raylib submodule inside of this repo
            .path = "raylib/raylib",
        },
        // Only needed when using raygui
        // .raygui = .{
        //     .path = "path/to/raygui",
        // },
    },

@mbekkomo mbekkomo mentioned this pull request Aug 24, 2024
@MarcPer
Copy link

MarcPer commented Oct 3, 2024

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

@AtishaRibeiro I noticed in your message that you seem to be importing the submodule with the name raylib-zig instead of raylib, as it says in the README, so I ran this:

git submodule add -f https://github.com/AtishaRibeiro/raylib.zig raylib-zig

That took care of the file exists in multiple modules error, but now I'm back to this one:

myproject/build.zig:13:26: error: expected type 'Target.Query', found 'Build.ResolvedTarget'
    raylib.addTo(b, exe, target, optimize, .{});
                         ^~~~~~
/path/to/zig/lib/std/Build.zig:2523:28: note: struct declared here
pub const ResolvedTarget = struct {
                           ^~~~~~
/path/to/zig/lib/std/Target/Query.zig:1:1: note: struct declared here
//! Contains all the same data as `Target`, additionally introducing the
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
myproject/raylib-zig/build.zig:113:77: note: parameter type declared here
pub fn addTo(b: *std.Build, exe: *std.Build.Step.Compile, target: std.Target.Query, optimize: std.builtin.Mode, raylibOptions: anytype) void {

Also using zig 0.13.0.

Just wondering if you have any hints. Thank you for opening this PR!

@MarcPer
Copy link

MarcPer commented Oct 3, 2024

I resolved the error: expected type 'Target.Query', found 'Build.ResolvedTarget' by updating raylib-zig/build.zig as follows:

diff --git a/build.zig b/build.zig
index 2170cf8..7eb96cc 100644
--- a/build.zig
+++ b/build.zig
@@ -89,11 +89,11 @@ const dir_raylib = cwd ++ sep ++ "raylib" ++ sep ++ "src";

 const raylib_build = @import("raylib");

-fn linkThisLibrary(b: *std.Build, target: std.Target.Query, optimize: std.builtin.Mode) *std.Build.Step.Compile {
+fn linkThisLibrary(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode) *std.Build.Step.Compile {
     const lib = b.addStaticLibrary(
         .{
             .name = "raylib.zig",
-            .target = b.resolveTargetQuery(target),
+            .target = target,
             .optimize = optimize,
             .root_source_file = std.Build.LazyPath{
                 .cwd_relative = cwd ++ sep ++ "raylib.zig",
@@ -110,10 +110,10 @@ fn linkThisLibrary(b: *std.Build, target: std.Target.Query, optimize: std.builti
 }

 /// add this package to exe
-pub fn addTo(b: *std.Build, exe: *std.Build.Step.Compile, target: std.Target.Query, optimize: std.builtin.Mode, raylibOptions: anytype) void {
+pub fn addTo(b: *std.Build, exe: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.Mode, raylibOptions: anytype) void {
     const lib_raylib = raylib_build.addRaylib(
         b,
-        b.resolveTargetQuery(target),
+        target,
         optimize,
         raylibOptions,
     ) catch |err| std.debug.panic("addRaylib: {any}", .{err});

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.

5 participants