Skip to content

Commit

Permalink
ci: add nix env and gha workflows
Browse files Browse the repository at this point in the history
First pass at a dev env, which pulls in the usual Rust deps, as well as
go, which is required to build `penumbra-indexer`. The go-linking
functionality isn't well supported yet: within the devShell, `cargo
build` works, but `nix build` does not.

CI cache timing info:

  * First run of cargo-check: 3m13s
  * First run of cargo-fmt: 1m57s
  • Loading branch information
conorsch committed Sep 5, 2024
1 parent c22cdd3 commit 58147a6
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
54 changes: 54 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Rust CI
on:
pull_request:

jobs:
check:
name: cargo check
runs-on: buildjet-8vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4
with:
lfs: true

- name: install nix
uses: nixbuild/nix-quick-install-action@v28

- name: setup nix cache
uses: nix-community/cache-nix-action@v5
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
backend: buildjet

- name: Load rust cache
uses: astriaorg/buildjet-rust-cache@v2.5.1

- name: Run cargo check, failing on warnings
run: >-
nix develop --command
just check
fmt:
name: cargo fmt
runs-on: buildjet-8vcpu-ubuntu-2204
steps:
- uses: actions/checkout@v4

- name: install nix
uses: nixbuild/nix-quick-install-action@v28

- name: setup nix cache
uses: nix-community/cache-nix-action@v5
with:
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }}
restore-prefixes-first-match: nix-${{ runner.os }}-
backend: buildjet

- name: Load rust cache
uses: astriaorg/buildjet-rust-cache@v2.5.1

- name: Run cargo fmt, failing on reformatting
run: >-
nix develop --command
just fmt
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@

# Rust / Cargo
/target

# Ignore .envrc; copy from .envrc.example to get started
.envrc
.direnv/
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[package]
name = "penumbra-reindexer"
authors = ["Penumbra Labs <team@penumbralabs.xyz"]
description = "A reindexing tool for Penumbra ABCI event data"
homepage = "https://penumbra.zone"
repository = "https://github.com/penumbra-zone/reindexer"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
.arg("cometbft.go")
.current_dir(&go_dir)
.status()
.unwrap();
.expect("failed to run go build command; make sure go is installed and on PATH");
assert!(status.success());

// Link the Go static library
Expand Down
104 changes: 104 additions & 0 deletions flake.lock

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

96 changes: 96 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
description = "A nix development shell and build environment for penumbra-reindexer";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
crane = {
url = "github:ipetkov/crane";
inputs = { nixpkgs.follows = "nixpkgs"; };
};
};

outputs = { self, nixpkgs, flake-utils, crane, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
# Permit version declarations, but default to unset,
# meaning the local working copy will be used.
penumbraReindexerRelease = null;

# Set up for Rust builds.
craneLib = crane.mkLib pkgs;

# Important environment variables so that the build can find the necessary libraries
LIBCLANG_PATH="${pkgs.libclang.lib}/lib";
ROCKSDB_LIB_DIR="${pkgs.rocksdb.out}/lib";
in with pkgs; with pkgs.lib; let
# All the Penumbra binaries
penumbraReindexer = (craneLib.buildPackage {
pname = "penumbra-reindexer";
# what
src = cleanSourceWith {
src = if penumbraReindexerRelease == null then craneLib.path ./. else fetchFromGitHub {
owner = "penumbra-zone";
repo = "reindexer";
rev = "v${penumbraReindexerRelease.version}";
sha256 = "${penumbraReindexerRelease.sha256}";
};
filter = path: type:
# Retain non-rust files as build inputs:
# * sql: database schema files for indexing
# * go, mod, sum: golang files for linking in cometbft
(builtins.match ".*\.(sql|go|mod|sum)$" path != null) ||
# ... as well as all the normal cargo source files:
(craneLib.filterCargoSources path type);
};
nativeBuildInputs = [ pkg-config ];
buildInputs = if stdenv.hostPlatform.isDarwin then
with pkgs.darwin.apple_sdk.frameworks; [clang openssl rocksdb SystemConfiguration CoreServices go]
else
[clang openssl rocksdb go];

inherit system LIBCLANG_PATH ROCKSDB_LIB_DIR;
cargoExtraArgs = "-p penumbra-reindexer";
meta = {
description = "A reindexing tool for Penumbra ABCI event data";
homepage = "https://penumbra.zone";
license = [ licenses.mit licenses.asl20 ];
};
}).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times

in rec {
packages = { inherit penumbraReindexer ; };
apps = {
penumbra-reindexer.type = "app";
penumbra-reindexer.program = "${penumbraReindexer}/bin/penumbra-reindexer";
};
defaultPackage = symlinkJoin {
name = "penumbra-reindexer";
paths = [ penumbraReindexer ];
};
devShells.default = craneLib.devShell {
inherit LIBCLANG_PATH ROCKSDB_LIB_DIR;
inputsFrom = [ penumbraReindexer ];
packages = [
cargo-nextest
cargo-watch
go
just
nix-prefetch-scripts
sqlfluff
];
shellHook = ''
export LIBCLANG_PATH=${LIBCLANG_PATH}
export ROCKSDB_LIB_DIR=${ROCKSDB_LIB_DIR}
'';
};
}
);
}
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Run cargo check, failing on warnings
check:
# The `-D warnings` option causes an error on warnings.
RUSTFLAGS="-D warnings" \
cargo check --release --all-targets

# Run cargo fmt, failing on warnings
fmt:
cargo fmt --all -- --check

0 comments on commit 58147a6

Please sign in to comment.