Hl.hx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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([
  32. "libpng-dev",
  33. "libjpeg-turbo8-dev",
  34. "libturbojpeg",
  35. "zlib1g-dev",
  36. "libvorbis-dev",
  37. "libsqlite3-dev",
  38. "libuv1-dev"]);
  39. case "Mac":
  40. case "Windows":
  41. //pass
  42. }
  43. FileSystem.createDirectory(hlBuild);
  44. final args = systemName == "Windows" ? ["-DCMAKE_SYSTEM_VERSION=10.0.19041.0"] : ["-GNinja"];
  45. if (systemName == "Mac") {
  46. args.push("-DDOWNLOAD_DEPENDENCIES=ON");
  47. args.push("-DCMAKE_OSX_ARCHITECTURES=x86_64");
  48. }
  49. runCommand("cmake", args.concat([
  50. "-DBUILD_TESTING=OFF",
  51. "-DWITH_DIRECTX=OFF",
  52. "-DWITH_FMT=ON",
  53. "-DWITH_OPENAL=OFF",
  54. "-DWITH_SDL=OFF",
  55. "-DWITH_SQLITE=ON",
  56. "-DWITH_SSL=ON",
  57. "-DWITH_UI=OFF",
  58. "-DWITH_UV=ON",
  59. "-DWITH_VIDEO=OFF",
  60. "-DCMAKE_INSTALL_PREFIX=" + hlInstallDir,
  61. "-B" + hlBuild,
  62. "-H" + hlSrc
  63. ]));
  64. runCommand("cmake", [
  65. "--build", hlBuild
  66. ]);
  67. runCommand("cmake", ["--build", hlBuild, "--target", "install"]);
  68. addToPATH(hlInstallBinDir);
  69. addToLIBPATH(hlInstallLibDir);
  70. runCommand(hlBinary, ["--version"]);
  71. haxelibDev("hashlink", '$hlSrc/other/haxelib/');
  72. Sys.putEnv("HASHLINK", hlInstallDir);
  73. if (systemName == "Windows") {
  74. Sys.putEnv("HASHLINK_SRC", hlSrc);
  75. Sys.putEnv("HASHLINK_BIN", hlInstallBinDir);
  76. }
  77. }
  78. static function buildAndRunHlc(dir:String, filename:String, ?run) {
  79. if (run == null) run = runCommand;
  80. if (!isCi())
  81. return;
  82. final compiler = if (systemName == "Mac") "clang" else "gcc";
  83. final extraCompilerFlags = switch (systemName) {
  84. case "Windows": ["-ldbghelp", "-municode"];
  85. case "Mac": ["-arch", "x86_64"];
  86. case _: [];
  87. };
  88. runCommand(compiler, [
  89. "-o", '$dir/$filename.exe',
  90. '$dir/$filename.c',
  91. '-I$dir',
  92. '-I$hlInstallDir/include',
  93. '-L$hlInstallLibDir',
  94. '$hlInstallLibDir/fmt.hdll',
  95. '$hlInstallLibDir/ssl.hdll',
  96. '$hlInstallLibDir/sqlite.hdll',
  97. '$hlInstallLibDir/uv.hdll',
  98. "-lm",
  99. "-lhl"
  100. ].concat(extraCompilerFlags));
  101. run('$dir/$filename.exe', []);
  102. // Run with MSBuild
  103. if (systemName == "Windows") {
  104. runCommand("MSBuild.exe", [
  105. '$dir/$filename.sln',
  106. '-nologo', '-verbosity:minimal',
  107. '-t:$filename',
  108. '-property:Configuration=Release',
  109. '-property:Platform=x64'
  110. ]);
  111. run('$dir/x64/Release/$filename.exe', []);
  112. }
  113. }
  114. static function buildAndRun(hxml:String, target:String, ?args:Array<String>) {
  115. if (args == null) args = [];
  116. runCommand("haxe", [hxml, "-hl", '$target/hl-jit.hl'].concat(args));
  117. runCommand(hlBinary, ['$target/hl-jit.hl']);
  118. runCommand("haxe", [hxml, "-hl", '$target/hlc.c', "-D", "hlgen.makefile=ci"].concat(args));
  119. buildAndRunHlc(target, "hlc");
  120. }
  121. static public function run(args:Array<String>) {
  122. getHlDependencies();
  123. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  124. runCommand(hlBinary, ['bin/unit.hl']);
  125. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  126. buildAndRunHlc("bin/hlc", "unit", runCommand);
  127. runCommand("haxe", ["compile-hl.hxml", "--undefine", "analyzer-optimize"].concat(args));
  128. runCommand(hlBinary, ['bin/unit.hl']);
  129. runCommand("haxe", ["compile-hlc.hxml", "--undefine", "analyzer-optimize"].concat(args));
  130. buildAndRunHlc("bin/hlc", "unit", runCommand);
  131. changeDirectory(threadsDir);
  132. buildAndRun("build.hxml", "export/threads");
  133. Display.maybeRunDisplayTests(Hl);
  134. changeDirectory(sysDir);
  135. runCommand("haxe", ["compile-hl.hxml"].concat(args));
  136. runSysTest(hlBinary, ["bin/hl/sys.hl"]);
  137. runCommand("haxe", ["compile-hlc.hxml"].concat(args));
  138. function dontRun(cmd,?args) {}
  139. buildAndRunHlc("bin/hlc/testArguments", "TestArguments", dontRun);
  140. buildAndRunHlc("bin/hlc/exitCode", "ExitCode", dontRun);
  141. buildAndRunHlc("bin/hlc/utilityProcess", "UtilityProcess", dontRun);
  142. buildAndRunHlc("bin/hlc/sys", "sys", (cmd, ?args) -> runSysTest(FileSystem.fullPath(cmd), args));
  143. changeDirectory(getMiscSubDir("eventLoop"));
  144. buildAndRun("build-hl.hxml", "bin/eventLoop");
  145. changeDirectory(getMiscSubDir("hl/reservedKeywords"));
  146. buildAndRun("compile.hxml", "bin/reservedKeywords");
  147. changeDirectory(miscHlDir);
  148. if (systemName == "Windows") {
  149. runCommand("haxe", ["run.hxml", "-D", "hlgen.makefile=vs2022"]);
  150. } else if (systemName == "Mac") {
  151. runCommand("arch", ["-x86_64", "haxe", "run.hxml", "-D", "hlgen.makefile=make"]);
  152. } else {
  153. runCommand("haxe", ["run.hxml", "-D", "hlgen.makefile=make"]);
  154. }
  155. }
  156. }