codex-storage-proofs/codex_storage_proofs.nim

39 lines
971 B
Nim
Raw Normal View History

import std/os
2023-12-22 18:24:12 -07:00
import std/strutils
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
2023-12-22 19:51:25 -07:00
proc len*(buff: Buffer): int =
buff.len.int
2023-12-22 19:45:17 -07:00
template unsafeBufferPath*(path: var string): Buffer =
2023-12-22 19:40:03 -07:00
assert path.len() > 0
2023-12-22 19:45:17 -07:00
Buffer(data: cast[ptr uint8](path.cstring),
len: path.len().uint)
template unsafeBufferFromFile*(path: string): Buffer =
assert path.len() > 0
let entireFile = readFile(path)
Buffer(data: cast[ptr uint8](entireFile.cstring),
len: entireFile.len().uint)