Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
};
inherit (nixpkgs) lib;

proto-js-bundle-drv = import ./nix/proto-to-js.nix {pkgs = nixpkgs;};

# We use cabalProject' to ensure we don't build the plan for
# all systems.
cabalProject = nixpkgs.haskell-nix.cabalProject' ({config, ...}: {
Expand Down Expand Up @@ -150,7 +152,11 @@
};
};
})
({pkgs, config, ...}: let
({
pkgs,
config,
...
}: let
generatedExampleFiles = ["cardano-wasm/lib-wrapper/cardano-api.d.ts"];
exportWasmPath = "export CARDANO_WASM=${config.hsPkgs.cardano-wasm.components.exes.cardano-wasm}/bin/cardano-wasm${pkgs.stdenv.hostPlatform.extensions.executable}";
in {
Expand Down Expand Up @@ -208,16 +214,16 @@
};
};
playwrightShell = let
playwright-pkgs = inputs.nixpkgs.legacyPackages.${system};
in {
playwright = playwright-pkgs.mkShell {
packages = [
playwright-pkgs.playwright-test
playwright-pkgs.python313Packages.docopt
playwright-pkgs.python313Packages.httpserver
];
};
playwright-pkgs = inputs.nixpkgs.legacyPackages.${system};
in {
playwright = playwright-pkgs.mkShell {
packages = [
playwright-pkgs.playwright-test
playwright-pkgs.python313Packages.docopt
playwright-pkgs.python313Packages.httpserver
];
};
};
flakeWithWasmShell = nixpkgs.lib.recursiveUpdate flake {
devShells = wasmShell;
hydraJobs = {devShells = wasmShell;};
Expand All @@ -238,13 +244,23 @@
// {
# This ensure hydra send a status for the required job (even if no change other than commit hash)
revision = nixpkgs.writeText "revision" (inputs.self.rev or "dirty");
proto-js-bundle = proto-js-bundle-drv;
};
}
// lib.optionalAttrs (system != "aarch64-darwin")
{
packages = {
proto-js-bundle = proto-js-bundle-drv;
};
};
legacyPackages = {
inherit cabalProject nixpkgs;
# also provide hydraJobs through legacyPackages to allow building without system prefix:
inherit hydraJobs;
};
packages = lib.optionalAttrs (system != "aarch64-darwin") {
proto-js-bundle = proto-js-bundle-drv;
};
devShells = let
# profiling shell
profilingShell = p: {
Expand Down
25 changes: 25 additions & 0 deletions nix/npm-deps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions nix/npm-deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"google-protobuf": "^3.21.4",
"grpc-web": "^1.5.0"
}
}
88 changes: 88 additions & 0 deletions nix/proto-to-js.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# proto-to-js.nix

{ pkgs ? import <nixpkgs> {} }:

let

# Node dependencies
node-deps = pkgs.buildNpmPackage {
version = "1.0.0";
name = "proto-js-dependencies";
src = ../nix/npm-deps;
npmDepsHash = "sha256-b8x9xZ0dCu1cvILF0HPVVLfkCGHOWCcPUKyC2x1gQ+c=";
dontNpmBuild = true;
dontNpmInstall = true;
installPhase = ''
mkdir -p $out
cp -r node_modules $out/
'';
};

cardano-rpc-src = ../cardano-rpc;

in pkgs.stdenv.mkDerivation {
pname = "cardano-rpc-proto-js-bundle";
version = "0.1.0";

src = cardano-rpc-src;

nativeBuildInputs = [
pkgs.protobuf
pkgs.protoc-gen-js
pkgs.protoc-gen-grpc-web
pkgs.nodePackages.browserify
];

buildPhase = ''
runHook preBuild

PROTO_INCLUDE_PATH=$src/proto
GEN_JS_PATH=./generated-js
BUNDLE_PATH=./bundled-js

mkdir -p $GEN_JS_PATH
mkdir -p $BUNDLE_PATH

PROTO_FILE=$PROTO_INCLUDE_PATH/cardano/rpc/node.proto

echo "--- Compiling .proto file: $PROTO_FILE ---"

protoc \
-I=$PROTO_INCLUDE_PATH \
--js_out=import_style=commonjs,binary:$GEN_JS_PATH \
--grpc-web_out=import_style=commonjs,mode=grpcwebtext:$GEN_JS_PATH \
$PROTO_FILE

echo "--- Compilation finished. Generated files are in $GEN_JS_PATH ---"
ls -R $GEN_JS_PATH

GENERATED_GRPC_FILE=$GEN_JS_PATH/cardano/rpc/node_grpc_web_pb.js

if [ ! -f "$GENERATED_GRPC_FILE" ]; then
echo "Error: Protoc did not generate the expected gRPC-Web file!"
exit 1
fi

echo "--- Setting up node_modules for browserify ---"
ln -s ${node-deps}/node_modules ./node_modules

echo "--- Bundling generated JS with browserify ---"

browserify --standalone grpc $GENERATED_GRPC_FILE > $BUNDLE_PATH/node_grpc_web_pb.js

echo "--- Bundling complete. Final file is in $BUNDLE_PATH ---"
ls $BUNDLE_PATH

runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out
cp ./bundled-js/node_grpc_web_pb.js $out/
runHook postInstall
'';

dontConfigure = true;
}

Loading