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

Package request: slang #359925

Closed
ArchercatNEO opened this issue Nov 28, 2024 · 3 comments · Fixed by #358202
Closed

Package request: slang #359925

ArchercatNEO opened this issue Nov 28, 2024 · 3 comments · Fixed by #358202
Labels
0.kind: packaging request Request for a new package to be added

Comments

@ArchercatNEO
Copy link
Contributor

Project description

Slang is a shading language now maintained by khronos intended to make shader programming easier and more maintainable.
slangc is the official compiler for the language.

Metadata


Note for maintainers: Please tag this issue in your PR.


Add a 👍 reaction to issues you find important.

@ArchercatNEO ArchercatNEO added the 0.kind: packaging request Request for a new package to be added label Nov 28, 2024
@pluiedev
Copy link
Contributor

I've tried my hand at this and it's not a particularly hard build if you use vendored dependencies, but let's try to avoid doing that in Nixpkgs if possible.

Right now I've figured out how to de-vendor miniz and lz4, though unordered_dense needs to be packaged first, and then for some bizarre reason it wants to link against vulkan-headers despite it being header-only, and then it couldn't find system spirv-headers. CUDA & NVAPI support would probably also be important.

Regarding #359938 (@ArchercatNEO), I think something like shader-slang would work for now, although the name is definitely up for debate.

My partial derivation:

{
  lib,
  llvmPackages_13,
  fetchFromGitHub,

  cmake,
  ninja,
  pkg-config,
  python3,
  tree,

  libllvm,
  miniz,
  lz4,
  vulkan-headers,
  spirv-headers,
  xorg,

  enableCUDA ? false,
}:
let 
  inherit (llvmPackages_13) stdenv;

  lz4-static = lz4.overrideAttrs (prev: {
    outputs = ["out"];
    cmakeFlags = (prev.cmakeFlags or []) ++ [
      (lib.cmakeBool "LZ4_BUNDLED_MODE" true)
    ];
    installPhase = ''
      runHook preInstall
      install -D liblz4.a $out/lib/liblz4_static.a
      runHook postInstall
    '';
  });
in
stdenv.mkDerivation (finalAttrs: {
  pname = "slang";
  version = "2024.14.6";

  src = fetchFromGitHub {
    owner = "shader-slang";
    repo = "slang";
    rev = "refs/tags/v${finalAttrs.version}";
    # hash = "sha256-ynq1YGgXD9f6+/lJSt4kFfs2N4QfzoyHOBbMT+4Flt4=";
    # TODO: fix this
    hash = "sha256-q/FR7CA3FddbHBmINOqQqfmOhlusswv3femKFax2AnM=";
    fetchSubmodules = true;
  };

  nativeBuildInputs = [
    cmake
    ninja
    pkg-config
    python3
    # llvmPackages_13.lld
  ];

  buildInputs = [
    llvmPackages_13.libllvm
    llvmPackages_13.libclang
    miniz
    lz4.dev
    lz4-static
    vulkan-headers
    spirv-headers

    # TODO: nvcc, OptiX, NVAPI, Aftermath
  ] ++ lib.optional stdenv.hostPlatform.isLinux xorg.libX11;

  cmakeFlags = [
    (lib.cmakeFeature "SLANG_VERSION_FULL" "${finalAttrs.version}")
    (lib.cmakeFeature "SLANG_SLANG_LLVM_FLAVOR" "USE_SYSTEM_LLVM")
    # (lib.cmakeBool "SLANG_USE_SYSTEM_UNORDERED_DENSE" true)
    (lib.cmakeBool "SLANG_USE_SYSTEM_MINIZ" true)
    (lib.cmakeBool "SLANG_USE_SYSTEM_LZ4" true)
    # (lib.cmakeBool "SLANG_USE_SYSTEM_VULKAN_HEADERS" true) # Wants to link against Vulkan-Headers
    # (lib.cmakeBool "SLANG_USE_SYSTEM_SPIRV_HEADERS" true) # Missing Cmake
    (lib.cmakeFeature "SLANG_SPIRV_HEADERS_INCLUDE_DIR" "${spirv-headers}/include")
  ];

  env.NIX_CFLAGS_COMPILE = toString [
    "-I${miniz}/include/miniz"
  ];
})

@ArchercatNEO
Copy link
Contributor Author

Interesting, though I can’t find nvcc with nix-locate as of now, optix requires that, nvapi is (apparently) windows-only and I didn’t look for aftermath. This definitely seems like a drv that’s better made than mine though so congrats on that.

@niklaskorz
Copy link
Contributor

See #358202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: packaging request Request for a new package to be added
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants