Skip to content

Commit

Permalink
chore(nix): add octez distribution to nix shell and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyob committed Sep 25, 2024
1 parent a211452 commit ef74ba5
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 6 deletions.
11 changes: 11 additions & 0 deletions crates/jstzd/tests/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use jstzd::main;
use tokio::process::Command;

#[tokio::test]
async fn test_main() {
main().await.unwrap();
}

#[tokio::test]
async fn test_octez_client() {
let output = Command::new("octez-client")
.arg("--version")
.output()
.await
.unwrap();
println!("octez-client --version: {:?}", output);
}
89 changes: 89 additions & 0 deletions flake.lock

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

66 changes: 65 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
url = "github:serokell/nix-npm-buildpackage";
inputs.nixpkgs.follows = "nixpkgs";
};

# Octez

# We explicitly have opam-nix-integration as an input to avoid having two versions of nixpkgs
opam-nix-integration = {
url = "github:vapourismo/opam-nix-integration";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};

octez-v21 = {
url = "gitlab:tezos/tezos/octez-v21.0-rc2";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.rust-overlay.follows = "rust-overlay";
inputs.opam-nix-integration.follows = "opam-nix-integration";
};
};

outputs = inputs:
Expand All @@ -43,6 +60,52 @@
overlays = [(import ./nix/overlay.nix) (import rust-overlay) npm-buildpackage.overlays.default];
};

# Build octez release for this system
#
# TODO(https://linear.app/tezos/issue/JSTZ-152):
# This patch here should be upstreamed to tezos/tezos
octez = octez-v21.packages.${system}.default.overrideAttrs (old: let
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile "${old.src}/rust-toolchain";
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;
};
in {
patches =
(old.patches or [])
++ [
./nix/patches/0001-fix-octez-rust-deps-for-nix.patch
];

# Network access for fetching cargo dependencies is disabled in sandboxed
# builds. Instead we need to explicitly fetch the dependencies. Nixpkgs
# provides two ways to do this:
#
# - `fetchCargoTarball` fetches the dependencies using `cargo vendor`
# It requires an explicit `hash`.
#
# - `importCargoLock` parses the `Cargo.lock` file and fetches each
# dependency using `fetchurl`. It doesn't require an explicit `hash`.
#
# The latter is slower but doesn't require an explicit `hash` and is therefore
# more maintainable (since this derivation isn't built in CI).
cargoDeps = rustPlatform.importCargoLock {
lockFile = "${old.src}/src/rust_deps/Cargo.lock";
};
cargoRoot = "src/rust_deps";

nativeBuildInputs =
(old.nativeBuildInputs or [])
++ [
# See https://nixos.org/manual/nixpkgs/stable/#compiling-non-rust-packages-that-include-rust-code
# for more information.
#
# `cargoSetupHook` configures cargo to vendor dependencies using `cargoDeps`.
rustToolchain
rustPlatform.cargoSetupHook
];
});

clangNoArch =
if pkgs.stdenv.isDarwin
then
Expand All @@ -61,7 +124,7 @@
else pkgs.clang;

rust-toolchain = pkgs.callPackage ./nix/rust-toolchain.nix {};
crates = pkgs.callPackage ./nix/crates.nix {inherit crane rust-toolchain;};
crates = pkgs.callPackage ./nix/crates.nix {inherit crane rust-toolchain octez;};
js-packages = pkgs.callPackage ./nix/js-packages.nix {};

fmt = treefmt.lib.evalModule pkgs {
Expand Down Expand Up @@ -136,6 +199,7 @@

# Code coverage
cargo-llvm-cov
octez
]
++ lib.optionals stdenv.isLinux [pkg-config openssl.dev]
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [Security SystemConfiguration]);
Expand Down
10 changes: 5 additions & 5 deletions nix/crates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
lib,
stdenv,
rust-toolchain,
octez,
}: let
craneLib = (crane.mkLib pkgs).overrideToolchain (_: rust-toolchain);

Expand Down Expand Up @@ -114,33 +115,32 @@ in {

cargo-test-unit = craneLib.cargoNextest (commonWorkspace
// {
cargoArtifacts = cargoDeps;
# Run the unit tests
cargoNextestExtraArg = "--bins --lib";
});

cargo-test-int = craneLib.cargoNextest (commonWorkspace
// {
cargoArtifacts = cargoDeps;
buildInputs = commonWorkspace.buildInputs ++ [octez];
doCheck = true;
# Run the integration tests
#
# FIXME():
# Don't run the `jstz_api` integration tests until they've been paralellized
#
# Note: --workspace is required for --exclude. Once --exclude is removed, remove --workspace
cargoNextestExtraArg = "--workspace --test \"*\" --exclude \"jstz_api\"";
cargoNextestExtraArgs = "--workspace --test \"*\" --exclude \"jstz_api\"";
});

cargo-llvm-cov = craneLib.cargoLlvmCov (commonWorkspace
// {
cargoArtifacts = cargoDeps;
buildInputs = commonWorkspace.buildInputs ++ [octez];
# Generate coverage reports for codecov
cargoLlvmCovExtraArgs = "--workspace --exclude-from-test \"jstz_api\" --codecov --output-path $out";
});

cargo-clippy = craneLib.cargoClippy (commonWorkspace
// {
cargoArtifacts = cargoDeps;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
};
Expand Down
23 changes: 23 additions & 0 deletions nix/patches/0001-fix-octez-rust-deps-for-nix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml
index f4336a077a..6ab49b65cf 100644
--- a/manifest/product_octez.ml
+++ b/manifest/product_octez.ml
@@ -522,7 +522,7 @@ let octez_rust_deps =
[S "source_tree"; S "../riscv"];
[S "source_tree"; S "../kernel_sdk"];
];
- [S "action"; [S "no-infer"; [S "bash"; S "./build.sh"]]];
+ [S "action"; [S "no-infer"; [S "system"; S "bash ./build.sh"]]];
];
]

diff --git a/src/rust_deps/dune b/src/rust_deps/dune
index de48dbfde8..20934e2e21 100644
--- a/src/rust_deps/dune
+++ b/src/rust_deps/dune
@@ -22,4 +22,4 @@
(source_tree src)
(source_tree ../riscv)
(source_tree ../kernel_sdk))
- (action (no-infer (bash ./build.sh))))
+ (action (no-infer (system "bash ./build.sh"))))

0 comments on commit ef74ba5

Please sign in to comment.