Hl.hx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package runci.targets;
  2. import haxe.io.Path;
  3. import sys.FileSystem;
  4. import runci.System.*;
  5. import runci.Config.*;
  6. using StringTools;
  7. class Hl {
  8. static final hlSrc = Path.join([getDownloadPath(), "hashlink"]);
  9. static final hlBuild = Path.join([getInstallPath(), "hashlink_build"]);
  10. static final hlBuildBinDir = Path.join([getInstallPath(), "hashlink_build", "bin"]);
  11. static final hlBinary =
  12. if (isCi() || !commandSucceed("hl", ["--version"])){
  13. Path.join([hlBuildBinDir, "hl"]) + ((systemName == "Windows") ? ".exe" : "");
  14. } else {
  15. commandResult(if(systemName == "Windows") "where" else "which", ["hl"]).stdout.trim();
  16. };
  17. static final miscHlDir = getMiscSubDir('hl');
  18. static public function getHlDependencies() {
  19. if (!isCi() && FileSystem.exists(hlBinary)) {
  20. infoMsg('hl has already been installed at $hlBinary.');
  21. return;
  22. }
  23. if (!FileSystem.exists(hlSrc))
  24. runCommand("git", ["clone", "https://github.com/HaxeFoundation/hashlink.git", hlSrc]);
  25. else
  26. infoMsg("Reusing hashlink repository");
  27. switch (systemName) {
  28. case "Linux":
  29. Linux.requireAptPackages(["libpng-dev", "libjpeg-turbo8-dev", "libturbojpeg", "zlib1g-dev", "libvorbis-dev", "libsqlite3-dev"]);
  30. case "Mac":
  31. runNetworkCommand("brew", ["update", '--preinstall']);
  32. runNetworkCommand("brew", ["bundle", '--file=${hlSrc}/Brewfile']);
  33. case "Windows":
  34. //pass
  35. }
  36. FileSystem.createDirectory(hlBuild);
  37. final generator = systemName == "Windows" ? ["-DCMAKE_SYSTEM_VERSION=10.0.19041.0"] : ["-GNinja"];
  38. runCommand("cmake", generator.concat([
  39. "-DBUILD_TESTING=OFF",
  40. "-DWITH_DIRECTX=OFF",
  41. "-DWITH_FMT=ON",
  42. "-DWITH_OPENAL=OFF",
  43. "-DWITH_SDL=OFF",
  44. "-DWITH_SQLITE=ON",
  45. "-DWITH_SSL=ON",
  46. "-DWITH_UI=OFF",
  47. "-DWITH_UV=OFF",
  48. "-DWITH_VIDEO=OFF",
  49. "-B" + hlBuild,
  50. "-H" + hlSrc
  51. ]));
  52. runCommand("cmake", [
  53. "--build", hlBuild
  54. ]);
  55. runCommand(hlBinary, ["--version"]);
  56. addToPATH(hlBuildBinDir);
  57. addToLIBPATH(hlBuildBinDir);
  58. haxelibDev("hashlink", '$hlSrc/other/haxelib/');
  59. }
  60. static public function run(args:Array<String>) {
  61. getHlDependencies();
  62. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  63. runCommand(hlBinary, ["bin/unit.hl"]);
  64. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  65. switch (systemName) {
  66. case "Linux" if (isCi()):
  67. runCommand("gcc", [
  68. "-o", "bin/hlc/main",
  69. "bin/hlc/main.c",
  70. "-Ibin/hlc/",
  71. '-I$hlSrc/src',
  72. '$hlBuildBinDir/fmt.hdll',
  73. "-lm",
  74. '-L$hlBuildBinDir', "-lhl"
  75. ]);
  76. runCommand("bin/hlc/main", []);
  77. case _:
  78. // TODO hl/c for mac/windows
  79. }
  80. changeDirectory(threadsDir);
  81. runCommand("haxe", ["build.hxml", "-hl", "export/threads.hl"]);
  82. runCommand(hlBinary, ["export/threads.hl"]);
  83. changeDirectory(sysDir);
  84. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  85. runSysTest(hlBinary, ["bin/hl/sys.hl"]);
  86. changeDirectory(getMiscSubDir("eventLoop"));
  87. runCommand("haxe", ["build-hl.hxml"]);
  88. // TODO: check output like misc tests do
  89. runCommand(hlBinary, ["eventLoop.hl"]);
  90. changeDirectory(getMiscSubDir("hl/reserved-keywords"));
  91. runCommand("haxe", ["compile.hxml"]);
  92. switch (systemName) {
  93. case "Linux" if (isCi()):
  94. runCommand("gcc", ["-o", "bin/test", "bin/test.c", "-Ibin/", '-I$hlSrc/src', '-L$hlBuildBinDir', "-lhl"]);
  95. runCommand("bin/test", []);
  96. case _:
  97. // TODO hl/c for mac/windows
  98. }
  99. changeDirectory(miscHlDir);
  100. runCommand("haxe", ["run.hxml"]);
  101. }
  102. }