Does not work on NixOS due to non standard FHS
Closed this issue · 2 comments
devins2518 commented
build.zig
const std = @import("std");
const Sdk = @import("sdl/Sdk.zig");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const sdk = Sdk.init(b);
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("ziggyboy", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
sdk.link(exe, .static);
exe.addPackage(sdk.getNativePackage("sdl2"));
// exe.linkSystemLibrary("SDL2");
// exe.linkSystemLibrary("c");
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const tests = b.addTest("src/main.zig");
tests.setBuildMode(mode);
const test_step = b.step("test", "Run all the tests");
test_step.dependOn(&tests.step);
}
Error from LLD
ld.lld: error: unable to find library -lsdl2
error: LLDReportedFailure
ziggyboy...The following command exited with error code 1:
/nix/store/rfpl182slqas5nq68xbla2901jc6f6c6-zig-master-unstable-2021-06-27/bin/zig build-exe /home/devin/Repos/ziggyboy/src/main.zig -lc -lsdl2 --cache-dir /home/devin/Repos/ziggyboy/zig-cache --global-cache-dir /home/devin/.cache/zig --name ziggyboy --enable-cache
error: the following build command failed with exit code 1:
/home/devin/Repos/ziggyboy/zig-cache/o/fd09d5499e7e1e5f701e4b7c647cdf96/build /nix/store/rfpl182slqas5nq68xbla2901jc6f6c6-zig-master-unstable-2021-06-27/bin/zig /home/devin/Repos/ziggyboy /home/devin/Repos/ziggyboy/zig-cache /home/devin/.cache/zig
My shell.nix
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [ SDL2 pkgconf ];
NIX_LD_LIBRARY_PATH =
pkgs.lib.makeLibraryPath [ pkgs.pkgconf pkgs.SDL2 pkgs.lld ];
NIX_LD = builtins.readFile "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
}
Using Andrew's build.zig as an example, linking them as system libraries does compile using the shell.nix.
exe.linkSystemLibrary("SDL2");
exe.linkSystemLibrary("c");
Might be related to NixOS/nixpkgs#24744
devins2518 commented
Actually it seems that just changing line 229 fixes it, but I'm not sure if this is portable to other distros.
- exe.linkSystemLibrary("sdl2");
+ exe.linkSystemLibrary("SDL2");
ikskuh commented
Afaik the official pkg-config
name is SDL2
, not sdl2
. This means that NixOS isn't compatible here to other linux distributions having pkg-config
.
It would be a good idea to verify this and maybe file a bug report to NixOS