diff --git a/packages/wasmd/default.nix b/packages/wasmd/default.nix index 5cb54ac8..02dbf8de 100644 --- a/packages/wasmd/default.nix +++ b/packages/wasmd/default.nix @@ -5,6 +5,11 @@ buildGoModule, autoPatchelfHook, }: +let + wasmvmLib = if stdenv.isLinux then "libwasmvm.x86_64.so" + else if stdenv.isDarwin then "libwasmvm.dylib" + else throw "platform not supported"; +in buildGoModule rec { pname = "wasmd"; version = "0.14.99"; @@ -19,21 +24,33 @@ buildGoModule rec { subPackages = ["cmd/wasmd"]; - buildInputs = [autoPatchelfHook]; + buildInputs = [] ++ lib.optional stdenv.isLinux [autoPatchelfHook]; postBuild = '' mkdir -p "$out/lib" # TODO: The correct binary below should depend on the current OS and CPU - cp "$GOPATH/pkg/mod/github.com/!cosm!wasm/wasmvm@v1.0.0/api/libwasmvm.x86_64.so" "$out/lib" + cp "$GOPATH/pkg/mod/github.com/!cosm!wasm/wasmvm@v1.0.0/api/${wasmvmLib}" "$out/lib" ''; - postInstall = '' + postInstall = if stdenv.isLinux then '' addAutoPatchelfSearchPath "$out/lib" # TODO: autoPatchElf is Linux-specific. We need a cross-platform solution autoPatchelf -- "$out/bin" - ''; + '' else + # TODO + # The package is still not working because we are missing the equivalent + # of autopatchelf for macOS. The "libwasmvm.dylib" is currently distributed + # as a pre-built binary by the wasmd team (it's stored in git). This leads + # to the final wasmd binary having a `rpath` which cannot be satisfied at + # run-time with Nix. + ""; + + vendorSha256 = if stdenv.isLinux then + "sha256-4vW1+vGOwbaE6fVXtHjKMheX9UpiY7WVh7QCC57QQUM=" + else if stdenv.isDarwin then + "sha256-vACKDwUP52iSjb0DC+dIuNrOeBMLnKBDYsNpQrq3IqI=" + else ""; - vendorSha256 = "sha256-4vW1+vGOwbaE6fVXtHjKMheX9UpiY7WVh7QCC57QQUM="; doCheck = false; meta = with lib; { description = "Basic cosmos-sdk app with web assembly smart contracts"; diff --git a/shell.nix b/shell.nix index d51777c4..8281e4f2 100644 --- a/shell.nix +++ b/shell.nix @@ -12,12 +12,12 @@ with pkgs; # Packages defined in this repo metacraft-labs.cosmos-theta-testnet metacraft-labs.circom + metacraft-labs.wasmd metacraft-labs.circ ] ++ lib.optionals (!stdenv.isDarwin) [ # Solana is still not compatible with macOS on M1 metacraft-labs.solana - metacraft-labs.wasmd ]; shellHook = ''