/
molten-vk.rb
189 lines (161 loc) 路 7.32 KB
/
molten-vk.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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.3.tar.gz"
sha256 "bb2c2e486284e0247a85e5f585425bfcb364bb13aa167047a16a1330b9a76e58"
# 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: "3550a54ae01b295c40ce972d951b420b388b9401"
end
resource "Vulkan-Headers" do
# ExternalRevisions/Vulkan-Headers_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Headers.git",
revision: "65ad768d8603671fc1085fe115019e72a595ced8"
end
resource "Vulkan-Tools" do
# ExternalRevisions/Vulkan-Tools_repo_revision
url "https://github.com/KhronosGroup/Vulkan-Tools.git",
revision: "f196c8d3cafcaf7e628b7b76a799c940999ee984"
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: "14e5a04e70057972eef8a40df422e30a3b70e4b5"
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: "44d72a9b36702f093dd20815561a56778b2d181e"
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: "1feaf4414eb2b353764d01d88f8aa4bcc67b60db"
end
end
bottle do
sha256 cellar: :any, arm64_ventura: "2282ecb3f31679d235f9f9c4634728f59ab67bad2dfee11b5e8727bd5aaa2231"
sha256 cellar: :any, arm64_monterey: "436ca449b89bfa327b57d45c6995ab04b78f695a85cc49e6acd8ac254e779ad1"
sha256 cellar: :any, arm64_big_sur: "5a37e688c7ed115fe709e9a8ebdd4854bd918e3e8b82db3480968ebe0f0c9eeb"
sha256 cellar: :any, ventura: "a83f24f191a04fd6a17cc45febc32cf623cc51579250b9f8493bc53819ffdbe3"
sha256 cellar: :any, monterey: "f3243b835848246fbaa16224a4b117f6ec38dc8c03a4f304dd0f6854d10adeed"
sha256 cellar: :any, big_sur: "d063df3b6442482b630982567e02a8cd23d4026a38c0e0512c5e943d89e69635"
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