homebrew-core/Formula/molten-vk.rb

191 lines
7.3 KiB
Ruby

class MoltenVk < Formula
desc "Implementation of the Vulkan graphics and compute API on top of Metal"
homepage "https://github.com/KhronosGroup/MoltenVK"
license "Apache-2.0"
stable do
url "https://github.com/KhronosGroup/MoltenVK/archive/v1.2.1.tar.gz"
sha256 "4742df8f35473c5a737f2b120ae06aa6b9e8a7a3753b88932e501b06b1d17ea8"
# MoltenVK depends on very specific revisions of its dependencies.
# For each resource the path to the file describing the expected
# revision is listed.
resource "SPIRV-Cross" do
# ExternalRevisions/SPIRV-Cross_repo_revision
url "https://github.com/KhronosGroup/SPIRV-Cross.git",
revision: "c77b09b57c27837dc2d41aa371ed3d236ce9ce47"
end
resource "Vulkan-Headers" do
# ExternalRevisions/Vulkan-Headers_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Headers.git",
revision: "b75e5a02b6933caf86c5822d019067b335492c85"
end
resource "Vulkan-Tools" do
# ExternalRevisions/Vulkan-Tools_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
revision: "ce45337c51ed53e6f1b337aa746a5a96c5018f86"
end
resource "cereal" do
# ExternalRevisions/cereal_repo_revision
url "https://github.com/USCiLab/cereal.git",
revision: "51cbda5f30e56c801c07fe3d3aba5d7fb9e6cca4"
end
resource "glslang" do
# ExternalRevisions/glslang_repo_revision
url "https://github.com/KhronosGroup/glslang.git",
revision: "77551c429f86c0e077f26552b7c1c0f12a9f235e"
end
resource "SPIRV-Tools" do
# known_good.json in the glslang repository at revision of resource above
url "https://github.com/KhronosGroup/SPIRV-Tools.git",
revision: "40f5bf59c6acb4754a0bffd3c53a715732883a12"
end
resource "SPIRV-Headers" do
# known_good.json in the glslang repository at revision of resource above
url "https://github.com/KhronosGroup/SPIRV-Headers.git",
revision: "1d31a100405cf8783ca7a31e31cdd727c9fc54c3"
end
end
bottle do
rebuild 1
sha256 cellar: :any, arm64_ventura: "508abcdaee3f928755028f1232fb6ff919b620d334de53ae9ef5c94685d9863e"
sha256 cellar: :any, arm64_monterey: "aa1f43f4f369546182b4f924038deba16e804c0fa4edf1c28798e63f0bdda8c9"
sha256 cellar: :any, arm64_big_sur: "692772c5b22ee1a64af6429dfd26e820cf47b2ab924f573556c2483518b4d552"
sha256 cellar: :any, ventura: "a27cb9922580250180236aebe747ad26eb6b8ec0bf0ea381d949ed55c732bdbf"
sha256 cellar: :any, monterey: "8606c8d2fff59ac56e4bead9c8d282ca700b1bb91a1aa2743503603b122ee219"
sha256 cellar: :any, big_sur: "588117bb74967b2d29f4b7e85d74622ecac365ba263135fcf86bca94fe5c0a34"
end
head do
url "https://github.com/KhronosGroup/MoltenVK.git", branch: "master"
resource "cereal" do
url "https://github.com/USCiLab/cereal.git", branch: "master"
end
resource "Vulkan-Headers" do
url "https://github.com/KhronosGroup/Vulkan-Headers.git", branch: "main"
end
resource "SPIRV-Cross" do
url "https://github.com/KhronosGroup/SPIRV-Cross.git", branch: "master"
end
resource "glslang" do
url "https://github.com/KhronosGroup/glslang.git", branch: "master"
end
resource "SPIRV-Tools" do
url "https://github.com/KhronosGroup/SPIRV-Tools.git", branch: "master"
end
resource "SPIRV-Headers" do
url "https://github.com/KhronosGroup/SPIRV-Headers.git", branch: "master"
end
resource "Vulkan-Tools" do
url "https://github.com/KhronosGroup/Vulkan-Tools.git", branch: "master"
end
end
depends_on "cmake" => :build
depends_on "python@3.11" => :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.
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"
# 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