homebrew-core/Formula/molten-vk.rb

166 lines
6.6 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.5.tar.gz"
sha256 "2cdcb8dbf2acdcd8cbe70b109dadc05a901038c84970afbe4863e5e23f33deae"
license "Apache-2.0"
bottle do
sha256 cellar: :any, arm64_big_sur: "0462e7825b8aa7db2e03e90533b06b1c36ecb10b111d02823d34a1d2fdceffaa"
sha256 cellar: :any, big_sur: "680dc3ea038ea88b96a81ac53f0bcf96b6f492f504deab1d9299de6ad451ae49"
sha256 cellar: :any, catalina: "9d5b04d2112a1d962129effbd808a7a81afb2bbda38cb9e02e8c20029cb84d9d"
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: "c5b7a2fa18750e435e91e06a50cdc5451c5b9abd"
end
resource "SPIRV-Cross" do
# ExternalRevisions/SPIRV-Cross_repo_revision
url "https://github.com/KhronosGroup/SPIRV-Cross.git",
revision: "0e2880ab990e79ce6cc8c79c219feda42d98b1e8"
end
resource "glslang" do
# ExternalRevisions/glslang_repo_revision
url "https://github.com/KhronosGroup/glslang.git",
revision: "2fb89a0072ae7316af1c856f22663fde4928128a"
end
resource "SPIRV-Tools" do
# External/glslang/known_good.json
url "https://github.com/KhronosGroup/SPIRV-Tools.git",
revision: "1fbed83c8aab8517d821fcb4164c08567951938f"
end
resource "SPIRV-Headers" do
# External/glslang/known_good.json
url "https://github.com/KhronosGroup/SPIRV-Headers.git",
revision: "449bc986ba6f4c5e10e32828783f9daef2a77644"
end
resource "Vulkan-Tools" do
# ExternalRevisions/Vulkan-Tools_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
revision: "58051062663477240484c8904459762ad544ba18"
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 "ARCHS=#{Hardware::CPU.arch}", "ONLY_ACTIVE_ARCH=YES",
"-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 "ARCHS=#{Hardware::CPU.arch}", "ONLY_ACTIVE_ARCH=YES",
"-project", "MoltenVKPackaging.xcodeproj",
"-scheme", "MoltenVK Package (macOS only)",
"-derivedDataPath", "#{buildpath}/build",
"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