169 lines
6.9 KiB
Ruby
169 lines
6.9 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.7.tar.gz"
|
|
sha256 "657f8ccb5d51323c55ba64fa91da2e5ddb7326189b648f60f5e7323ddc21c42f"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_monterey: "026a359f528fd8595fb2f7de001dee78f68fddcffd310d3b370afb8752ae07c7"
|
|
sha256 cellar: :any, arm64_big_sur: "9025529b512bf776b237071a321d8bf6c5a49984842fd9e52f05465060aa023a"
|
|
sha256 cellar: :any, monterey: "de840658d17ffb4a822c3294e7544439cae0e673855ed5e163fc66819e15ffdf"
|
|
sha256 cellar: :any, big_sur: "e9ac3922ef255656ae6ccf14856788788a56f30b4b998e48daefdb3d80a8edcb"
|
|
sha256 cellar: :any, catalina: "b55955c3522410d2d8b10add00f6cd4f690f2164db784be9e485fdd57f0d32d4"
|
|
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: "1dace16d8044758d32736eb59802d171970e9448"
|
|
end
|
|
|
|
resource "SPIRV-Cross" do
|
|
# ExternalRevisions/SPIRV-Cross_repo_revision
|
|
url "https://github.com/KhronosGroup/SPIRV-Cross.git",
|
|
revision: "131278458ea8eebe6a6e9c476fbcf71278726e1a"
|
|
end
|
|
|
|
resource "glslang" do
|
|
# ExternalRevisions/glslang_repo_revision
|
|
url "https://github.com/KhronosGroup/glslang.git",
|
|
revision: "2742e959347ae2fac58acd0d022c92a0ff1f24bf"
|
|
end
|
|
|
|
resource "SPIRV-Tools" do
|
|
# known_good.json in the glslang repository
|
|
url "https://github.com/KhronosGroup/SPIRV-Tools.git",
|
|
revision: "45dd184c790d6bfc78a5a74a10c37e888b1823fa"
|
|
end
|
|
|
|
resource "SPIRV-Headers" do
|
|
# known_good.json in the glslang repository
|
|
url "https://github.com/KhronosGroup/SPIRV-Headers.git",
|
|
revision: "b42ba6d92faf6b4938e6f22ddd186dbdacc98d78"
|
|
end
|
|
|
|
resource "Vulkan-Tools" do
|
|
# ExternalRevisions/Vulkan-Tools_repo_revision
|
|
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
|
|
revision: "bb32aa13d4920261b5086219028ef329605d0126"
|
|
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
|