xmake.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package("muslcc")
  2. set_kind("toolchain")
  3. set_homepage("https://musl.cc/")
  4. set_description("static cross- and native- musl-based toolchains.")
  5. if is_host("windows") then
  6. if is_arch("arm64") then
  7. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/aarch64-linux-musl-cross.win.zip")
  8. add_versions("20210202", "1fa7226fb2317fa8dd1571f2a8964e8e4bb973479ec18e35e04b6b0606ff2eba")
  9. elseif is_arch("arm.*") then
  10. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/arm-linux-musleabi-cross.win.zip")
  11. add_versions("20210202", "87061cdc288b6a74b3414bb70ce91da524c126199548cf4b86ae40e074988291")
  12. elseif is_arch("x86", "i386") then
  13. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/i686-linux-musl-cross.win.zip")
  14. add_versions("20210202", "5f2903646a4bdd45d6dadfa65652a3bfe4191eab2e5b0ae1dd9b2e6ccf87f629")
  15. else
  16. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/x86_64-linux-musl-cross.win.zip")
  17. add_versions("20210202", "3a13f8bb3694b26ffbe3fe97d45db6cabadb662161cd5fc9cc80fc0adfb02091")
  18. end
  19. elseif is_host("linux") then
  20. if is_arch("arm64") then
  21. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/aarch64-linux-musl-cross.linux.tgz")
  22. add_versions("20210202", "7e237ecd528d31cb3eadc48a95f4779467f588a89444c43276c77cdfe93787de")
  23. elseif is_arch("arm.*") then
  24. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/arm-linux-musleabi-cross.linux.tgz")
  25. add_versions("20210202", "4e03e69f30eacf6bb573999b5a20c59e320720ed02edccfebfa6f89a9e76b445")
  26. elseif is_arch("x86", "i386") then
  27. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/i686-linux-musl-cross.linux.tgz")
  28. add_versions("20210202", "411e98b50c2f965ec0c7d752896151dc2068060e583f0eb245f2c86556d749c3")
  29. else
  30. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/x86_64-linux-musl-cross.linux.tgz")
  31. add_versions("20210202", "37ef7b69d4c4a20bb2c5e7e01ec7c60c1ac7de2c33b029eaa6c0d8b9e1869c6b")
  32. end
  33. elseif is_host("macosx") then
  34. if is_arch("arm64") then
  35. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/aarch64-linux-musl-cross.mac.tgz")
  36. add_versions("20210202", "5b3e91ebc430428578fa2a443256aca866e61da886d5f645eee9725485877389")
  37. elseif is_arch("arm.*") then
  38. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/arm-linux-musleabi-cross.mac.tgz")
  39. add_versions("20210202", "a177df3f847181c0c7f2b34b9bd7725b4c556c11a347aa0ae36e09ebf23fb480")
  40. elseif is_arch("x86", "i386") then
  41. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/i686-linux-musl-cross.mac.tgz")
  42. add_versions("20210202", "12cd8be154c122f6957ce21a9a5ff2d55a8bd660707b17fb3248578ac955ba25")
  43. else
  44. set_urls("https://github.com/xmake-mirror/musl.cc/releases/download/$(version)/x86_64-linux-musl-cross.mac.tgz")
  45. add_versions("20210202", "09e63d9ec8d2e21643750b9543fb138e59c8e255e5a0ae86bc099368addead89")
  46. end
  47. end
  48. if is_host("macosx") then
  49. -- fix missing libisl.22.dylib
  50. add_deps("libisl 0.22", {host = true, configs = {shared = true}})
  51. end
  52. on_check(function (package)
  53. local arch = os.arch()
  54. assert(arch == "x86_64" or arch == "i386" or arch == "x86" or arch == "x64", "package(%s): only run on x86/x86_64 machine.", package:name())
  55. end)
  56. on_install("@windows", "@msys", "@linux", "@macosx", function (package)
  57. -- remove soft link
  58. os.tryrm("usr")
  59. -- remove invalid path, it will break copy directory
  60. -- arm-linux-musleabi/lib/ld-musl-arm.so.1 -> /lib/libc.so
  61. os.tryrm("arm-linux-musleabi/lib/ld-musl-arm.so.1")
  62. -- fix missing libisl.22.dylib
  63. if is_host("macosx") then
  64. local function patchbin(bin_name)
  65. local cross
  66. if package:is_targetarch("arm64") then
  67. cross = "aarch64-linux-musl-"
  68. elseif package:is_targetarch("arm.*") then
  69. cross = "arm-linux-musleabi-"
  70. elseif package:is_targetarch("x86", "i386") then
  71. cross = "i686-linux-musl-"
  72. else
  73. cross = "x86_64-linux-musl-"
  74. end
  75. local binfile = path.join("bin", cross .. bin_name)
  76. local binfile_raw = binfile .. "-raw"
  77. os.mv(binfile, binfile_raw)
  78. io.writefile(binfile, ([[
  79. #!/usr/bin/env bash
  80. export DYLD_LIBRARY_PATH="%s"
  81. "%s" "$@"]]):format(package:dep("libisl"):installdir("lib"),
  82. path.join(package:installdir(), binfile_raw)))
  83. os.vrunv("chmod", {"777", binfile})
  84. end
  85. patchbin("gcc")
  86. patchbin("g++")
  87. end
  88. os.vcp("*", package:installdir())
  89. end)
  90. on_test(function (package)
  91. local gcc
  92. if package:is_targetarch("arm64") then
  93. gcc = "aarch64-linux-musl-gcc"
  94. elseif package:is_targetarch("arm.*") then
  95. gcc = "arm-linux-musleabi-gcc"
  96. elseif package:is_targetarch("x86", "i386") then
  97. gcc = "i686-linux-musl-gcc"
  98. else
  99. gcc = "x86_64-linux-musl-gcc"
  100. end
  101. if gcc and is_host("windows") then
  102. gcc = gcc .. ".exe"
  103. end
  104. local file = os.tmpfile() .. ".c"
  105. io.writefile(file, "int main(int argc, char** argv) {return 0;}")
  106. os.vrunv(gcc, {"-c", file})
  107. end)