homebrew-core/Formula/molten-vk.rb

163 lines
6.4 KiB
Ruby

class MoltenVk < Formula
desc "Implementation of the Vulkan graphics and compute API on top of Metal"
homepage "https://github.com/KhronosGroup/MoltenVK"
url "https://github.com/KhronosGroup/MoltenVK/archive/v1.1.4.tar.gz"
sha256 "f9bba6d3bf3648e7685c247cb6d126d62508af614bc549cedd5859a7da64967e"
license "Apache-2.0"
bottle do
sha256 cellar: :any, arm64_big_sur: "0ba0530a306310f1c9508d1c87661df6b488ec2db5a32ce35e3613f550b6132e"
sha256 cellar: :any, big_sur: "d0fb5ac702f4119ee0a4c294af47b4621f33da63e872ecfc83c00a57d986cfa3"
sha256 cellar: :any, catalina: "8731818bcaae271c0583867531674e2ef91be1a4c5c87baaf97ac6b6eff60d38"
end
depends_on "cmake" => :build
depends_on "python@3.9" => :build
depends_on xcode: ["11.7", :build]
# Requires IOSurface/IOSurfaceRef.h.
depends_on macos: :sierra
# MoltenVK depends on very specific revisions of its dependencies.
# For each resource the path to the file describing the expected
# revision is listed.
resource "cereal" do
# ExternalRevisions/cereal_repo_revision
url "https://github.com/USCiLab/cereal.git",
revision: "51cbda5f30e56c801c07fe3d3aba5d7fb9e6cca4"
end
resource "Vulkan-Headers" do
# ExternalRevisions/Vulkan-Headers_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Headers.git",
revision: "37164a5726f7e6113810f9557903a117498421cf"
end
resource "SPIRV-Cross" do
# ExternalRevisions/SPIRV-Cross_repo_revision
url "https://github.com/KhronosGroup/SPIRV-Cross.git",
revision: "9cdeefb5e322fc26b5fed70795fe79725648df1f"
end
resource "glslang" do
# ExternalRevisions/glslang_repo_revision
url "https://github.com/KhronosGroup/glslang.git",
revision: "ae2a562936cc8504c9ef2757cceaff163147834f"
end
resource "SPIRV-Tools" do
# External/glslang/known_good.json
url "https://github.com/KhronosGroup/SPIRV-Tools.git",
revision: "5dd2f76918bb2d0d67628e338f60f724f3e02e13"
end
resource "SPIRV-Headers" do
# External/glslang/known_good.json
url "https://github.com/KhronosGroup/SPIRV-Headers.git",
revision: "07f259e68af3a540038fa32df522554e74f53ed5"
end
resource "Vulkan-Tools" do
# ExternalRevisions/Vulkan-Tools_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
revision: "dbd221b2bc7acbfe993be40fbfbf4f4a0a1ed816"
end
def install
resources.each do |res|
res.stage(buildpath/"External"/res.name)
end
mv "External/SPIRV-Tools", "External/glslang/External/spirv-tools"
mv "External/SPIRV-Headers", "External/glslang/External/spirv-tools/external/spirv-headers"
# Build glslang
cd "External/glslang" do
system "./build_info.py", ".",
"-i", "build_info.h.tmpl",
"-o", "build/include/glslang/build_info.h"
end
# Build spirv-tools
mkdir "External/glslang/External/spirv-tools/build" do
# Required due to files being generated during build.
system "cmake", "..", *std_cmake_args
system "make"
end
# Build ExternalDependencies
xcodebuild "-project", "ExternalDependencies.xcodeproj",
"-scheme", "ExternalDependencies-macOS",
"-derivedDataPath", "External/build",
"SYMROOT=External/build", "OBJROOT=External/build",
"build"
# Create SPIRVCross.xcframework
xcodebuild "-quiet", "-create-xcframework",
"-output", "External/build/Latest/SPIRVCross.xcframework",
"-library", "External/build/Intermediates/XCFrameworkStaging/" \
"Release/Platform/libSPIRVCross.a"
# Create SPIRVTools.xcframework
xcodebuild "-quiet", "-create-xcframework",
"-output", "External/build/Latest/SPIRVTools.xcframework",
"-library", "External/build/Intermediates/XCFrameworkStaging/" \
"Release/Platform/libSPIRVTools.a"
# Created glslang.xcframework
xcodebuild "-quiet", "-create-xcframework",
"-output", "External/build/Latest/glslang.xcframework",
"-library", "External/build/Intermediates/XCFrameworkStaging/" \
"Release/Platform/libglslang.a"
# Build MoltenVK Package
xcodebuild "-project", "MoltenVKPackaging.xcodeproj",
"-scheme", "MoltenVK Package (macOS only)",
"SYMROOT=#{buildpath}/build", "OBJROOT=build",
"build"
(libexec/"lib").install Dir["External/build/Intermediates/XCFrameworkStaging/Release/" \
"Platform/lib{SPIRVCross,SPIRVTools,glslang}.a"]
glslang_dir = Pathname.new("External/glslang")
Pathname.glob("External/glslang/{glslang,SPIRV}/**/*.{h,hpp}") do |header|
header.chmod 0644
(libexec/"include"/header.parent.relative_path_from(glslang_dir)).install header
end
(libexec/"include").install "External/SPIRV-Cross/include/spirv_cross"
(libexec/"include").install "External/glslang/External/spirv-tools/include/spirv-tools"
(libexec/"include").install "External/Vulkan-Headers/include/vulkan" => "vulkan"
(libexec/"include").install "External/Vulkan-Headers/include/vk_video" => "vk_video"
frameworks.install "Package/Release/MoltenVK/MoltenVK.xcframework"
lib.install "Package/Release/MoltenVK/dylib/macOS/libMoltenVK.dylib"
lib.install "build/Release/libMoltenVK.a"
include.install "MoltenVK/MoltenVK/API" => "MoltenVK"
bin.install "Package/Release/MoltenVKShaderConverter/Tools/MoltenVKShaderConverter"
frameworks.install "Package/Release/MoltenVKShaderConverter/" \
"MoltenVKShaderConverter.xcframework"
include.install Dir["Package/Release/MoltenVKShaderConverter/include/" \
"MoltenVKShaderConverter"]
(share/"vulkan").install "MoltenVK/icd" => "icd.d"
end
test do
(testpath/"test.cpp").write <<~EOS
#include <vulkan/vulkan.h>
int main(void) {
const char *extensionNames[] = { "VK_KHR_surface" };
VkInstanceCreateInfo instanceCreateInfo = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, NULL,
0, NULL,
0, NULL,
1, extensionNames,
};
VkInstance inst;
vkCreateInstance(&instanceCreateInfo, NULL, &inst);
return 0;
}
EOS
system ENV.cc, "-o", "test", "test.cpp", "-I#{include}", "-I#{libexec/"include"}", "-L#{lib}", "-lMoltenVK"
system "./test"
end
end