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

Does not work on NixOS due to non standard FHS #14

Closed
devins2518 opened this issue Oct 6, 2021 · 2 comments
Closed

Does not work on NixOS due to non standard FHS #14

devins2518 opened this issue Oct 6, 2021 · 2 comments

Comments

@devins2518
Copy link

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 devins2518 changed the title Does not workon NixOS due to non standard FHS Does not work on NixOS due to non standard FHS Oct 6, 2021
@devins2518
Copy link
Author

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
Copy link
Owner

ikskuh commented Oct 11, 2021

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

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

No branches or pull requests

2 participants