From a3015f45b428eb239238156da8794dec398f8c1f Mon Sep 17 00:00:00 2001 From: xq114 <1140735506@qq.com> Date: Mon, 5 Sep 2022 15:01:38 +0800 Subject: move find_vulkansdk to sdk detection --- xmake/modules/detect/packages/find_vulkansdk.lua | 30 +------ xmake/modules/detect/sdks/find_vulkansdk.lua | 100 +++++++++++++++++++++++ 2 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 xmake/modules/detect/sdks/find_vulkansdk.lua diff --git a/xmake/modules/detect/packages/find_vulkansdk.lua b/xmake/modules/detect/packages/find_vulkansdk.lua index 902fdd498..efce6adeb 100644 --- a/xmake/modules/detect/packages/find_vulkansdk.lua +++ b/xmake/modules/detect/packages/find_vulkansdk.lua @@ -19,8 +19,7 @@ -- -- imports -import("lib.detect.find_path") -import("lib.detect.find_library") +import("detect.sdks.find_vulkansdk") -- find vulkansdk -- @@ -30,30 +29,5 @@ import("lib.detect.find_library") -- function main(opt) - -- init search paths - local paths = - { - "$(env VK_SDK_PATH)", - "$(env VULKAN_SDK)" - } - - -- find library - local result = {links = {}, linkdirs = {}, includedirs = {}} - local libname = (opt.plat == "windows" and "vulkan-1" or "vulkan") - local libsuffix = ((opt.plat == "windows" and opt.arch == "x86") and "lib32" or "lib") - local binsuffix = ((opt.plat == "windows" and opt.arch == "x86") and "bin32" or "bin") - local linkinfo = find_library(libname, paths, {suffixes = libsuffix}) - if linkinfo then - result.sdkdir = path.directory(linkinfo.linkdir) - result.bindir = path.join(result.sdkdir, binsuffix) - table.insert(result.linkdirs, linkinfo.linkdir) - table.insert(result.links, libname) - else - -- not found? - return - end - - -- find include - table.insert(result.includedirs, find_path(path.join("vulkan", "vulkan.h"), paths, {suffixes = "include"})) - return result + return find_vulkansdk() end diff --git a/xmake/modules/detect/sdks/find_vulkansdk.lua b/xmake/modules/detect/sdks/find_vulkansdk.lua new file mode 100644 index 000000000..5cea9dce4 --- /dev/null +++ b/xmake/modules/detect/sdks/find_vulkansdk.lua @@ -0,0 +1,100 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author xq114 +-- @file find_vulkansdk.lua +-- + +-- imports +import("lib.detect.find_file") +import("lib.detect.find_path") +import("lib.detect.find_library") +import("lib.detect.find_programver") + +-- find vulkan sdk info executable +function _find_vkinfo() + + -- init search paths + local paths = + { + "$(env VK_SDK_PATH)", + "$(env VULKAN_SDK)" + } + + -- find vulkan sdk info + local vkinfo + if is_host("windows") then + if is_arch("x86") then + vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin32"}}) + else + vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin"}}) + end + elseif is_host("linux") then + vkinfo = find_file("vulkaninfo", paths, {suffixes = {"bin"}}) + end + + return vkinfo +end + +-- find vulkansdk +-- +-- @param opt the package options. e.g. see the options of find_package() +-- +-- @return see the return value of find_package() +-- +function main(opt) + + -- find vkinfo + local vkinfo = _find_vkinfo() + if not vkinfo then + -- not found? + return + end + local sdkdir = path.directory(path.directory(vkinfo)) + + -- find api version + local apiver = find_programver(vkinfo, {command = "--summary", parse = "Vulkan Instance Version: (%d+%.%d+%.%d+)"}) + + -- initialize result + local result = {sdkdir = sdkdir, apiversion = apiver, links = {}, linkdirs = {}, includedirs = {}} + local binsuffix = ((is_host("windows") and is_arch("x86")) and "bin32" or "bin") + result.bindir = path.join(result.sdkdir, binsuffix) + + -- find library + local libname = (is_host("windows") and "vulkan-1" or "vulkan") + local libsuffix = ((is_host("windows") and is_arch("x86")) and "lib32" or "lib") + local linkinfo = find_library(libname, sdkdir, {suffixes = libsuffix}) + if linkinfo then + table.insert(result.linkdirs, linkinfo.linkdir) + table.insert(result.links, libname) + else + -- not found? + return + end + + -- find headers + local incdir = find_path(path.join("vulkan", "vulkan.h"), sdkdir, {suffixes = {"include"}}) + if incdir then + table.insert(result.includedirs, incdir) + else + -- not found? + return + end + + -- return + print(result) + return result +end -- cgit v1.3.1 From 80d10b758c80eb49fc46f1aab57c013baf278ed5 Mon Sep 17 00:00:00 2001 From: xq114 <1140735506@qq.com> Date: Mon, 5 Sep 2022 15:03:40 +0800 Subject: improve python.library for mingw --- xmake/rules/python/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/python/xmake.lua b/xmake/rules/python/xmake.lua index da54ead22..20c30c6b5 100644 --- a/xmake/rules/python/xmake.lua +++ b/xmake/rules/python/xmake.lua @@ -36,7 +36,7 @@ rule("python.library") end end else - if target:is_plat("windows") then + if target:is_plat("windows", "mingw") then target:set("extension", ".pyd") else target:set("extension", ".so") -- cgit v1.3.1 From fbdcc61009d3dbf37720babcb044d161077f7e16 Mon Sep 17 00:00:00 2001 From: xq114 <1140735506@qq.com> Date: Mon, 5 Sep 2022 23:12:10 +0800 Subject: improve arch detection --- xmake/modules/detect/packages/find_vulkansdk.lua | 4 ++-- xmake/modules/detect/sdks/find_vulkansdk.lua | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/xmake/modules/detect/packages/find_vulkansdk.lua b/xmake/modules/detect/packages/find_vulkansdk.lua index efce6adeb..451a9c8ac 100644 --- a/xmake/modules/detect/packages/find_vulkansdk.lua +++ b/xmake/modules/detect/packages/find_vulkansdk.lua @@ -28,6 +28,6 @@ import("detect.sdks.find_vulkansdk") -- @return see the return value of find_package() -- function main(opt) - - return find_vulkansdk() + opt = opt or {} + return find_vulkansdk({arch = opt.arch}) end diff --git a/xmake/modules/detect/sdks/find_vulkansdk.lua b/xmake/modules/detect/sdks/find_vulkansdk.lua index 5cea9dce4..ad47c2be7 100644 --- a/xmake/modules/detect/sdks/find_vulkansdk.lua +++ b/xmake/modules/detect/sdks/find_vulkansdk.lua @@ -19,13 +19,14 @@ -- -- imports +import("core.project.config") import("lib.detect.find_file") import("lib.detect.find_path") import("lib.detect.find_library") import("lib.detect.find_programver") -- find vulkan sdk info executable -function _find_vkinfo() +function _find_vkinfo(opt) -- init search paths local paths = @@ -35,9 +36,10 @@ function _find_vkinfo() } -- find vulkan sdk info + local arch = opt.arch or config.arch() or os.arch() local vkinfo if is_host("windows") then - if is_arch("x86") then + if arch == "x86" then vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin32"}}) else vkinfo = find_file("vulkaninfoSDK.exe", paths, {suffixes = {"bin"}}) @@ -58,7 +60,8 @@ end function main(opt) -- find vkinfo - local vkinfo = _find_vkinfo() + opt = opt or {} + local vkinfo = _find_vkinfo(opt) if not vkinfo then -- not found? return @@ -69,13 +72,14 @@ function main(opt) local apiver = find_programver(vkinfo, {command = "--summary", parse = "Vulkan Instance Version: (%d+%.%d+%.%d+)"}) -- initialize result + local arch = opt.arch or config.arch() or os.arch() local result = {sdkdir = sdkdir, apiversion = apiver, links = {}, linkdirs = {}, includedirs = {}} - local binsuffix = ((is_host("windows") and is_arch("x86")) and "bin32" or "bin") + local binsuffix = ((is_host("windows") and arch == "x86") and "bin32" or "bin") result.bindir = path.join(result.sdkdir, binsuffix) -- find library local libname = (is_host("windows") and "vulkan-1" or "vulkan") - local libsuffix = ((is_host("windows") and is_arch("x86")) and "lib32" or "lib") + local libsuffix = ((is_host("windows") and arch == "x86") and "lib32" or "lib") local linkinfo = find_library(libname, sdkdir, {suffixes = libsuffix}) if linkinfo then table.insert(result.linkdirs, linkinfo.linkdir) @@ -95,6 +99,5 @@ function main(opt) end -- return - print(result) return result end -- cgit v1.3.1