xmake.lua 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package("quickjs-ng")
  2. set_homepage("https://github.com/quickjs-ng/quickjs")
  3. set_description("QuickJS, the Next Generation: a mighty JavaScript engine")
  4. set_license("MIT")
  5. add_urls("https://github.com/quickjs-ng/quickjs/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/quickjs-ng/quickjs.git", {submodules = false})
  7. add_versions("v0.10.1", "4e917eea3bb6051a0551fdd3aac45199ff705fa08920c15b824a08c5fbb032e4")
  8. add_versions("v0.9.0", "77f9e79b42e2e7cff9517bae612431af47e120730286cb1dcfad0753bc160f10")
  9. add_versions("v0.8.0", "7e60e1e0dcd07d25664331308a2f4aee2a88d60d85896e828d25df7c3d40204e")
  10. add_versions("v0.7.0", "46c45cc2ed174474765dac8e41062998d92c4dd5fd779624da4073d6cd430eeb")
  11. add_versions("v0.6.1", "276edbb30896cdf2eee12a8bdb5b9c1cc2734eac8c898de6d52268ae201e614d")
  12. add_versions("v0.5.0", "41212a6fb84bfe07d61772c02513734b7a06465843ba8f76f1ce1e5df866f489")
  13. add_configs("libc", {description = "Build standard library modules as part of the library", default = false, type = "boolean"})
  14. if is_plat("linux", "bsd", "cross") then
  15. add_syslinks("m", "pthread")
  16. end
  17. add_deps("cmake")
  18. if on_check then
  19. on_check("windows", function (package)
  20. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  21. if vs_toolset then
  22. local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
  23. local minor = vs_toolset_ver:minor()
  24. assert(minor and minor >= 30, "package(quickjs-ng) require vs_toolset >= 14.3")
  25. end
  26. end)
  27. end
  28. on_install(function (package)
  29. io.replace("CMakeLists.txt", "xcheck_add_c_compiler_flag(-Werror)", "", {plain = true})
  30. io.replace("CMakeLists.txt", "if(NOT WIN32 AND NOT EMSCRIPTEN)", "if(0)", {plain = true})
  31. local configs = {}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. table.insert(configs, "-DCONFIG_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
  35. table.insert(configs, "-DCONFIG_MSAN=" .. (package:config("msan") and "ON" or "OFF"))
  36. table.insert(configs, "-DCONFIG_UBSAN=" .. (package:config("ubsan") and "ON" or "OFF"))
  37. table.insert(configs, "-DBUILD_QJS_LIBC=" .. (package:config("libc") and "ON" or "OFF"))
  38. if package:config("shared") and package:is_plat("windows") then
  39. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  40. end
  41. if package:is_plat("wasm") then
  42. io.replace("quickjs-libc.c", " defined(__wasi__)", " (defined(__wasi__) || defined(EMSCRIPTEN))", {plain = true})
  43. io.replace("quickjs-libc.c", " !defined(__wasi__)", " (!defined(__wasi__) && !defined(EMSCRIPTEN))", {plain = true})
  44. end
  45. if package:is_plat("linux", "bsd", "cross") then
  46. io.replace("CMakeLists.txt", "M_LIBRARIES OR CMAKE_C_COMPILER_ID STREQUAL \"TinyCC\"", "1", {plain = true}) -- m library link
  47. end
  48. import("package.tools.cmake").install(package, configs)
  49. if package:is_plat("windows") and package:is_debug() then
  50. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  51. os.vcp(path.join(package:buildir(), "qjs.pdb"), dir)
  52. end
  53. os.trycp("*.h", package:installdir("include"))
  54. os.trycp(path.join(package:buildir(), "**.a"), package:installdir("lib"))
  55. os.trycp(path.join(package:buildir(), "**.so"), package:installdir("lib"))
  56. os.trycp(path.join(package:buildir(), "**.dylib"), package:installdir("lib"))
  57. os.trycp(path.join(package:buildir(), "**.lib"), package:installdir("lib"))
  58. os.trycp(path.join(package:buildir(), "**.dll"), package:installdir("bin"))
  59. package:add("links", "qjs")
  60. end)
  61. on_test(function (package)
  62. assert(package:has_cfuncs("JS_NewRuntime", {includes = "quickjs.h"}))
  63. end)