Skip to content

Commit

Permalink
build.zig: let user decide how to set build mode + fix linker warning (
Browse files Browse the repository at this point in the history
…#2763)

* build.zig: let user decide how to set build mode

This should delegate the responsibility of calling `standardReleaseOptions` and setting the build mode of the `*LibExeObjStep` step to the caller, especially since this might not be the process by which one wants to determine the build mode.

Also changes hides `getSrcDir` to enforce usage of `srcdir`, and asserts that the file is in fact inside a directory.

* build.zig: set root_src param to `null`

Supplying the header file as the root source here appears to cause a linker warning of the form:
```
LLD Link... warning(link): unexpected LLD stderr:
ld.lld: warning: {build_root}/zig-cache/o/{hash}/libraylib.a: archive member '{build_root}/zig-cache/o/{hash}/raylib.o' is neither ET_REL nor LLVM bitcode
```
Passing `null` instead fixes it.
  • Loading branch information
InKryption authored Oct 20, 2022
1 parent b8e14a4 commit 40cf84e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/build.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const std = @import("std");

pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-DPLATFORM_DESKTOP",
Expand All @@ -13,9 +9,8 @@ pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
};

const raylib = b.addStaticLibrary("raylib", srcdir ++ "/raylib.h");
const raylib = b.addStaticLibrary("raylib", null);
raylib.setTarget(target);
raylib.setBuildMode(mode);
raylib.linkLibC();

raylib.addIncludePath(srcdir ++ "/external/glfw/include");
Expand Down Expand Up @@ -90,8 +85,8 @@ pub fn build(b: *std.build.Builder) void {
lib.install();
}

const srcdir = getSrcDir();

fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
const srcdir = struct{
fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file).?;
}
}.getSrcDir();

0 comments on commit 40cf84e

Please sign in to comment.