crossbind 2.0.0-beta.62 → 2.0.0-beta.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/AGENTS.md +2 -1
  2. package/README.md +2 -2
  3. package/package.json +7 -2
  4. package/src/actions/buildBinTools.js +0 -0
  5. package/src/actions/buildDependencies.js +15 -2
  6. package/src/actions/buildExternal.js +9 -1
  7. package/src/actions/buildJs.js +2 -9
  8. package/src/actions/buildLib.js +25 -8
  9. package/src/actions/buildNativeCommand.js +84 -0
  10. package/src/actions/buildNode.js +49 -10
  11. package/src/actions/buildTypes.js +8 -2
  12. package/src/actions/buildWasiCommand.js +10 -9
  13. package/src/actions/buildWasm.js +72 -31
  14. package/src/actions/cloudCommands.js +133 -0
  15. package/src/actions/createImportedBridges.js +71 -0
  16. package/src/actions/createInterface.js +247 -68
  17. package/src/actions/createLib.js +70 -42
  18. package/src/actions/getData.js +6 -2
  19. package/src/actions/getEnv.js +7 -0
  20. package/src/actions/getLinkInputs.js +12 -5
  21. package/src/actions/isSourceNewer.js +2 -0
  22. package/src/actions/licenses.js +143 -19
  23. package/src/actions/prepareConanDependencies.js +51 -0
  24. package/src/actions/publishBinary.js +32 -0
  25. package/src/actions/run.js +63 -66
  26. package/src/actions/runnerCommands.js +433 -0
  27. package/src/actions/writeRuntimeEntry.js +80 -0
  28. package/src/assets/cmake/command/CMakeLists.txt +21 -0
  29. package/src/assets/cmake/command/command.cpp +1 -0
  30. package/src/assets/cmake/dist.cmake +2 -1
  31. package/src/assets/configure/install.sh +22 -0
  32. package/src/assets/cpp-runtime/node.cpp +18 -1
  33. package/src/assets/js-runtime/adapters/path-url.js +6 -3
  34. package/src/assets/js-runtime/adapters/unboundMessage.js +2 -0
  35. package/src/assets/js-runtime/adapters/worker-comlink.js +138 -60
  36. package/src/assets/js-runtime/core.js +12 -0
  37. package/src/assets/node-import-hooks.mjs +61 -0
  38. package/src/assets/toolchain-digests.json +19 -19
  39. package/src/assets/wasi-runtime/http/README.md +17 -0
  40. package/src/assets/wasi-runtime/http/bindings/crossbind_http.c +2537 -0
  41. package/src/assets/wasi-runtime/http/bindings/crossbind_http.h +826 -0
  42. package/src/assets/wasi-runtime/http/bindings/crossbind_http_component_type.o +0 -0
  43. package/src/assets/wasi-runtime/http/handler.cpp +298 -0
  44. package/src/assets/wasi-runtime/http/include/crossbind/http.h +31 -0
  45. package/src/assets/wasi-runtime/http/wit/deps/LICENSE.md +8 -0
  46. package/src/assets/wasi-runtime/http/wit/deps/cli.wit +28 -0
  47. package/src/assets/wasi-runtime/http/wit/deps/clocks.wit +43 -0
  48. package/src/assets/wasi-runtime/http/wit/deps/http.wit +509 -0
  49. package/src/assets/wasi-runtime/http/wit/deps/random.wit +18 -0
  50. package/src/assets/wasi-runtime/http/wit/world.wit +6 -0
  51. package/src/assets/wasi-runtime/stubs.c +29 -0
  52. package/src/bin.js +218 -161
  53. package/src/cli.js +14 -0
  54. package/src/index.js +3 -0
  55. package/src/integration/bindHeaderImports.js +18 -0
  56. package/src/integration/getCrossbindScript.js +50 -13
  57. package/src/integration/getDependFilePath.js +9 -0
  58. package/src/integration/resolveNativeImport.js +14 -0
  59. package/src/node/dev.mjs +19 -0
  60. package/src/program.js +169 -0
  61. package/src/runner/blobs.js +135 -0
  62. package/src/runner/files.js +193 -0
  63. package/src/runner/server.js +320 -0
  64. package/src/state/attachConanDependencies.js +56 -0
  65. package/src/state/index.js +20 -11
  66. package/src/state/loadConfig.js +37 -35
  67. package/src/state/refreshBuiltDependencies.js +20 -0
  68. package/src/state/refreshConanDependencies.js +17 -0
  69. package/src/utils/androidToolchain.js +4 -0
  70. package/src/utils/appRustCrates.js +19 -1
  71. package/src/utils/appSources.js +97 -6
  72. package/src/utils/archiveFlags.js +12 -0
  73. package/src/utils/boundHeaders.js +79 -0
  74. package/src/utils/bridgeExtras.js +554 -0
  75. package/src/utils/bridgeRuntimeFixes.js +48 -0
  76. package/src/utils/bundledLicenses.js +26 -0
  77. package/src/utils/cargoLock.js +19 -0
  78. package/src/utils/cargoTarget.js +21 -3
  79. package/src/utils/cloudAccount.js +55 -0
  80. package/src/utils/conanDependencies.js +66 -0
  81. package/src/utils/conanImport.js +58 -0
  82. package/src/utils/conanInstall.js +154 -0
  83. package/src/utils/conanProfile.js +203 -0
  84. package/src/utils/conanStage.js +292 -0
  85. package/src/utils/copyToDistSource.js +13 -0
  86. package/src/utils/cppDts.js +60 -15
  87. package/src/utils/darwinToolchain.js +11 -0
  88. package/src/utils/dirLock.js +137 -28
  89. package/src/utils/downloadAndExtractFile.js +34 -7
  90. package/src/utils/embindArgumentGuards.js +41 -2
  91. package/src/utils/embindCallArguments.js +19 -0
  92. package/src/utils/embindJspiQueue.js +25 -0
  93. package/src/utils/embindObjectLifetime.js +35 -0
  94. package/src/utils/execContainer.js +49 -0
  95. package/src/utils/headerImports.js +16 -5
  96. package/src/utils/hostPlatform.js +21 -0
  97. package/src/utils/iosToolchain.js +6 -0
  98. package/src/utils/isSourceCmakePackage.js +10 -0
  99. package/src/utils/licenseReport.js +11 -2
  100. package/src/utils/linuxToolchain.js +24 -0
  101. package/src/utils/makeTreeWritable.js +12 -0
  102. package/src/utils/nativeImports.js +23 -0
  103. package/src/utils/nativeSourceStamp.js +36 -0
  104. package/src/utils/nodeDevBuild.js +92 -0
  105. package/src/utils/packageLicense.js +103 -0
  106. package/src/utils/pthreadMainScript.js +14 -0
  107. package/src/utils/pullDockerImage.js +3 -1
  108. package/src/utils/relocatePrebuilt.js +119 -0
  109. package/src/utils/remoteClient.js +127 -0
  110. package/src/utils/remoteOutputs.js +39 -0
  111. package/src/utils/remoteRunner.js +97 -0
  112. package/src/utils/remoteUpload.js +134 -0
  113. package/src/utils/replaceFile.js +8 -0
  114. package/src/utils/resetCMakeCacheForSource.js +26 -0
  115. package/src/utils/runCargo.js +48 -51
  116. package/src/utils/runConan.js +257 -0
  117. package/src/utils/runtimeEntries.js +56 -0
  118. package/src/utils/rustBridgeGen.js +22 -8
  119. package/src/utils/rustMt.js +9 -0
  120. package/src/utils/rustSysroot.js +7 -5
  121. package/src/utils/scopedEmbind.js +22 -0
  122. package/src/utils/selectRunner.js +81 -0
  123. package/src/utils/sourceFingerprint.js +4 -3
  124. package/src/utils/swigInterface.js +70 -4
  125. package/src/utils/systemConfig.js +13 -0
  126. package/src/utils/systemKeys.js +35 -3
  127. package/src/utils/targets.js +60 -4
  128. package/src/utils/toolchainNotices.js +5 -0
  129. package/src/utils/wasiHttp.js +50 -0
  130. package/src/utils/wasiToolchain.js +14 -1
  131. package/src/utils/windowsToolchain.js +18 -0
  132. package/vitest.config.js +11 -0
