191 lines
7.4 KiB
Ruby
191 lines
7.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"
|
|
license "Apache-2.0"
|
|
|
|
stable do
|
|
url "https://github.com/KhronosGroup/MoltenVK/archive/v1.2.0.tar.gz"
|
|
sha256 "6e7af2dad0530b2b404480dbe437ca4670c6615cc2ec6cf6a20ed04d9d75e0bd"
|
|
|
|
# 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: "f09ba2777714871bddb70d049878af34b94fa54d"
|
|
end
|
|
|
|
resource "Vulkan-Headers" do
|
|
# ExternalRevisions/Vulkan-Headers_repo_revision
|
|
url "https://github.com/KhronosGroup/Vulkan-Headers.git",
|
|
revision: "98f440ce6868c94f5ec6e198cc1adda4760e8849"
|
|
end
|
|
|
|
resource "Vulkan-Tools" do
|
|
# ExternalRevisions/Vulkan-Tools_repo_revision
|
|
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
|
|
revision: "e52fa1cf2d95503d28f9d020800cbab15aaa304b"
|
|
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: "5755de46b07e4374c05fb1081f65f7ae1f8cca81"
|
|
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: "eb0a36633d2acf4de82588504f951ad0f2cecacb"
|
|
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: "85a1ed200d50660786c1a88d9166e871123cce39"
|
|
end
|
|
end
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_ventura: "7a324b696eac122a0e3ef699a7371bf68b75b152d2042476484851aab62bd493"
|
|
sha256 cellar: :any, arm64_monterey: "c565838d5d9f71002f5f03ff25b81d634255d9d5c9e3bc6d8be606a24931aaee"
|
|
sha256 cellar: :any, arm64_big_sur: "76bf0192ae994e4073d6746de6e34e245e3782c22e5590e0cd3eb83e6447e899"
|
|
sha256 cellar: :any, ventura: "7d0ae3c4c23e24ff97a7d674c1c88e776e01d61469ecf52aa1b2cf2aa266e83c"
|
|
sha256 cellar: :any, monterey: "718bee197b1dccf476e7ee93a6f60b2bcbf801c2f5692f4712721052e8775ded"
|
|
sha256 cellar: :any, big_sur: "e11fee329d1791981290df56ccfad8e0ed10a8aae2562a8c05b38097cf744a28"
|
|
sha256 cellar: :any, catalina: "e8d7c4e39c1002cf88156e93d716f89a2ac87b0d804ab085a2d4a19286220bc2"
|
|
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.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.
|
|
|
|
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
|