homebrew-core/Formula/molten-vk.rb

173 lines
7.1 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.10.tar.gz"
sha256 "fac11c2501195c9ce042103685c7778e35484562e6c084963a22072dd0a602e0"
license "Apache-2.0"
revision 1
bottle do
sha256 cellar: :any, arm64_monterey: "db4bd2f19ea7d78b956d802fb1c56891c14ee3789351496d8caeb6b200e97ac3"
sha256 cellar: :any, arm64_big_sur: "ea03822343ee3e0b8e4bb8058e4893927f56632b99d5133d981140a9c0418b29"
sha256 cellar: :any, monterey: "bcfcade5f4b8c52683671dd1456ea1ff52f2ffce77ca9e6c365637545b557a50"
sha256 cellar: :any, big_sur: "dabba76e226f9423af84dcb107850f85e7daa806fec11f3f31c35c2c316efda2"
sha256 cellar: :any, catalina: "cbbf37ddeecf29e9e6b562436c995c14e022253a0ae545a507587cbd815a3898"
end
depends_on "cmake" => :build
depends_on "python@3.10" => :build
depends_on xcode: ["11.7", :build]
# Requires IOSurface/IOSurfaceRef.h.
depends_on macos: :sierra
depends_on :macos # Linux does not have a Metal implementation. Not implied by the line above.
# 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: "3ef4c97fd6ea001d75a8e9da408ee473c180e456"
end
resource "SPIRV-Cross" do
# ExternalRevisions/SPIRV-Cross_repo_revision
url "https://github.com/KhronosGroup/SPIRV-Cross.git",
revision: "50b4d5389b6a06f86fb63a2848e1a7da6d9755ca"
end
resource "glslang" do
# ExternalRevisions/glslang_repo_revision
url "https://github.com/KhronosGroup/glslang.git",
revision: "adbf0d3106b26daa237b10b9bf72b1af7c31092d"
end
resource "SPIRV-Tools" do
# known_good.json in the glslang repository
url "https://github.com/KhronosGroup/SPIRV-Tools.git",
revision: "b930e734ea198b7aabbbf04ee1562cf6f57962f0"
end
resource "SPIRV-Headers" do
# known_good.json in the glslang repository
url "https://github.com/KhronosGroup/SPIRV-Headers.git",
revision: "5a121866927a16ab9d49bed4788b532c7fcea766"
end
resource "Vulkan-Tools" do
# ExternalRevisions/Vulkan-Tools_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
revision: "ef9db7a8ec52f6c56158d83f5d57ef388c1abec1"
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"]
inreplace "MoltenVK/icd/MoltenVK_icd.json",
"./libMoltenVK.dylib",
(lib/"libMoltenVK.dylib").relative_path_from(share/"vulkan/icd.d")
(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