190 lines
7.3 KiB
Ruby
190 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
|
|
sha256 cellar: :any, arm64_ventura: "fdded6a6fee9488df91ba40dfa60eb71aefd48ce3e61d2b5f879d65d03e91773"
|
|
sha256 cellar: :any, arm64_monterey: "3ba33d3913fff723ccb189acec0607904ee3ae37b3e2cf2defc4c3a3b53e57df"
|
|
sha256 cellar: :any, arm64_big_sur: "69bc8c5ea78a4adaab9a5e1ea0889f13f5209cf239cb493781683a2965c30733"
|
|
sha256 cellar: :any, ventura: "4827554bc961e7c4e35635ab73ef41188bc5063b59fafedf35f1ef8b791fdfdc"
|
|
sha256 cellar: :any, monterey: "58a6dbcf2c1772fea882fcf6074d65a9423a4478fbf316ddb2747e068c35f7c4"
|
|
sha256 cellar: :any, big_sur: "56975701b9d135ef23cf75a9c1a078ddc689e2b9933bae85910f5fb9e40356ae"
|
|
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
|