windows-runtime-host-build.test.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import assert from "node:assert/strict";
  2. import { test } from "node:test";
  3. import { resolveRuntimeHostBuild, verifyRuntimeHostPe } from "../build-windows-runtime-host.mjs";
  4. test("Windows builds both supported architectures with the matching MSVC target", () => {
  5. assert.deepEqual(resolveRuntimeHostBuild("x64", "win32").configureArgs, [
  6. "-G",
  7. "Visual Studio 17 2022",
  8. "-A",
  9. "x64",
  10. ]);
  11. assert.deepEqual(resolveRuntimeHostBuild("arm64", "win32").configureArgs, [
  12. "-G",
  13. "Visual Studio 17 2022",
  14. "-A",
  15. "ARM64",
  16. ]);
  17. assert.throws(() => resolveRuntimeHostBuild("ia32", "win32"), /architecture/);
  18. });
  19. test("cross builds explicitly select a Windows compiler", () => {
  20. assert.ok(
  21. resolveRuntimeHostBuild("x64", "linux").configureArgs.includes("-DCMAKE_SYSTEM_NAME=Windows"),
  22. );
  23. assert.ok(
  24. resolveRuntimeHostBuild("arm64", "linux", "example-clang++").configureArgs.includes(
  25. "-DCMAKE_CXX_COMPILER=example-clang++",
  26. ),
  27. );
  28. });
  29. test("packaging rejects wrong-architecture and corrupt PE binaries", () => {
  30. const bytes = Buffer.alloc(128);
  31. bytes.write("MZ");
  32. bytes.writeUInt32LE(64, 60);
  33. bytes.write("PE\0\0", 64);
  34. bytes.writeUInt16LE(0x8664, 68);
  35. verifyRuntimeHostPe(bytes, "x64");
  36. assert.throws(() => verifyRuntimeHostPe(bytes, "arm64"), /architecture/);
  37. assert.throws(() => verifyRuntimeHostPe(Buffer.from("bad"), "x64"), /PE/);
  38. });