xmake.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package("v8")
  2. set_homepage("https://v8.dev")
  3. set_description("V8 JavaScript Engine")
  4. add_urls("https://github.com/v8/v8.git")
  5. add_versions("13.5.212.10", "e2591684c45463aa1e46ebefc3fd35deee63f37c")
  6. add_deps("depot_tools")
  7. if is_plat("linux", "bsd") then
  8. add_syslinks("pthread", "dl")
  9. elseif is_plat("windows") then
  10. add_syslinks("user32", "winmm", "advapi32", "dbghelp", "shlwapi")
  11. add_configs("runtimes", {description = "Set runtime.", default = "MT", readonly = true})
  12. end
  13. add_includedirs("include")
  14. add_links("v8_monolith")
  15. on_check(function (package)
  16. local is_release = not package:is_debug()
  17. local is_static = not package:config("shared")
  18. local is_arm64 = package:is_arch("arm64")
  19. -- Require C++20
  20. assert(package:check_cxxsnippets({test = [[
  21. #include <cstddef>
  22. #include <iterator>
  23. struct SimpleInputIterator {
  24. using difference_type = std::ptrdiff_t;
  25. using value_type = int;
  26. int operator*() const;
  27. SimpleInputIterator& operator++();
  28. void operator++(int) { ++*this; }
  29. };
  30. static_assert(std::input_iterator<SimpleInputIterator>);
  31. ]]}, {configs = {languages = "c++20"}}), "package(v8): require at least C++20.")
  32. -- Only configured and tested for:
  33. assert(is_release and is_static, "package(v8): only configured for static + release usage.")
  34. if package:is_plat("windows") then
  35. -- Require MSVC / Visual Studio 2022
  36. local msvc = package:toolchain("msvc")
  37. if msvc then
  38. local vs = msvc:config("vs")
  39. local year = tonumber(vs)
  40. assert(year >= 2022, "package(v8): require at least Visual Studio 2022.")
  41. else
  42. assert(false, "package(v8): only configured for MSVC on Windows.")
  43. end
  44. local is_win11 = winos.version():ge("10.0.22000+194")
  45. assert(not (is_win11 and is_arm64), "package(v8): Windows 11 arm64 is not supported.")
  46. elseif package:is_plat("linux") then
  47. local distrib = linuxos.name()
  48. assert(distrib ~= "archlinux", "package(v8): Archlinux is not supported.")
  49. assert(distrib ~= "fedora", "package(v8): Fedora is not supported.")
  50. assert(not is_arm64, "package(v8): Linux arm64 is not supported.")
  51. end
  52. end)
  53. on_install("linux", "windows", function (package)
  54. import("core.base.global")
  55. -- maybe we need set proxy, e.g. `xmake g --proxy=http://127.0.0.1:xxxx`
  56. local envs = {}
  57. local proxy = global.get("proxy")
  58. if proxy then
  59. envs.HTTP_PROXY = proxy
  60. envs.HTTPS_PROXY = proxy
  61. envs.ALL_PROXY = proxy
  62. end
  63. io.writefile(".gclient", [=[solutions = [
  64. {
  65. "name": ".",
  66. "url": "https://github.com/v8/v8.git",
  67. "deps_file": "DEPS",
  68. "managed": False,
  69. "custom_deps": {},
  70. }]]=])
  71. if package:is_plat("windows") then
  72. envs.DEPOT_TOOLS_WIN_TOOLCHAIN = "0"
  73. envs.GYP_MSVS_VERSION = "2022"
  74. end
  75. local gclient = package:is_plat("windows") and "gclient.bat" or "gclient"
  76. -- A Git account needs to be configured
  77. os.vrunv("git", {"config", "user.email", "[email protected]"})
  78. os.vrunv("git", {"config", "user.name", "Dummy Dummy"})
  79. -- Prevent long path issue on Windows
  80. os.vrunv("git", {"config", "--local", "core.longpaths", "true"})
  81. -- Update repository and dependencies
  82. -- Clean any local changes to apply patches
  83. os.vrunv(gclient, {"sync", "-v"}, {envs = envs})
  84. -- Setup args.gn
  85. local configs = {
  86. is_official_build = false,
  87. is_component_build = false,
  88. is_debug = package:is_debug(),
  89. symbol_level = package:is_debug() and 2 or 0,
  90. strip_debug_info = not package:is_debug(),
  91. treat_warnings_as_errors = false,
  92. use_custom_libcxx = false,
  93. v8_monolithic = true,
  94. v8_enable_sandbox = false,
  95. v8_enable_pointer_compression = false,
  96. v8_enable_webassembly = false,
  97. v8_enable_gdbjit = package:is_debug(),
  98. v8_enable_i18n_support = false,
  99. v8_enable_test_features = false,
  100. v8_use_external_startup_data = false
  101. }
  102. if not package:is_plat("windows") then
  103. configs.is_clang = false
  104. end
  105. -- Build V8 library
  106. import("package.tools.gn").build(package, configs, {buildir = "out.gn", target = {"v8_monolith"}})
  107. -- Install headers and library files
  108. os.cp("include", package:installdir())
  109. os.trycp("out.gn/obj/*.a", package:installdir("lib"))
  110. os.trycp("out.gn/obj/*.lib", package:installdir("lib"))
  111. os.trycp("out.gn/obj/*.dll", package:installdir("bin"))
  112. end)
  113. on_test(function (package)
  114. local cxxflags = package:is_plat("windows") and "/Zc:__cplusplus" or ""
  115. assert(package:has_cxxfuncs("v8::V8::InitializePlatform(0)", {
  116. configs = {
  117. languages = "c++20",
  118. cxxflags = cxxflags
  119. },
  120. includes = "v8.h"
  121. }))
  122. end)