From 0048221026e22efad5b8539618dd54ce650956ba Mon Sep 17 00:00:00 2001 From: Alec Goncharow Date: Sun, 8 Sep 2024 20:11:39 -0400 Subject: compiles again --- .gitmodules | 3 +++ build.zig | 68 ++++++++++++++++++++++++++++++++++++++++++++----------- build.zig.zon | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ raylib | 1 + 4 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 build.zig.zon create mode 160000 raylib diff --git a/.gitmodules b/.gitmodules index e69de29..00a5561 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "raylib"] + path = raylib + url = https://github.com/raysan5/raylib.git diff --git a/build.zig b/build.zig index 048b263..762efee 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,33 @@ const std = @import("std"); -const raySdk = @import("raylib/src/build.zig"); +const raySdk = @import("raylib"); + +pub const Options = struct { + raudio: bool = true, + rmodels: bool = true, + rshapes: bool = true, + rtext: bool = true, + rtextures: bool = true, + platform_drm: bool = false, + shared: bool = false, + linux_display_backend: LinuxDisplayBackend = .X11, + opengl_version: OpenglVersion = .auto, +}; + +pub const OpenglVersion = enum { + auto, + gl_1_1, + gl_2_1, + gl_3_3, + gl_4_3, + gles_2, + gles_3, +}; + +pub const LinuxDisplayBackend = enum { + X11, + Wayland, +}; // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external @@ -16,23 +43,38 @@ pub fn build(b: *std.Build) !void { // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); - const defaults = raySdk.Options{}; - const options = raySdk.Options{ + const defaults = Options{}; + const options = Options{ .platform_drm = b.option(bool, "platform_drm", "Compile raylib in native mode (no X11)") orelse defaults.platform_drm, .raudio = b.option(bool, "raudio", "Compile with audio support") orelse defaults.raudio, .rmodels = b.option(bool, "rmodels", "Compile with models support") orelse defaults.rmodels, .rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext, .rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures, .rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes, - .raygui = b.option(bool, "raygui", "Compile with raygui support") orelse defaults.raygui, + .shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared, + .linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend, + .opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version, }; - const raylib = try raySdk.addRaylib(b, target, optimize, options); + + const raylib = b.dependency("raylib", .{ + .target = target, + .optimize = optimize, + .raudio = options.raudio, + .rmodels = options.rmodels, + .rshapes = options.rshapes, + .rtext = options.rtext, + .rtextures = options.rtextures, + .platform_drm = options.platform_drm, + .shared = options.shared, + .linux_display_backend = options.linux_display_backend, + .opengl_version = options.opengl_version, + }); const lib = b.addStaticLibrary(.{ - .name = "zigdown", + .name = "shipit", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. - .root_source_file = .{ .path = "src/root.zig" }, + .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }); @@ -46,7 +88,7 @@ pub fn build(b: *std.Build) !void { .name = "zig-raylib", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -56,15 +98,15 @@ pub fn build(b: *std.Build) !void { .name = "zig-raylib", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); const check = b.step("check", "Check if it compiles"); check.dependOn(&exe_check.step); - exe.addIncludePath(.{ .path = "raylib/src" }); - exe.linkLibrary(raylib); + exe.addIncludePath(b.path("raylib/src")); + exe.linkLibrary(raylib.artifact("raylib")); // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default @@ -97,14 +139,14 @@ pub fn build(b: *std.Build) !void { // Creates a step for unit testing. This only builds the test executable // but does not run it. const lib_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/root.zig" }, + .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }); const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..1d0f7c2 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,73 @@ +.{ + // This is the default name used by packages depending on this one. For + // example, when a user runs `zig fetch --save `, 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 = "shipit", + + // 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 = .{ + // See `zig fetch --save ` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + // + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + .raylib = .{ .path = "raylib" }, + }, + + // 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", + }, +} diff --git a/raylib b/raylib new file mode 160000 index 0000000..0656440 --- /dev/null +++ b/raylib @@ -0,0 +1 @@ +Subproject commit 0656440e38208e4d57201706520eb0571fb13bd9 -- cgit v1.2.3-70-g09d2