From 317343431e68a97f1e13d8e8edd4ca9699e398eb Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Sat, 6 Dec 2025 14:15:47 +0800 Subject: [PATCH 1/4] add glslang-nihui --- packages/g/glslang-nihui/xmake.lua | 128 +++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 packages/g/glslang-nihui/xmake.lua diff --git a/packages/g/glslang-nihui/xmake.lua b/packages/g/glslang-nihui/xmake.lua new file mode 100644 index 00000000000..e43410af2a0 --- /dev/null +++ b/packages/g/glslang-nihui/xmake.lua @@ -0,0 +1,128 @@ +package("glslang-nihui") + set_homepage("https://github.com/nihui/glslang/") + set_description("nihui's fork of KhronosGroup/glslang for C++14 compatibility. Mainly for Tencent/ncnn") + set_license("Apache-2.0") + + add_urls("https://github.com/nihui/glslang.git") + + add_versions("20250916", "cpp14-2") -- 8cd77a808d0bffa442ae9462d5e3a8141892ba5a + add_versions("20250503", "a9ac7d5f307e5db5b8c4fbf904bdba8fca6283bc") + + add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"}) + add_configs("spv_remapper", {description = "Enable building of SPVRemapper.", default = false, type = "boolean"}) + add_configs("spirv_tools", {description = "Enable SPIRV-Tools integration (Optimizer).", default = false, type = "boolean"}) + add_configs("hlsl", {description = "Enable HLSL support.", default = false, type = "boolean"}) + add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"}) + add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"}) + add_configs("tools", {description = "Build the glslangValidator tool.", default = false, type = "boolean"}) + add_configs("default_resource_limits", {description = "Build with default resource limits.", default = false, type = "boolean"}) + if is_plat("wasm") then + add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) + end + + add_deps("cmake") + if is_plat("linux") then + add_syslinks("pthread") + end + + on_load(function (package) + if package:config("binaryonly") then + package:set("kind", "binary") + package:config_set("tools", true) + end + if package:config("spirv_tools") or package:config("tools") then + package:add("deps", "python 3.x", {kind = "binary"}) + end + if package:config("spirv_tools") then + package:add("deps", "spirv-tools") + end + end) + + on_fetch(function (package, opt) + if opt.system and package:config("binaryonly") then + return package:find_tool("glslangValidator") + end + end) + + on_install(function (package) + package:addenv("PATH", "bin") + + if package:config("spirv_tools") then + io.replace("StandAlone/CMakeLists.txt", "target_link_libraries(glslangValidator ${LIBRARIES})", [[ + target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools) + ]], {plain = true}) + io.replace("SPIRV/CMakeLists.txt", "target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)", [[ + target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools) + ]], {plain = true}) + end + + -- glslang will add a debug lib postfix for win32 platform, disable this to fix compilation issues under windows + io.replace("CMakeLists.txt", 'set(CMAKE_DEBUG_POSTFIX "d")', [[ + message(WARNING "Disabled CMake Debug Postfix for xmake package generation") + ]], {plain = true}) + + if package:is_plat("wasm") then + -- wasm-ld doesn't support --no-undefined + io.replace("CMakeLists.txt", [[add_link_options("-Wl,--no-undefined")]], "", {plain = true}) + end + + local configs = {"-DENABLE_CTEST=OFF", "-DGLSLANG_TESTS=OFF", "-DBUILD_EXTERNAL=OFF", "-DENABLE_PCH=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + if package:is_plat("windows") then + table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") + if package:is_debug() then + table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''") + end + else + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + end + table.insert(configs, "-DENABLE_EXCEPTIONS=" .. (package:config("exceptions") and "ON" or "OFF")) + table.insert(configs, "-DENABLE_HLSL=" .. (package:config("hlsl") and "ON" or "OFF")) + table.insert(configs, "-DENABLE_RTTI=" .. (package:config("rtti") and "ON" or "OFF")) + table.insert(configs, "-DENABLE_SPVREMAPPER=" .. (package:config("spv_remapper") and "ON" or "OFF")) + table.insert(configs, "-DENABLE_GLSLANG_BINARIES=" .. (package:config("tools") and "ON" or "OFF")) + local packagedeps = {} + if package:config("spirv_tools") then + table.insert(configs, "-DENABLE_OPT=ON") + table.insert(configs, "-DALLOW_EXTERNAL_SPIRV_TOOLS=ON") + table.insert(packagedeps, "spirv-tools") + else + table.insert(configs, "-DENABLE_OPT=OFF") + end + import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps}) + if not package:config("binaryonly") then + package:add("links", "glslang", "MachineIndependent", "GenericCodeGen", "OGLCompiler", "OSDependent", "SPIRV") + if package:config("spv_remapper") then + package:add("links", "SPVRemapper") + end + if package:config("hlsl") then + package:add("links", "HLSL") + end + end + if package:config("default_resource_limits") then + package:add("links", "glslang-default-resource-limits") + end + + os.cp("glslang/MachineIndependent/**.h", package:installdir("include", "glslang", "MachineIndependent")) + os.cp("glslang/Include/**.h", package:installdir("include", "glslang", "Include")) + + -- https://github.com/KhronosGroup/glslang/releases/tag/12.3.0 + if package:config("tools") then + local bindir = package:installdir("bin") + local glslangValidator = path.join(bindir, "glslangValidator" .. (is_host("windows") and ".exe" or "")) + if not os.isfile(glslangValidator) then + local glslang = path.join(bindir, "glslang" .. (is_host("windows") and ".exe" or "")) + os.trycp(glslang, glslangValidator) + end + end + end) + + on_test(function (package) + if not package:is_cross() and package:config("tools") then + os.vrun("glslangValidator --version") + end + + if not package:config("binaryonly") then + assert(package:has_cxxfuncs("ShInitialize", {configs = {languages = "c++11"}, includes = "glslang/Public/ShaderLang.h"})) + end + end) From 8b3cb925e9a735a262b709ab5dbaa67e46fb7638 Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Sat, 6 Dec 2025 14:53:45 +0800 Subject: [PATCH 2/4] update xmake.lua --- packages/g/glslang-nihui/xmake.lua | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/g/glslang-nihui/xmake.lua b/packages/g/glslang-nihui/xmake.lua index e43410af2a0..dfd93450ef4 100644 --- a/packages/g/glslang-nihui/xmake.lua +++ b/packages/g/glslang-nihui/xmake.lua @@ -8,13 +8,13 @@ package("glslang-nihui") add_versions("20250916", "cpp14-2") -- 8cd77a808d0bffa442ae9462d5e3a8141892ba5a add_versions("20250503", "a9ac7d5f307e5db5b8c4fbf904bdba8fca6283bc") - add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"}) + add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"}) add_configs("spv_remapper", {description = "Enable building of SPVRemapper.", default = false, type = "boolean"}) - add_configs("spirv_tools", {description = "Enable SPIRV-Tools integration (Optimizer).", default = false, type = "boolean"}) - add_configs("hlsl", {description = "Enable HLSL support.", default = false, type = "boolean"}) - add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"}) - add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"}) - add_configs("tools", {description = "Build the glslangValidator tool.", default = false, type = "boolean"}) + add_configs("spirv_tools", {description = "Enable SPIRV-Tools integration (Optimizer).", default = false, type = "boolean"}) + add_configs("hlsl", {description = "Enable HLSL support.", default = false, type = "boolean"}) + add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"}) + add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"}) + add_configs("tools", {description = "Build the glslangValidator tool.", default = false, type = "boolean"}) add_configs("default_resource_limits", {description = "Build with default resource limits.", default = false, type = "boolean"}) if is_plat("wasm") then add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) @@ -47,15 +47,6 @@ package("glslang-nihui") on_install(function (package) package:addenv("PATH", "bin") - if package:config("spirv_tools") then - io.replace("StandAlone/CMakeLists.txt", "target_link_libraries(glslangValidator ${LIBRARIES})", [[ - target_link_libraries(glslangValidator ${LIBRARIES} SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools) - ]], {plain = true}) - io.replace("SPIRV/CMakeLists.txt", "target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt)", [[ - target_link_libraries(SPIRV PRIVATE MachineIndependent SPIRV-Tools-opt SPIRV-Tools-link SPIRV-Tools-reduce SPIRV-Tools) - ]], {plain = true}) - end - -- glslang will add a debug lib postfix for win32 platform, disable this to fix compilation issues under windows io.replace("CMakeLists.txt", 'set(CMAKE_DEBUG_POSTFIX "d")', [[ message(WARNING "Disabled CMake Debug Postfix for xmake package generation") From e2bce024309602a071a65488c92eb580a963bd3a Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Tue, 9 Dec 2025 23:35:12 +0800 Subject: [PATCH 3/4] design for ncnn, drop unused configs --- packages/g/glslang-nihui/xmake.lua | 98 ++++++------------------------ 1 file changed, 18 insertions(+), 80 deletions(-) diff --git a/packages/g/glslang-nihui/xmake.lua b/packages/g/glslang-nihui/xmake.lua index dfd93450ef4..03bdaa659c0 100644 --- a/packages/g/glslang-nihui/xmake.lua +++ b/packages/g/glslang-nihui/xmake.lua @@ -1,6 +1,6 @@ package("glslang-nihui") set_homepage("https://github.com/nihui/glslang/") - set_description("nihui's fork of KhronosGroup/glslang for C++14 compatibility. Mainly for Tencent/ncnn") + set_description("nihui's fork of KhronosGroup/glslang for C++14 compatibility. This package is designed for Tencent/ncnn.") set_license("Apache-2.0") add_urls("https://github.com/nihui/glslang.git") @@ -8,45 +8,20 @@ package("glslang-nihui") add_versions("20250916", "cpp14-2") -- 8cd77a808d0bffa442ae9462d5e3a8141892ba5a add_versions("20250503", "a9ac7d5f307e5db5b8c4fbf904bdba8fca6283bc") - add_configs("binaryonly", {description = "Only use binary program.", default = false, type = "boolean"}) - add_configs("spv_remapper", {description = "Enable building of SPVRemapper.", default = false, type = "boolean"}) - add_configs("spirv_tools", {description = "Enable SPIRV-Tools integration (Optimizer).", default = false, type = "boolean"}) - add_configs("hlsl", {description = "Enable HLSL support.", default = false, type = "boolean"}) - add_configs("rtti", {description = "Build with RTTI support.", default = false, type = "boolean"}) - add_configs("exceptions", {description = "Build with exception support.", default = false, type = "boolean"}) - add_configs("tools", {description = "Build the glslangValidator tool.", default = false, type = "boolean"}) - add_configs("default_resource_limits", {description = "Build with default resource limits.", default = false, type = "boolean"}) if is_plat("wasm") then add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) end add_deps("cmake") - if is_plat("linux") then + if is_plat("linux", "bsd") then add_syslinks("pthread") end on_load(function (package) - if package:config("binaryonly") then - package:set("kind", "binary") - package:config_set("tools", true) - end - if package:config("spirv_tools") or package:config("tools") then - package:add("deps", "python 3.x", {kind = "binary"}) - end - if package:config("spirv_tools") then - package:add("deps", "spirv-tools") - end - end) - - on_fetch(function (package, opt) - if opt.system and package:config("binaryonly") then - return package:find_tool("glslangValidator") - end + package:add("links", "glslang", "glslang-default-resource-limits") end) on_install(function (package) - package:addenv("PATH", "bin") - -- glslang will add a debug lib postfix for win32 platform, disable this to fix compilation issues under windows io.replace("CMakeLists.txt", 'set(CMAKE_DEBUG_POSTFIX "d")', [[ message(WARNING "Disabled CMake Debug Postfix for xmake package generation") @@ -57,63 +32,26 @@ package("glslang-nihui") io.replace("CMakeLists.txt", [[add_link_options("-Wl,--no-undefined")]], "", {plain = true}) end - local configs = {"-DENABLE_CTEST=OFF", "-DGLSLANG_TESTS=OFF", "-DBUILD_EXTERNAL=OFF", "-DENABLE_PCH=OFF"} + local configs = { + "-DGLSLANG_TESTS=OFF", + "-DBUILD_EXTERNAL=OFF", + "-DENABLE_PCH=OFF", + "-DENABLE_GLSLANG_BINARIES=OFF", + "-DENABLE_SPVREMAPPER=OFF", + "-DENABLE_OPT=OFF", + "-DENABLE_HLSL=OFF", + "-DENABLE_EXCEPTIONS=OFF", + "-DENABLE_RTTI=OFF" + } table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) - if package:is_plat("windows") then - table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") - if package:is_debug() then - table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''") - end - else - table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) - end - table.insert(configs, "-DENABLE_EXCEPTIONS=" .. (package:config("exceptions") and "ON" or "OFF")) - table.insert(configs, "-DENABLE_HLSL=" .. (package:config("hlsl") and "ON" or "OFF")) - table.insert(configs, "-DENABLE_RTTI=" .. (package:config("rtti") and "ON" or "OFF")) - table.insert(configs, "-DENABLE_SPVREMAPPER=" .. (package:config("spv_remapper") and "ON" or "OFF")) - table.insert(configs, "-DENABLE_GLSLANG_BINARIES=" .. (package:config("tools") and "ON" or "OFF")) - local packagedeps = {} - if package:config("spirv_tools") then - table.insert(configs, "-DENABLE_OPT=ON") - table.insert(configs, "-DALLOW_EXTERNAL_SPIRV_TOOLS=ON") - table.insert(packagedeps, "spirv-tools") - else - table.insert(configs, "-DENABLE_OPT=OFF") - end - import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps}) - if not package:config("binaryonly") then - package:add("links", "glslang", "MachineIndependent", "GenericCodeGen", "OGLCompiler", "OSDependent", "SPIRV") - if package:config("spv_remapper") then - package:add("links", "SPVRemapper") - end - if package:config("hlsl") then - package:add("links", "HLSL") - end - end - if package:config("default_resource_limits") then - package:add("links", "glslang-default-resource-limits") - end + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + + import("package.tools.cmake").install(package, configs) os.cp("glslang/MachineIndependent/**.h", package:installdir("include", "glslang", "MachineIndependent")) os.cp("glslang/Include/**.h", package:installdir("include", "glslang", "Include")) - - -- https://github.com/KhronosGroup/glslang/releases/tag/12.3.0 - if package:config("tools") then - local bindir = package:installdir("bin") - local glslangValidator = path.join(bindir, "glslangValidator" .. (is_host("windows") and ".exe" or "")) - if not os.isfile(glslangValidator) then - local glslang = path.join(bindir, "glslang" .. (is_host("windows") and ".exe" or "")) - os.trycp(glslang, glslangValidator) - end - end end) on_test(function (package) - if not package:is_cross() and package:config("tools") then - os.vrun("glslangValidator --version") - end - - if not package:config("binaryonly") then - assert(package:has_cxxfuncs("ShInitialize", {configs = {languages = "c++11"}, includes = "glslang/Public/ShaderLang.h"})) - end + assert(package:has_cxxfuncs("ShInitialize", {configs = {languages = "c++11"}, includes = "glslang/Public/ShaderLang.h"})) end) From 92906ef8ca2a4524a462223dd3bb730c164b5ecc Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Wed, 10 Dec 2025 23:29:15 +0800 Subject: [PATCH 4/4] version format improvement --- packages/g/glslang-nihui/xmake.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/g/glslang-nihui/xmake.lua b/packages/g/glslang-nihui/xmake.lua index 03bdaa659c0..f8d9eee6e93 100644 --- a/packages/g/glslang-nihui/xmake.lua +++ b/packages/g/glslang-nihui/xmake.lua @@ -5,8 +5,8 @@ package("glslang-nihui") add_urls("https://github.com/nihui/glslang.git") - add_versions("20250916", "cpp14-2") -- 8cd77a808d0bffa442ae9462d5e3a8141892ba5a - add_versions("20250503", "a9ac7d5f307e5db5b8c4fbf904bdba8fca6283bc") + add_versions("2025.09.16", "8cd77a808d0bffa442ae9462d5e3a8141892ba5a") + add_versions("2025.05.03", "a9ac7d5f307e5db5b8c4fbf904bdba8fca6283bc") if is_plat("wasm") then add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})