Hl.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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([getDownloadPath(), "hashlink_build"]);
  10. static final hlInstallDir = Path.join([getInstallPath(), "hashlink"]);
  11. static final hlInstallBinDir = if (systemName == "Windows") hlInstallDir else Path.join([hlInstallDir, "bin"]);
  12. static final hlInstallLibDir = if (systemName == "Windows") hlInstallDir else Path.join([hlInstallDir, "lib"]);
  13. static final hlBinary =
  14. if (isCi() || !commandSucceed("hl", ["--version"])){
  15. Path.join([hlInstallBinDir, "hl"]) + ((systemName == "Windows") ? ".exe" : "");
  16. } else {
  17. commandResult(if(systemName == "Windows") "where" else "which", ["hl"]).stdout.trim();
  18. };
  19. static final miscHlDir = getMiscSubDir('hl');
  20. static public function getHlDependencies() {
  21. if (!isCi() && FileSystem.exists(hlBinary)) {
  22. infoMsg('hl has already been installed at $hlBinary.');
  23. return;
  24. }
  25. if (!FileSystem.exists(hlSrc))
  26. runCommand("git", ["clone", "https://github.com/HaxeFoundation/hashlink.git", hlSrc]);
  27. else
  28. infoMsg("Reusing hashlink repository");
  29. switch (systemName) {
  30. case "Linux":
  31. Linux.requireAptPackages(["libpng-dev", "libjpeg-turbo8-dev", "libturbojpeg", "zlib1g-dev", "libvorbis-dev", "libsqlite3-dev"]);
  32. case "Mac":
  33. runNetworkCommand("brew", ["update", '--auto-update']);
  34. runNetworkCommand("brew", ["bundle", '--file=${hlSrc}/Brewfile']);
  35. case "Windows":
  36. //pass
  37. }
  38. FileSystem.createDirectory(hlBuild);
  39. final generator = systemName == "Windows" ? ["-DCMAKE_SYSTEM_VERSION=10.0.19041.0"] : ["-GNinja"];
  40. runCommand("cmake", generator.concat([
  41. "-DBUILD_TESTING=OFF",
  42. "-DWITH_DIRECTX=OFF",
  43. "-DWITH_FMT=ON",
  44. "-DWITH_OPENAL=OFF",
  45. "-DWITH_SDL=OFF",
  46. "-DWITH_SQLITE=ON",
  47. "-DWITH_SSL=ON",
  48. "-DWITH_UI=OFF",
  49. "-DWITH_UV=OFF",
  50. "-DWITH_VIDEO=OFF",
  51. "-DCMAKE_INSTALL_PREFIX=" + hlInstallDir,
  52. "-B" + hlBuild,
  53. "-H" + hlSrc
  54. ]));
  55. runCommand("cmake", [
  56. "--build", hlBuild
  57. ]);
  58. runCommand("cmake", ["--build", hlBuild, "--target", "install"]);
  59. addToPATH(hlInstallBinDir);
  60. addToLIBPATH(hlInstallLibDir);
  61. runCommand(hlBinary, ["--version"]);
  62. haxelibDev("hashlink", '$hlSrc/other/haxelib/');
  63. }
  64. static function buildAndRunHlc(dir:String, filename:String, ?run) {
  65. if (run == null) run = runCommand;
  66. if (!isCi())
  67. return;
  68. final compiler = if (systemName == "Mac") "clang" else "gcc";
  69. final extraCompilerFlags = if (systemName == "Windows") ["-ldbghelp", "-municode"] else [];
  70. runCommand(compiler, [
  71. "-o", '$dir/$filename.exe',
  72. '$dir/$filename.c',
  73. '-I$dir',
  74. '-I$hlInstallDir/include',
  75. '-L$hlInstallLibDir',
  76. '$hlInstallLibDir/fmt.hdll',
  77. '$hlInstallLibDir/ssl.hdll',
  78. '$hlInstallLibDir/sqlite.hdll',
  79. "-lm",
  80. "-lhl"
  81. ].concat(extraCompilerFlags));
  82. run('$dir/$filename.exe', []);
  83. }
  84. static function buildAndRun(hxml:String, target:String, ?args:Array<String>) {
  85. if (args == null) args = [];
  86. runCommand("haxe", [hxml, "-hl", '$target/hl-jit.hl'].concat(args));
  87. runCommand(hlBinary, ['$target/hl-jit.hl']);
  88. runCommand("haxe", [hxml, "-hl", '$target/hlc.c'].concat(args));
  89. buildAndRunHlc(target, "hlc");
  90. }
  91. static public function run(args:Array<String>) {
  92. getHlDependencies();
  93. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  94. runCommand(hlBinary, ['bin/unit.hl']);
  95. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  96. buildAndRunHlc("bin/hlc", "unit", runCommand);
  97. changeDirectory(threadsDir);
  98. buildAndRun("build.hxml", "export/threads");
  99. changeDirectory(sysDir);
  100. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  101. runSysTest(hlBinary, ["bin/hl/sys.hl"]);
  102. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  103. function dontRun(cmd,?args) {}
  104. buildAndRunHlc("bin/hlc/testArguments", "TestArguments", dontRun);
  105. buildAndRunHlc("bin/hlc/exitCode", "ExitCode", dontRun);
  106. buildAndRunHlc("bin/hlc/utilityProcess", "UtilityProcess", dontRun);
  107. buildAndRunHlc("bin/hlc/sys", "sys", (cmd, ?args) -> runSysTest(FileSystem.fullPath(cmd), args));
  108. changeDirectory(getMiscSubDir("eventLoop"));
  109. buildAndRun("build-hl.hxml", "bin/eventLoop");
  110. changeDirectory(getMiscSubDir("hl/reservedKeywords"));
  111. buildAndRun("compile.hxml", "bin/reservedKeywords");
  112. changeDirectory(miscHlDir);
  113. runCommand("haxe", ["run.hxml"]);
  114. }
  115. }