2022-02-20 05:27:41 +00:00
|
|
|
|
{ lib
|
2022-08-12 12:06:08 +00:00
|
|
|
|
, overrideCC
|
2022-02-20 05:27:41 +00:00
|
|
|
|
, stdenv
|
|
|
|
|
, fetchurl
|
|
|
|
|
, fetchFromGitHub
|
|
|
|
|
, cctools
|
|
|
|
|
, sigtool
|
|
|
|
|
, cereal
|
2022-08-12 12:06:08 +00:00
|
|
|
|
, libcxx
|
2022-02-20 05:27:41 +00:00
|
|
|
|
, glslang
|
|
|
|
|
, spirv-cross
|
|
|
|
|
, spirv-headers
|
|
|
|
|
, spirv-tools
|
|
|
|
|
, vulkan-headers
|
2022-08-12 12:06:08 +00:00
|
|
|
|
, xcbuild
|
2022-02-20 05:27:41 +00:00
|
|
|
|
, AppKit
|
|
|
|
|
, Foundation
|
2022-08-12 12:06:08 +00:00
|
|
|
|
, Libsystem
|
|
|
|
|
, MacOSX-SDK
|
2022-02-20 05:27:41 +00:00
|
|
|
|
, Metal
|
|
|
|
|
, QuartzCore
|
|
|
|
|
}:
|
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2022-02-20 05:27:41 +00:00
|
|
|
|
pname = "MoltenVK";
|
2023-02-02 18:25:31 +00:00
|
|
|
|
version = "1.2.1";
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
|
buildInputs = [
|
|
|
|
|
AppKit
|
|
|
|
|
Foundation
|
|
|
|
|
Metal
|
|
|
|
|
QuartzCore
|
|
|
|
|
cereal
|
|
|
|
|
glslang
|
|
|
|
|
spirv-cross
|
|
|
|
|
spirv-headers
|
|
|
|
|
spirv-tools
|
|
|
|
|
vulkan-headers
|
|
|
|
|
];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
|
|
nativeBuildInputs = [ cctools sigtool xcbuild ];
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
|
outputs = [ "out" "bin" "dev" ];
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
|
owner = "KhronosGroup";
|
|
|
|
|
repo = "MoltenVK";
|
2022-06-16 17:23:12 +00:00
|
|
|
|
rev = "v${finalAttrs.version}";
|
2023-02-02 18:25:31 +00:00
|
|
|
|
hash = "sha256-JqHPKLSFq+8hyOjVZbjh4AsHM8zSF7ZVxlEePmnEC2w=";
|
2022-02-20 05:27:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
|
# Fix the Xcode projects to play nicely with `xcbuild`.
|
|
|
|
|
./MoltenVKShaderConverter.xcodeproj.patch
|
|
|
|
|
./MoltenVK.xcodeproj.patch
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
postPatch = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
|
# Move `mvkGitRevDerived.h` to a stable location
|
2022-02-20 05:27:41 +00:00
|
|
|
|
substituteInPlace Scripts/gen_moltenvk_rev_hdr.sh \
|
2022-08-12 12:06:08 +00:00
|
|
|
|
--replace '$'''{BUILT_PRODUCTS_DIR}' "$NIX_BUILD_TOP/$sourceRoot/build/include" \
|
2022-06-16 17:23:12 +00:00
|
|
|
|
--replace '$(git rev-parse HEAD)' ${finalAttrs.src.rev}
|
2023-02-02 18:25:31 +00:00
|
|
|
|
# Use the SPIRV-Cross packaged in nixpkgs instead of one built specifically for MoltenVK.
|
|
|
|
|
substituteInPlace MoltenVK/MoltenVK.xcodeproj/project.pbxproj \
|
|
|
|
|
--replace SPIRV_CROSS_NAMESPACE_OVERRIDE=MVK_spirv_cross SPIRV_CROSS_NAMESPACE_OVERRIDE=spirv_cross
|
|
|
|
|
substituteInPlace MoltenVKShaderConverter/MoltenVKShaderConverter.xcodeproj/project.pbxproj \
|
|
|
|
|
--replace SPIRV_CROSS_NAMESPACE_OVERRIDE=MVK_spirv_cross SPIRV_CROSS_NAMESPACE_OVERRIDE=spirv_cross
|
2022-08-12 12:06:08 +00:00
|
|
|
|
# Adding all of `usr/include` from the SDK results in header conflicts with `libcxx.dev`.
|
|
|
|
|
# Work around it by symlinking just the SIMD stuff needed by MoltenVK.
|
|
|
|
|
mkdir -p build/include
|
|
|
|
|
ln -s "${MacOSX-SDK}/usr/include/simd" "build/include"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
dontConfigure = true;
|
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
|
NIX_CFLAGS_COMPILE = [
|
|
|
|
|
"-isystem ${lib.getDev libcxx}/include/c++/v1"
|
2023-02-02 18:25:31 +00:00
|
|
|
|
"-I${lib.getDev spirv-cross}/include/spirv_cross"
|
|
|
|
|
"-I${lib.getDev spirv-headers}/include/spirv/unified1/"
|
2022-08-12 12:06:08 +00:00
|
|
|
|
];
|
|
|
|
|
|
2022-02-20 05:27:41 +00:00
|
|
|
|
buildPhase = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
|
NIX_CFLAGS_COMPILE+=" \
|
|
|
|
|
-I$NIX_BUILD_TOP/$sourceRoot/build/include \
|
|
|
|
|
-I$NIX_BUILD_TOP/$sourceRoot/Common"
|
|
|
|
|
NIX_LDFLAGS+=" -L$NIX_BUILD_TOP/$sourceRoot/build/lib"
|
|
|
|
|
|
2022-02-20 05:27:41 +00:00
|
|
|
|
# Build each project on its own because `xcbuild` fails to build `MoltenVKPackaging.xcodeproj`.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
build=$NIX_BUILD_TOP/$sourceRoot/build
|
|
|
|
|
mkdir -p "$build/bin" "$build/lib"
|
|
|
|
|
|
|
|
|
|
NIX_LDFLAGS+=" \
|
|
|
|
|
-lMachineIndependent \
|
|
|
|
|
-lGenericCodeGen \
|
|
|
|
|
-lOGLCompiler \
|
|
|
|
|
-lglslang \
|
|
|
|
|
-lOSDependent \
|
|
|
|
|
-lSPIRV \
|
|
|
|
|
-lSPIRV-Tools \
|
|
|
|
|
-lSPIRV-Tools-opt \
|
|
|
|
|
-lspirv-cross-msl \
|
|
|
|
|
-lspirv-cross-core \
|
|
|
|
|
-lspirv-cross-glsl"
|
|
|
|
|
|
2022-02-20 05:27:41 +00:00
|
|
|
|
pushd MoltenVKShaderConverter
|
2022-08-12 12:06:08 +00:00
|
|
|
|
xcodebuild build \
|
|
|
|
|
-jobs $NIX_BUILD_CORES \
|
|
|
|
|
-configuration Release \
|
|
|
|
|
-project MoltenVKShaderConverter.xcodeproj \
|
|
|
|
|
-scheme MoltenVKShaderConverter \
|
|
|
|
|
-arch ${stdenv.targetPlatform.darwinArch}
|
|
|
|
|
declare -A products=( [MoltenVKShaderConverter]=bin [libMoltenVKShaderConverter.a]=lib )
|
|
|
|
|
for product in "''${!products[@]}"; do
|
|
|
|
|
cp MoltenVKShaderConverter-*/Build/Products/Release/$product "$build/''${products[$product]}/$product"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
done
|
2022-08-12 12:06:08 +00:00
|
|
|
|
popd
|
|
|
|
|
|
|
|
|
|
NIX_LDFLAGS+=" \
|
|
|
|
|
-lobjc \
|
|
|
|
|
-lMoltenVKShaderConverter \
|
|
|
|
|
-lspirv-cross-reflect"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
|
|
|
|
pushd MoltenVK
|
2022-08-12 12:06:08 +00:00
|
|
|
|
xcodebuild build \
|
|
|
|
|
-jobs $NIX_BUILD_CORES \
|
|
|
|
|
-configuration Release \
|
|
|
|
|
-project MoltenVK.xcodeproj \
|
|
|
|
|
-scheme MoltenVK-macOS \
|
|
|
|
|
-arch ${stdenv.targetPlatform.darwinArch}
|
|
|
|
|
cp MoltenVK-*/Build/Products/Release/dynamic/libMoltenVK.dylib "$build/lib/libMoltenVK.dylib"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
popd
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
installPhase = ''
|
2022-06-16 17:23:12 +00:00
|
|
|
|
mkdir -p "$out/lib" "$out/share/vulkan/icd.d" "$bin/bin" "$dev/include/MoltenVK"
|
2022-08-12 12:06:08 +00:00
|
|
|
|
cp build/bin/MoltenVKShaderConverter "$bin/bin/"
|
|
|
|
|
cp build/lib/libMoltenVK.dylib "$out/lib/"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
cp MoltenVK/MoltenVK/API/* "$dev/include/MoltenVK"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
install -m644 MoltenVK/icd/MoltenVK_icd.json "$out/share/vulkan/icd.d/MoltenVK_icd.json"
|
|
|
|
|
substituteInPlace $out/share/vulkan/icd.d/MoltenVK_icd.json \
|
2022-06-16 17:23:12 +00:00
|
|
|
|
--replace ./libMoltenVK.dylib "$out/lib/libMoltenVK.dylib"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
|
postFixup = ''
|
|
|
|
|
install_name_tool -id "$out/lib/libMoltenVK.dylib" "$out/lib/libMoltenVK.dylib"
|
|
|
|
|
codesign -s - -f "$out/lib/libMoltenVK.dylib"
|
2022-02-20 05:27:41 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
|
description = "A Vulkan Portability implementation built on top of Apple’s Metal API";
|
|
|
|
|
homepage = "https://github.com/KhronosGroup/MoltenVK";
|
|
|
|
|
changelog = "https://github.com/KhronosGroup/MoltenVK/releases";
|
|
|
|
|
maintainers = [ lib.maintainers.reckenrode ];
|
|
|
|
|
license = lib.licenses.asl20;
|
|
|
|
|
platforms = lib.platforms.darwin;
|
|
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
|
})
|