xmake.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package("nzsl")
  2. set_homepage("https://github.com/NazaraEngine/ShaderLang")
  3. set_description("NZSL is a shader language inspired by Rust and C++ which compiles to GLSL or SPIRV")
  4. set_license("MIT")
  5. add_urls("https://github.com/NazaraEngine/ShaderLang/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/NazaraEngine/ShaderLang.git")
  7. add_versions("v1.0.0", "ef434fec5d32ddf64f2f7c7691a4d96a6ac24cab4cc6c091d46a542c86825359")
  8. set_policy("package.strict_compatibility", true)
  9. add_deps("nazarautils")
  10. add_deps("fast_float", "frozen", "ordered_map", {private = true})
  11. add_configs("cbinding", {description = "Builds the C binding library (CNZSL)", default = false, type = "boolean"})
  12. add_configs("nzsla", {description = "Includes standalone archiver", default = true, type = "boolean"})
  13. add_configs("nzslc", {description = "Includes standalone compiler", default = true, type = "boolean"})
  14. add_configs("symbols", {description = "Enable debug symbols in release", default = false, type = "boolean"})
  15. if is_plat("windows", "linux", "mingw", "macosx", "bsd") then
  16. add_configs("fs_watcher", {description = "Includes filesystem watcher", default = true, type = "boolean"})
  17. end
  18. if is_plat("wasm") then
  19. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  20. end
  21. on_load(function (package)
  22. package:addenv("PATH", "bin")
  23. if not package:config("shared") then
  24. package:add("defines", "NZSL_STATIC")
  25. package:add("deps", "fmt")
  26. end
  27. if package:config("fs_watcher") then
  28. package:add("deps", "efsw")
  29. end
  30. if package:config("nzsla") then
  31. package:add("deps", "lz4", {private = package:config("shared")})
  32. end
  33. if package:config("nzslc") then
  34. package:add("deps", "cxxopts >=3.1.1", "nlohmann_json", {private = true})
  35. end
  36. end)
  37. on_install(function (package)
  38. local configs = {}
  39. configs.cbinding = package:config("cbinding")
  40. configs.fs_watcher = package:config("fs_watcher") or false
  41. configs.erronwarn = false
  42. configs.examples = false
  43. configs.tests = false
  44. configs.with_nzsla = package:config("nzsla") or false
  45. configs.with_nzslc = package:config("nzslc") or false
  46. -- enable unitybuild for faster compilation except on MinGW (doesn't like big object even with /bigobj)
  47. if not os.getenv("NAZARA_DISABLE_UNITYBUILD") then
  48. configs.unitybuild = not package:is_plat("mingw")
  49. end
  50. if package:is_debug() then
  51. configs.mode = "debug"
  52. elseif package:config("symbols") then
  53. configs.mode = "releasedbg"
  54. else
  55. configs.mode = "release"
  56. end
  57. import("package.tools.xmake").install(package, configs)
  58. package:add("linkorders", "cnzsl", "nzsl")
  59. end)
  60. on_test(function (package)
  61. if (package:config("nzsla") or package:config("nzslc")) and not package:is_cross() then
  62. local envs
  63. if package:is_plat("windows") then
  64. import("core.tool.toolchain")
  65. local msvc = package:toolchain("msvc")
  66. if msvc and msvc:check() then
  67. envs = msvc:runenvs()
  68. end
  69. elseif package:is_plat("mingw") then
  70. import("core.tool.toolchain")
  71. local mingw = package:toolchain("mingw")
  72. if mingw and mingw:check() then
  73. envs = mingw:runenvs()
  74. end
  75. end
  76. if package:config("nzsla") then
  77. os.vrunv("nzsla", {"--version"}, {envs = envs})
  78. end
  79. if package:config("nzslc") then
  80. os.vrunv("nzslc", {"--version"}, {envs = envs})
  81. end
  82. end
  83. if not package:is_binary() then
  84. assert(package:check_cxxsnippets({test = [[
  85. void test() {
  86. nzsl::Ast::ModulePtr shaderModule = nzsl::Parse(R"(
  87. [nzsl_version("1.0")]
  88. module;
  89. struct FragOut
  90. {
  91. value: vec4[f32]
  92. }
  93. [entry(frag)]
  94. fn fragShader() -> FragOut
  95. {
  96. let output: FragOut;
  97. output.value = vec4[f32](0.0, 0.0, 1.0, 1.0);
  98. return output;
  99. }
  100. )");
  101. }
  102. ]]}, {configs = {languages = "c++17"}, includes = "NZSL/Parser.hpp"}))
  103. end
  104. end)