Hl.hx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 function buildAndRunHlc(dir:String, filename:String, ?run) {
  61. if (run == null) run = runCommand;
  62. switch (systemName) {
  63. case "Linux" if (isCi()):
  64. runCommand("gcc", [
  65. "-o", '$dir/$filename.exe',
  66. '$dir/$filename.c',
  67. '-I$dir',
  68. '-I$hlSrc/src',
  69. '$hlBuildBinDir/fmt.hdll',
  70. '$hlBuildBinDir/ssl.hdll',
  71. '$hlBuildBinDir/sqlite.hdll',
  72. "-lm",
  73. '-L$hlBuildBinDir', "-lhl"
  74. ]);
  75. run('$dir/$filename.exe', []);
  76. case _: // TODO hl/c for mac/windows
  77. }
  78. }
  79. static function buildAndRun(hxml:String, target:String, ?args:Array<String>) {
  80. if (args == null) args = [];
  81. runCommand("haxe", [hxml, "-hl", '$target/hl-jit.hl'].concat(args));
  82. runCommand(hlBinary, ['$target/hl-jit.hl']);
  83. runCommand("haxe", [hxml, "-hl", '$target/hlc.c'].concat(args));
  84. buildAndRunHlc(target, "hlc");
  85. }
  86. static public function run(args:Array<String>) {
  87. getHlDependencies();
  88. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  89. runCommand(hlBinary, ['bin/unit.hl']);
  90. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  91. buildAndRunHlc("bin/hlc", "unit", runCommand);
  92. changeDirectory(threadsDir);
  93. buildAndRun("build.hxml", "export/threads");
  94. changeDirectory(sysDir);
  95. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  96. runSysTest(hlBinary, ["bin/hl/sys.hl"]);
  97. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  98. function dontRun(cmd,?args) {}
  99. buildAndRunHlc("bin/hlc/testArguments", "TestArguments", dontRun);
  100. buildAndRunHlc("bin/hlc/exitCode", "ExitCode", dontRun);
  101. buildAndRunHlc("bin/hlc/utilityProcess", "UtilityProcess", dontRun);
  102. buildAndRunHlc("bin/hlc/sys", "sys", (cmd, ?args) -> runSysTest(FileSystem.fullPath(cmd), args));
  103. changeDirectory(getMiscSubDir("eventLoop"));
  104. buildAndRun("build-hl.hxml", "bin/eventLoop");
  105. changeDirectory(getMiscSubDir("hl/reservedKeywords"));
  106. buildAndRun("compile.hxml", "bin/reservedKeywords");
  107. changeDirectory(miscHlDir);
  108. runCommand("haxe", ["run.hxml"]);
  109. }
  110. }