Main.hx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import sys.io.Process;
  2. using StringTools;
  3. enum abstract Arch(String) {
  4. final Arm64;
  5. final Arm;
  6. final X86;
  7. final X86_64;
  8. public function getNdllSuffix():String {
  9. return switch abstract {
  10. case Arm64: "Arm64";
  11. case Arm: "Arm";
  12. case X86_64: "64";
  13. case X86: "";
  14. };
  15. }
  16. }
  17. function getArchWindows() {
  18. return switch Sys.getEnv("PROCESSOR_ARCHITECTURE") {
  19. case "x86": X86;
  20. case "AMD64": X86_64;
  21. case "ARM64": Arm64;
  22. case other: throw 'Unknown CPU architecture: $other';
  23. };
  24. }
  25. function getArchUnix() {
  26. final uname = new Process("uname", ["-m"]);
  27. final arch = try {
  28. uname.stdout.readLine();
  29. } catch (e:haxe.io.Eof) {
  30. "";
  31. };
  32. uname.kill();
  33. uname.close();
  34. return switch arch {
  35. case "x86_64" | "amd64": X86_64;
  36. case "i386" | "x86": X86;
  37. case "arm64" | "aarch64": Arm64;
  38. case "arm": Arm;
  39. case other: throw 'Unknown CPU architecture: "$other"';
  40. };
  41. }
  42. function getArch() {
  43. return switch Sys.systemName() {
  44. case "Windows": getArchWindows();
  45. default: getArchUnix();
  46. };
  47. }
  48. function main() {
  49. final arch = getArch();
  50. final expectedNdllSubDir = Sys.systemName() + arch.getNdllSuffix() + "/";
  51. final ndllPath = neko.vm.Loader.local().getPath()[0];
  52. if (ndllPath.endsWith(expectedNdllSubDir)) {
  53. Sys.println("Success");
  54. } else {
  55. Sys.println('Failure: Expected $ndllPath to end with $expectedNdllSubDir');
  56. }
  57. }