@@ -0,0 +1,50 @@
1
+ // The runtime of an http build: crossbind's wasi:http/handler export, which calls the app's
2
+ // crossbind::http::handle, and the bindings wit-bindgen generated for it (assets/wasi-runtime/http/README.md).
3
+
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+
7
+ const RUNTIME = 'assets/wasi-runtime/http';
8
+ // The stack of each request: wasi-libc mallocs one per concurrent request, with no guard below it.
9
+ const STACK_SIZE = 1024 * 1024;
10
+ const HEADER = 'include/crossbind/http.h';
11
+ const LINKED = [
12
+ 'handler.cpp',
13
+ 'bindings/crossbind_http.c',
14
+ 'bindings/crossbind_http.h',
15
+ 'bindings/crossbind_http_component_type.o',
16
+ HEADER,
17
+ ];
18
+
19
+ // paths.cli can lie outside the docker mount, so the files are copied into the build tree first.
20
+ function stage(cliPath, dir, files) {
21
+ files.forEach((file) => {
22
+ fs.mkdirSync(path.dirname(`${dir}/${file}`), { recursive: true });
23
+ fs.copyFileSync(`${cliPath}/${RUNTIME}/${file}`, `${dir}/${file}`);
24
+ });
25
+ }
26
+
27
+ export const wasiHttpFiles = (cliPath) => LINKED.map((file) => `${cliPath}/${RUNTIME}/${file}`);
28
+
29
+ export const wasiHttpHeader = (cliPath) => `${cliPath}/${RUNTIME}/${HEADER}`;
30
+
31
+ // The include dir of a wasi source build, where the app's handler finds <crossbind/http.h>.
32
+ export function stageWasiHttpInclude(cliPath, dir) {
33
+ stage(cliPath, dir, [HEADER]);
34
+ return `${dir}/include`;
35
+ }
36
+
37
+ // What an http link adds to a command's: the handler export, its bindings (C, hence -x c) with the world
38
+ // they implement, the reactor model, which has no main, and a stack as large as the wasm builds'.
39
+ export function stageWasiHttpLink(cliPath, dir) {
40
+ stage(cliPath, dir, LINKED);
41
+ return [
42
+ `-I${dir}/include`,
43
+ `-I${dir}/bindings`,
44
+ `${dir}/handler.cpp`,
45
+ '-x', 'c', `${dir}/bindings/crossbind_http.c`, '-x', 'none',
46
+ `${dir}/bindings/crossbind_http_component_type.o`,
47
+ '-mexec-model=reactor',
48
+ `-Wl,-z,stack-size=${STACK_SIZE}`,
49
+ ];
50
+ }
@@ -1,5 +1,7 @@
1
1
  // Toolchain surface for platform:'wasi' (wasm32-wasip3, wasi-sdk >= 34; run under `wasmtime`).
