Преглед изворни кода

add vulkan utilities: loader, tools and validationlayers (#196)

* add vulkan utilities

* rearrange definition style
Hoildkv пре 4 година
родитељ
комит
a60129bb6f

+ 47 - 0
packages/v/vulkan-loader/xmake.lua

@@ -0,0 +1,47 @@
+package("vulkan-loader")
+
+    set_homepage("https://github.com/KhronosGroup/Vulkan-Loader")
+    set_description("This project provides the Khronos official Vulkan ICD desktop loader for Windows, Linux, and MacOS.")
+    set_license("Apache-2.0")
+
+    add_urls("https://github.com/KhronosGroup/Vulkan-Loader/archive/sdk-$(version).tar.gz", {version = function (version) return version:gsub("%+", ".") end})
+    add_versions("1.2.154+1", "889e45f7175d915dd0d702013b8021192e181d20f2ad4021c94006088f1edfe5")
+
+    add_deps("cmake", "ninja")
+    if is_plat("linux") then
+        add_deps("wayland", "libxrandr", "libxcb", "libxkbcommon")
+    end
+
+    on_load("windows", "linux", function (package)
+        local sdkver = package:version():split("%+")[1]
+        package:add("deps", "vulkan-headers " .. sdkver)
+    end)
+
+    on_install("windows", "linux", function (package)
+        import("package.tools.cmake")
+        local envs = cmake.buildenvs(package, {cmake_generator = "Ninja"})
+        if package:is_plat("linux") then
+            local includes = {}
+            local linkdirs = {}
+            for _, lib in ipairs({"wayland", "libxrandr", "libxcb", "libxkbcommon"}) do
+                local fetchinfo = package:dep(lib):fetch()
+                for _, dir in ipairs(fetchinfo.sysincludedirs or fetchinfo.includedirs) do
+                    table.insert(includes, dir)
+                end
+                for _, dir in ipairs(fetchinfo.linkdirs) do
+                    table.insert(linkdirs, dir)
+                end
+            end
+            envs.C_INCLUDE_PATH = (envs.C_INCLUDE_PATH or "") .. path.envsep() .. path.joinenv(table.unique(includes))
+            envs.LD_LIBRARY_PATH = (envs.LD_LIBRARY_PATH or "") .. path.envsep() .. path.joinenv(table.unique(linkdirs))
+        end
+
+        local configs = {"-DBUILD_TESTS=OFF"}
+        local vulkan_headers = package:dep("vulkan-headers")
+        table.insert(configs, "-DVULKAN_HEADERS_INSTALL_DIR=" .. vulkan_headers:installdir())
+        cmake.install(package, configs, {cmake_generator = "Ninja", envs = envs})
+    end)
+
+    on_test(function (package)
+        assert(package:has_cfuncs("vkGetDeviceProcAddr", {includes = "vulkan/vulkan_core.h"}))
+    end)

+ 55 - 0
packages/v/vulkan-tools/xmake.lua

@@ -0,0 +1,55 @@
+package("vulkan-tools")
+
+    set_homepage("https://github.com/KhronosGroup/Vulkan-Tools")
+    set_description("Vulkan Utilities and Tools")
+    set_license("Apache-2.0")
+
+    add_urls("https://github.com/KhronosGroup/Vulkan-Tools/archive/sdk-$(version).tar.gz", {version = function (version) return version:gsub("%+", ".") end})
+    add_versions("1.2.154+0", "c7d66ec1f5fe5c0a13e487fe5c6eefd3a954522c0b05f06bd2ae41792aeea272")
+
+    add_deps("cmake", "ninja")
+    add_deps("glslang")
+    if is_plat("linux") then
+        add_deps("wayland", "libxrandr", "libxcb", "libxkbcommon")
+    end
+
+    on_load("windows", "linux", function (package)
+        local sdkver = package:version():split("%+")[1]
+        package:add("deps", "vulkan-headers " .. sdkver)
+        package:add("deps", "vulkan-loader " .. sdkver)
+    end)
+
+    on_install("windows", "linux", function (package)
+        import("package.tools.cmake")
+        local envs = cmake.buildenvs(package, {cmake_generator = "Ninja"})
+        if package:is_plat("linux") then
+            local includes = {}
+            local linkdirs = {}
+            for _, lib in ipairs({"wayland", "libxrandr", "libxcb", "libxkbcommon"}) do
+                local fetchinfo = package:dep(lib):fetch()
+                for _, dir in ipairs(fetchinfo.sysincludedirs or fetchinfo.includedirs) do
+                    table.insert(includes, dir)
+                end
+                for _, dir in ipairs(fetchinfo.linkdirs) do
+                    table.insert(linkdirs, dir)
+                end
+            end
+            envs.CPLUS_INCLUDE_PATH = (envs.CPLUS_INCLUDE_PATH or "") .. path.envsep() .. path.joinenv(table.unique(includes))
+            envs.LD_LIBRARY_PATH = (envs.LD_LIBRARY_PATH or "") .. path.envsep() .. path.joinenv(table.unique(linkdirs))
+        end
+
+        package:addenv("PATH", "bin")
+        io.replace(path.join("icd", "CMakeLists.txt"), "copy ${src_json} ${dst_json}", "${CMAKE_COMMAND} -E copy ${src_json} ${dst_json}", {plain = true})
+        local configs = {}
+        local vulkan_headers = package:dep("vulkan-headers")
+        local vulkan_loader = package:dep("vulkan-loader")
+        local glslang = package:dep("glslang")
+        table.insert(configs, "-DVULKAN_HEADERS_INSTALL_DIR=" .. vulkan_headers:installdir())
+        table.insert(configs, "-DVULKAN_LOADER_INSTALL_DIR=" .. vulkan_loader:installdir())
+        table.insert(configs, "-DGLSLANG_INSTALL_DIR=" .. glslang:installdir())
+        cmake.install(package, configs, {cmake_generator = "Ninja", envs = envs})
+    end)
+
+    on_test(function (package)
+        os.vrun("vulkaninfo --summary")
+    end)

+ 66 - 0
packages/v/vulkan-validationlayers/xmake.lua

@@ -0,0 +1,66 @@
+package("vulkan-validationlayers")
+
+    set_homepage("https://github.com/KhronosGroup/Vulkan-ValidationLayers/")
+    set_description("Vulkan Validation Layers")
+    set_license("Apache-2.0")
+
+    add_urls("https://github.com/KhronosGroup/Vulkan-ValidationLayers/archive/sdk-$(version).tar.gz", {version = function (version) return version:gsub("%+", ".") end})
+    add_versions("1.2.154+0", "8898ab05d0d8dec04fbba03d0ed2e79a1eb5c0382e5c89d4c737b45a6648f7f9")
+
+    add_patches("1.2.154+0", "https://github.com/KhronosGroup/Vulkan-ValidationLayers/commit/9d3ef3258715573b17e8195855c76626600998be.patch", "1fa39483c345fbfb43b925e8410a55e58fa8a9776f9e5443c6e4ec994a554749")
+
+    add_deps("cmake")
+    add_deps("glslang", "spirv-headers", "spirv-tools")
+    if is_plat("windows") then
+        add_syslinks("Advapi32")
+    elseif is_plat("linux") then
+        add_deps("ninja")
+        add_deps("wayland", "libxrandr", "libxcb", "libxkbcommon")
+    end
+
+    on_load("windows", "linux", function (package)
+        local sdkver = package:version():split("%+")[1]
+        package:add("deps", "vulkan-headers " .. sdkver)
+    end)
+
+    on_install("windows", "linux", function (package)
+        import("package.tools.cmake")
+
+        local envs = cmake.buildenvs(package, {cmake_generator = "Ninja"})
+        if package:is_plat("linux") then
+            local includes = {}
+            local linkdirs = {}
+            for _, lib in ipairs({"wayland", "libxrandr", "libxcb", "libxkbcommon"}) do
+                local fetchinfo = package:dep(lib):fetch()
+                for _, dir in ipairs(fetchinfo.sysincludedirs or fetchinfo.includedirs) do
+                    table.insert(includes, dir)
+                end
+                for _, dir in ipairs(fetchinfo.linkdirs) do
+                    table.insert(linkdirs, dir)
+                end
+            end
+            envs.CPLUS_INCLUDE_PATH = (envs.CPLUS_INCLUDE_PATH or "") .. path.envsep() .. path.joinenv(table.unique(includes))
+            envs.LD_LIBRARY_PATH = (envs.LD_LIBRARY_PATH or "") .. path.envsep() .. path.joinenv(table.unique(linkdirs))
+        end
+
+        local configs = {"-DBUILD_TESTS=OFF"}
+        local vulkan_headers = package:dep("vulkan-headers")
+        local glslang = package:dep("glslang")
+        local spirv_headers = package:dep("spirv-headers")
+        local spirv_tools = package:dep("spirv-tools")
+        table.insert(configs, "-DVULKAN_HEADERS_INSTALL_DIR=" .. vulkan_headers:installdir())
+        table.insert(configs, "-DGLSLANG_INSTALL_DIR=" .. glslang:installdir())
+        table.insert(configs, "-DSPIRV_HEADERS_INSTALL_DIR=" .. spirv_headers:installdir())
+        table.insert(configs, "-DSPIRV_TOOLS_INSTALL_DIR=" .. spirv_tools:installdir())
+
+        if package:is_plat("windows") then
+            cmake.install(package, configs, {buildir = os.tmpfile() .. ".dir"})
+        elseif is_plat("linux") then
+            cmake.install(package, configs, {buildir = os.tmpfile() .. ".dir", cmake_generator = "Ninja", envs = envs})
+        end
+        os.mv("layers", package:installdir("include"))
+    end)
+
+    on_test(function (package)
+        assert(package:has_cxxfuncs("getLayerOption", {includes = "layers/vk_layer_config.h"}))
+    end)