logos-storage-proofs/codex_storage_proofs.nim

43 lines
1.1 KiB
Nim
Raw Normal View History

import std/os
2023-12-22 18:24:12 -07:00
import std/strutils
import std/sha1
import std/macros
2023-12-22 18:07:17 -07:00
const
currentDir = currentSourcePath().parentDir()
2023-12-22 18:45:26 -07:00
libDir* = currentDir/"target"/"release"
libPath* = libDir/"libcodex_storage_proofs.a"
2023-12-22 18:07:17 -07:00
static:
2023-12-22 18:24:12 -07:00
let cmd = "cargo build --release"
2023-12-22 18:28:15 -07:00
warning "\nBuilding codex-storage-proofs: " & cmd
2023-12-22 18:07:17 -07:00
let (output, exitCode) = gorgeEx cmd
2023-12-22 18:24:12 -07:00
for ln in output.splitLines():
2023-12-22 18:28:15 -07:00
warning("cargo> " & ln)
2023-12-22 18:07:17 -07:00
if exitCode != 0:
raise (ref Defect)(msg: "Failed to build codex-storage-proofs")
2023-12-22 18:45:26 -07:00
{.passl: "-lcodex_storage_proofs" & " -L" & libDir.}
2023-12-22 19:03:43 -07:00
2023-12-22 19:40:03 -07:00
include codex_proofs_ffi
proc unsafeBufferPath*(path: var string): Buffer =
assert path.len() > 0
Buffer(data: cast[ptr uint8](path.cstring), len: path.len().uint)
2023-12-22 19:05:31 -07:00
when isMainModule:
2023-12-22 19:40:03 -07:00
var
r1cs_path = "src/circuit_tests/artifacts/storer-test.r1cs"
wasm_path = "src/circuit_tests/artifacts/storer-test_js/storer-test.wasm"
let
r1cs_buff = unsafeBufferPath(r1cs_path)
wasm_buff = unsafeBufferPath(wasm_path)
let storage_ctx = init_storage_proofs(r1cs_buff, wasm_buff, nil)
echo "storage_ctx: ", storage_ctx.repr
assert storage_ctx != nil