Skip to content

Commit

Permalink
Merge branch 'raysan5:master' into pure
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley authored Nov 10, 2024
2 parents 002bb81 + 2af4f31 commit 3c2aa5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 61 deletions.
85 changes: 25 additions & 60 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,6 @@ comptime {
@compileError("Raylib requires zig version " ++ min_ver);
}

// NOTE(freakmangd): I don't like using a global here, but it prevents having to
// get the flags a second time when adding raygui
var raylib_flags_arr: std.ArrayListUnmanaged([]const u8) = .{};

// This has been tested with zig version 0.13.0
pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
const raylib_dep = b.dependencyFromBuildZig(@This(), .{
.target = target,
.optimize = optimize,
.raudio = options.raudio,
.rmodels = options.rmodels,
.rshapes = options.rshapes,
.rtext = options.rtext,
.rtextures = options.rtextures,
.platform = options.platform,
.shared = options.shared,
.linux_display_backend = options.linux_display_backend,
.opengl_version = options.opengl_version,
.config = options.config,
});
const raylib = raylib_dep.artifact("raylib");

if (options.raygui) {
const raygui_dep = b.dependency(options.raygui_dependency_name, .{});
addRaygui(b, raylib, raygui_dep);
}

return raylib;
}

fn setDesktopPlatform(raylib: *std.Build.Step.Compile, platform: PlatformBackend) void {
raylib.defineCMacro("PLATFORM_DESKTOP", null);

Expand Down Expand Up @@ -107,21 +77,26 @@ const config_h_flags = outer: {
};

fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
raylib_flags_arr.clearRetainingCapacity();
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
defer raylib_flags_arr.deinit();

const shared_flags = &[_][]const u8{
"-fPIC",
"-DBUILD_LIBTYPE_SHARED",
};
try raylib_flags_arr.appendSlice(b.allocator, &[_][]const u8{
try raylib_flags_arr.appendSlice(&[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
});

if (options.shared) {
try raylib_flags_arr.appendSlice(&[_][]const u8{
"-fPIC",
"-DBUILD_LIBTYPE_SHARED",
});
}

if (options.config.len > 0) {
// Sets a flag indiciating the use of a custom `config.h`
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
try raylib_flags_arr.append("-DEXTERNAL_CONFIG_FLAGS");

// Splits a space-separated list of config flags into multiple flags
//
Expand All @@ -131,7 +106,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.

// Apply config flags supplied by the user
while (config_iter.next()) |config_flag|
try raylib_flags_arr.append(b.allocator, config_flag);
try raylib_flags_arr.append(config_flag);

// Apply all relevant configs from `src/config.h` *except* the user-specified ones
//
Expand All @@ -149,14 +124,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
}

// Otherwise, append default value from config.h to compile flags
try raylib_flags_arr.append(b.allocator, flag);
try raylib_flags_arr.append(flag);
}
}

if (options.shared) {
try raylib_flags_arr.appendSlice(b.allocator, shared_flags);
}

const raylib = if (options.shared)
b.addSharedLibrary(.{
.name = "raylib",
Expand Down Expand Up @@ -288,7 +259,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
}

// On macos rglfw.c include Objective-C files.
try raylib_flags_arr.append(b.allocator, "-ObjC");
try raylib_flags_arr.append("-ObjC");
raylib.root_module.addCSourceFile(.{
.file = b.path("src/rglfw.c"),
.flags = raylib_flags_arr.items,
Expand Down Expand Up @@ -327,25 +298,19 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
.flags = raylib_flags_arr.items,
});

return raylib;
}

/// This function does not need to be called if you passed .raygui = true to addRaylib
pub fn addRaygui(b: *std.Build, raylib: *std.Build.Step.Compile, raygui_dep: *std.Build.Dependency) void {
if (raylib_flags_arr.items.len == 0) {
@panic(
\\argument 2 `raylib` in `addRaygui` must come from b.dependency("raylib", ...).artifact("raylib")
);
}
if (options.raygui) {
const raygui_dep = b.dependency(options.raygui_dependency_name, .{});

var gen_step = b.addWriteFiles();
raylib.step.dependOn(&gen_step.step);
var gen_step = b.addWriteFiles();
raylib.step.dependOn(&gen_step.step);

const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items });
raylib.addIncludePath(raygui_dep.path("src"));
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.addCSourceFile(.{ .file = raygui_c_path, .flags = raylib_flags_arr.items });
raylib.addIncludePath(raygui_dep.path("src"));
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
}

raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
return raylib;
}

pub const Options = struct {
Expand Down
Binary file modified logo/raylib.ico
Binary file not shown.
Binary file modified logo/raylib_1024x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified logo/raylib_144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/rmodels.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
for (int i = 0; i < sides; i++)
{
rlVertex3f(0, 0, 0);
rlVertex3f(sinf(DEG2RAD*i*angleStep)*radiusBottom, 0, cosf(DEG2RAD*(i+1)*angleStep)*radiusBottom);
rlVertex3f(sinf(DEG2RAD*(i+1)*angleStep)*radiusBottom, 0, cosf(DEG2RAD*(i+1)*angleStep)*radiusBottom);
rlVertex3f(sinf(DEG2RAD*i*angleStep)*radiusBottom, 0, cosf(DEG2RAD*i*angleStep)*radiusBottom);
}

Expand Down

0 comments on commit 3c2aa5c

Please sign in to comment.