@mainsail/evm 0.0.1-evm.51 → 0.0.1-evm.53
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.
- package/Cargo.lock +5922 -0
- package/Cargo.toml +34 -0
- package/bindings/Cargo.toml +33 -0
- package/bindings/build.rs +6 -0
- package/bindings/src/ctx.rs +667 -0
- package/bindings/src/lib.rs +2231 -0
- package/bindings/src/logger.rs +110 -0
- package/bindings/src/result.rs +542 -0
- package/bindings/src/utils.rs +71 -0
- package/core/Cargo.toml +36 -0
- package/core/src/account.rs +112 -0
- package/core/src/bytecode.rs +39 -0
- package/core/src/compression.rs +158 -0
- package/core/src/db.rs +3311 -0
- package/core/src/events.rs +9 -0
- package/core/src/historical.rs +544 -0
- package/core/src/legacy.rs +153 -0
- package/core/src/lib.rs +14 -0
- package/core/src/logger.rs +98 -0
- package/core/src/logs_bloom.rs +96 -0
- package/core/src/precompiles.rs +450 -0
- package/core/src/receipt.rs +153 -0
- package/core/src/state_changes.rs +122 -0
- package/core/src/state_commit.rs +615 -0
- package/core/src/state_root.rs +266 -0
- package/index.d.ts +1 -0
- package/index.js +52 -52
- package/package.json +5 -4
- package/scripts/postinstall.mjs +73 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Builds the EVM native addon from source on platforms that have no prebuilt binary.
|
|
2
|
+
//
|
|
3
|
+
// Prebuilt `.node` binaries are delivered through the `optionalDependencies` in package.json
|
|
4
|
+
// (currently only linux x64/arm64 gnu). On any other platform npm/pnpm silently skip those
|
|
5
|
+
// optional packages and the napi loader in index.js finds no binding. This script runs on
|
|
6
|
+
// install and, when no binding is available, compiles one from the Rust source shipped in the
|
|
7
|
+
// tarball using the bundled @napi-rs/cli (so the package works on macOS, musl, etc.).
|
|
8
|
+
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { dirname, join, sep } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const packageDir = dirname(scriptDir);
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
const log = (message) => console.log(`[@mainsail/evm] ${message}`);
|
|
20
|
+
const warn = (message) => console.warn(`[@mainsail/evm] ${message}`);
|
|
21
|
+
|
|
22
|
+
const force = process.env.MAINSAIL_EVM_FORCE_POSTINSTALL === "1";
|
|
23
|
+
|
|
24
|
+
// In the monorepo source checkout the native addon is built explicitly via `pnpm run build:rs`,
|
|
25
|
+
// not on install — building here too would slow every `pnpm install`. Only run when this package
|
|
26
|
+
// is installed as a dependency (i.e. it lives under a node_modules directory).
|
|
27
|
+
const installedAsDependency = packageDir.split(sep).includes("node_modules");
|
|
28
|
+
if (!installedAsDependency && !force) {
|
|
29
|
+
log("source checkout detected; skipping postinstall (build with `pnpm run build:rs`).");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A binding may already be available: a prebuilt optionalDependency on a supported platform, or a
|
|
34
|
+
// previous from-source build. The napi loader in index.js resolves both, so reuse it.
|
|
35
|
+
try {
|
|
36
|
+
require(join(packageDir, "index.js"));
|
|
37
|
+
log("native binding available; nothing to build.");
|
|
38
|
+
process.exit(0);
|
|
39
|
+
} catch {
|
|
40
|
+
// No binding could be loaded — fall through and build one from source.
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
log(`no prebuilt binding for ${process.platform}-${process.arch}; building from source.`);
|
|
44
|
+
|
|
45
|
+
// Building from source needs the Rust source (shipped in the tarball) ...
|
|
46
|
+
const manifestPath = join(packageDir, "bindings", "Cargo.toml");
|
|
47
|
+
if (!existsSync(manifestPath)) {
|
|
48
|
+
warn("Rust source not found; cannot build the native addon. The package will not work on this platform.");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ... and a Rust toolchain.
|
|
53
|
+
if (spawnSync("cargo", ["--version"], { stdio: "ignore" }).status !== 0) {
|
|
54
|
+
warn("a Rust toolchain is required to build the native addon on this platform.");
|
|
55
|
+
warn("install Rust from https://rustup.rs, then reinstall this package.");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Compile via the bundled @napi-rs/cli, mirroring the package's `build-napi` script. `--platform`
|
|
60
|
+
// makes napi name the output `evm.<host-triple>.node`, which index.js loads relative to itself.
|
|
61
|
+
const napiCli = join(dirname(require.resolve("@napi-rs/cli/package.json")), "dist", "cli.js");
|
|
62
|
+
const result = spawnSync(
|
|
63
|
+
process.execPath,
|
|
64
|
+
[napiCli, "build", "--platform", "--release", "--manifest-path", "bindings/Cargo.toml", "--output-dir", "."],
|
|
65
|
+
{ cwd: packageDir, stdio: "inherit" },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (result.status !== 0) {
|
|
69
|
+
warn("failed to build the native addon from source.");
|
|
70
|
+
process.exit(result.status ?? 1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
log("native addon built successfully.");
|