2
2
 
3
+ import { isLocalRunner } from './selectRunner.js';
4
+
3
5
  export const WASI_TARGET_TRIPLE = 'wasm32-wasip3';
4
6
  // The sdk's clang still defaults to wasip1, so every compile/link carries --target explicitly.
5
7
  export const WASI_TARGET_FLAGS = [`--target=${WASI_TARGET_TRIPLE}`];
@@ -31,6 +33,7 @@ export const WASI_LINK_LIBS = [
31
33
  '-lunwind',
32
34
  '-lsetjmp',
33
35
  ...WASI_EMULATION_LIBS,
36
+ '-Wl,--wrap=lseek',
34
37
  ];
35
38
 
36
39
  export function wasiCFlags() {
@@ -41,7 +44,17 @@ export function wasiCxxFlags() {
41
44
  return [...WASI_TARGET_FLAGS, ...WASI_COMPILE_DEFINES, '-fwasm-exceptions', ...WASI_EH_CFLAGS];
42
45
  }
43
46
 
44
- // Env override first, then persistent ~/.crossbind.json; null when unset.
47
+ // The host sdk of a RUNNER=LOCAL build: env override first, then persistent ~/.crossbind.json; null when
48
+ // unset, and under the other runners, whose builds use the sdk in the image.
45
49
  export function resolveWasiSdkPath(system, env = process.env) {
50
+ if (!isLocalRunner(system, env)) return null;
46
51
  return env.CROSSBIND_WASI_SDK_PATH || system?.WASI_SDK_PATH || null;
47
52
  }
53
+
54
+ // Recipes read the wasi-sdk location from the environment (lazily, in getBuildParams), so it names
55
+ // the sdk the build uses: the host's under RUNNER=LOCAL, none (the image's) under the other runners.
56
+ export function exportWasiSdkPath(system, env = process.env) {
57
+ const sdk = resolveWasiSdkPath(system, env);
58
+ if (sdk) env.CROSSBIND_WASI_SDK_PATH = sdk;
59
+ else delete env.CROSSBIND_WASI_SDK_PATH;
60
+ }
@@ -0,0 +1,18 @@
1
+ // The windows image's llvm-mingw and its CMake toolchain files, one per target triple: port archives and
2
+ // Conan packages link into the same addon, so they move together.
3
+ const LLVM_MINGW = '/opt/llvm-mingw';
4
+ const WINDOWS_TOOLCHAIN = '/opt/crossbind/windows';
5
+ const WINDOWS_TRIPLES = { x64: 'x86_64-w64-mingw32', arm64: 'aarch64-w64-mingw32' };
6
+
7
+ export const windowsTriple = (target) => WINDOWS_TRIPLES[target.arch];
8
+ export const windowsToolchainFile = (target) => `${WINDOWS_TOOLCHAIN}/${windowsTriple(target)}.cmake`;
9
+ export const windowsTool = (target, name) => `${LLVM_MINGW}/bin/${windowsTriple(target)}-${name}`;
10
+
11
+ // The compilers, archive and resource tools of the target's triple, by the variables build systems read
12
+ // them from. The image's own .pc files describe its libraries, not the target's, so pkg-config reads none.
13
+ export const windowsBuildEnv = (target) => ({
14
+ ...Object.fromEntries(Object.entries({
15
+ CC: 'clang', CXX: 'clang++', AR: 'ar', RANLIB: 'ranlib', NM: 'nm', STRIP: 'strip', RC: 'windres', WINDRES: 'windres',
16
+ }).map(([variable, tool]) => [variable, windowsTool(target, tool)])),
17
+ PKG_CONFIG_LIBDIR: '',
18
+ });
package/vitest.config.js CHANGED
@@ -12,6 +12,17 @@ export default defineConfig({
12
12
  test: {
13
13
  include: ['test/**/*.test.js'],
14
14
  environment: 'node',
15
+ // A developer's own runner settings must not decide where the tested steps run, and neither must their
16
+ // crossbind login: no one signs in to a cloud at this address.
17
+ env: {
18
+ CROSSBIND_RUNNER: '',
19
+ CROSSBIND_REMOTE_URL: '',
20
+ CROSSBIND_REMOTE_URL_WEB: '',
21
+ CROSSBIND_REMOTE_URL_ANDROID: '',
22
+ CROSSBIND_REMOTE_URL_LINUX: '',
23
+ CROSSBIND_REMOTE_URL_WINDOWS: '',
24
+ CROSSBIND_CLOUD_URL: 'http://127.0.0.1:9',
25
+ },
15
26
  coverage: {
16
27
  provider: 'v8',
17
28
  reporter: ['text', 'html'],