How do I find the location of an installed binary from a package? #2219
-
I am currently writing an application that needs some code generation before C++ compliation. More specifically, I'm using a tool called package("sokol-tools-bin")
set_kind("library", {binary = true})
add_urls("https://github.com/floooh/sokol-tools-bin.git")
on_install("windows", function (package)
os.cp("bin/win32/sokol-shdc.exe", package:installdir("bin"))
end) Now I'm trying to create a custom rule to invoke sokol-shdc for all files with the rule("sokol_shaders")
set_extensions(".glsl")
on_load(function (target)
target:add("includedirs", target:autogendir())
end)
before_buildcmd_file(function (target, batchcmds, shaderfile, opt)
import("lib.detect.find_package")
local headerdir = target:autogendir()
local name = path.basename(shaderfile)
local ext = path.extension(shaderfile)
local headerfile = path.join(headerdir, string.format("%s.%s.h", name, ext))
local package = find_package("sokol-tools-bin")
local binary = path.join(package:installdir("bin"), "sokol-shdc.exe")
batchcmds:show_progress(opt.progress, "${color.build.object}generating headers for %s", shaderfile)
batchcmds:vrunv(binary, "--input", shaderfile, "--output", headerfile, "--slang", "glsl330:hlsl5:metal_macos")
batchcmds:add_depfiles(shaderfile)
batchcmds:set_depmtime(os.mtime(headerfile))
batchcmds:set_depcache(target:dependfile(headerfile))
end)
rule_end() Then I apply this rule to my target: target("renderer_test")
add_rules("sokol_shaders")
set_kind("binary")
add_files("renderer/*.cpp")
add_files("renderer/shaders/*.glsl")
add_includedirs("renderer")
add_packages("opengl", "sokol", "sokol-tools-bin") The problem is, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
why do not use https://xmake.io/#/manual/custom_rule?id=utilsbin2c or you can refer https://github.com/xmake-io/xmake/blob/master/xmake/rules/utils/glsl2spv/xmake.lua |
Beta Was this translation helpful? Give feedback.
why do not use
bin2c
orglsl2spv
rules?https://xmake.io/#/manual/custom_rule?id=utilsbin2c
https://xmake.io/#/manual/custom_rule?id=utilsglsl2spv
or you can refer https://github.com/xmake-io/xmake/blob/master/xmake/rules/utils/glsl2spv/xmake.lua