Skip to content

Commit efd60fa

Browse files
SyndamiaPetarKirov
authored andcommitted
fix(pkgs/zkm): Build internal go library
Recently ZKMips copied a Go library from their SDK to the ZKM repo. Before we evaded the issue by not building the Rust package, which builds the Go library. This is no longer viable, because the library has been officially moved (i.e. removed from the SDK). Now we're building it ourselves, and removing the go build command from the appropriate build.rs
1 parent 8093465 commit efd60fa

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

packages/zkm/default.nix

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
fetchzip,
77
pkg-config,
88
openssl,
9+
buildGoModule,
910
...
1011
}:
1112
let
@@ -29,6 +30,28 @@ let
2930
};
3031
};
3132

33+
zkm_libsnark = buildGoModule rec {
34+
pname = "zkmgnark";
35+
36+
inherit (commonArgs) version src;
37+
38+
sourceRoot = "${src.name}/recursion/src/snark/libsnark";
39+
40+
vendorHash = "sha256-zZNyMW0KGBtk8k4bW8UP9LAar+ZLfJCdrCYOp5u8osc=";
41+
42+
# Taken from
43+
# https://github.com/zkMIPS/zkm/blob/b8014509756b34bb92f90301801d67e7a3645094/recursion/build.rs#L9-L21
44+
CGO_ENABLED = 1;
45+
buildPhase = ''
46+
go build -tags=debug -o ./lib${pname}.a -buildmode=c-archive .
47+
'';
48+
49+
installPhase = ''
50+
mkdir -p "$out"/lib
51+
mv ./lib${pname}.a "$out"/lib/
52+
'';
53+
};
54+
3255
rust-toolchain = zkm-rust;
3356
crane = craneLib.overrideToolchain rust-toolchain;
3457
cargoArtifacts = crane.buildDepsOnly commonArgs;
@@ -41,11 +64,15 @@ crane.buildPackage (
4164

4265
preBuild = ''
4366
export HOME=$PWD
44-
'';
4567
46-
cargoBuildCommand = "cargo build --release -p zkm-runtime -p zkm-emulator -p zkm-prover -p zkm-build";
68+
export OUT_DIR="${zkm_libsnark}/lib" RUSTFLAGS="$RUSTFLAGS -L ${zkm_libsnark}/lib"
69+
sed -i '9,24d' recursion/build.rs
70+
'';
4771

4872
postInstall = ''
73+
mkdir -p "$out"/lib
74+
ln -s "${zkm_libsnark}"/lib/* "$out"/lib
75+
4976
rm "$out"/bin/cargo
5077
cat <<EOF > "$out"/bin/cargo
5178
#!/usr/bin/env sh

0 commit comments

Comments
 (0)