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
17 changes: 12 additions & 5 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ jobs:
- name: Check out the SDK repo
uses: actions/checkout@v4

- name: Setup Go, Rust and Golem Base
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Setup Go and Golem Base
uses: ./.github/workflows/setup

# TODO: This could probably just be a derivation
- name: Run Rust demo example
run: cargo run
run: nix develop --command cargo run
working-directory: ./demo

run-tests-and-docs:
Expand All @@ -30,17 +34,20 @@ jobs:
- name: Setup Go, Rust and Golem Base
uses: ./.github/workflows/setup

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Run tests
run: cargo test
run: nix flake check --keep-going -L

- name: Build docs
run: cargo doc --no-deps --workspace
run: nix build .#checks.x86_64-linux.cargo-doc

- name: Deploy docs to branch folder
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
publish_dir: ./result/share/doc
publish_branch: gh-pages
destination_dir: ${{ github.head_ref }}

Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# - Starts a `gb-op-geth` container for Ethereum-compatible RPC.
# - Checks out the `gb-op-geth` repo and sets up Go.
# - Creates and funds a test account.
# - Reads the `./rust-toolchain` version and install it.
#
# To use, reference this action in your workflow with `uses:`.

Expand Down Expand Up @@ -35,12 +34,3 @@ runs:
go run ./cmd/golembase account fund
working-directory: ./gb-op-geth
shell: bash

- name: Set `env.rust_stable`
run: echo "RUST_STABLE=$(cat ./rust-toolchain)" >> $GITHUB_ENV
shell: bash

- name: Install Rust
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE }}
57 changes: 24 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
# `pre-commit` configuration for Rust projects.
# `pre-commit` hook configuration for running checks from the nix flake.
#
# Defines formatting, linting, and TOML validation hooks.
# This hook will run `nix flake check` before every commit to
# ensure your project passes all flake-defined checks.
#
# To enable these checks before every commit, install `pre-commit` and run:
# You can view which checks will be run for your system with `nix flake show`.
#
# pre-commit install
# Usage:
# 1. Make sure you are inside the dev shell:
#
# This will set up the hooks as git `pre-commit` hooks.
# `nix develop`
#
# (Otherwise, `nix flake check` may fail due to missing dependencies.)
#
# 2. Install the pre-commit hook (only once per repo):
#
# `pre-commit install`
#
# 3. From now on, every `git commit` will automatically run `nix flake check`.
#
# To bypass these checks (not recommended), commit with:
#
# `git commit --no-verify`
#
# ------------------------------------------------------------

repos:
- repo: local
hooks:
- id: rustfmt
name: rustfmt
entry: rustfmt
args: ["--edition", "2024", "--check"]
language: system
types: [rust]
files: \.rs$

- id: cargo-clippy
name: cargo clippy
entry: cargo
args: ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]
- id: nix-flake-check
name: nix flake check
entry: nix flake check
language: system
types: [rust]
pass_filenames: false

# - id: cargo-audit
# name: cargo audit
# entry: cargo
# args: ["audit"]
# language: system
# files: ^(Cargo\.toml|Cargo\.lock)$
# pass_filenames: false

- id: taplo-validate
name: Taplo TOML validate
entry: taplo
args: ["check"]
language: system
files: \.toml$
3 changes: 3 additions & 0 deletions .rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.88.0"
components = ["rust-src", "rust-analyzer", "rustfmt", "clippy"]
File renamed without changes.
5 changes: 2 additions & 3 deletions demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
private_key_path.push("golembase/private.key");
let private_key_bytes = fs::read(&private_key_path).map_err(|e| {
format!(
"Failed to read private key at {}: {}",
"Failed to read private key at {}: {e}",
private_key_path.display(),
e
)
})?;
let private_key = Hash::from_slice(&private_key_bytes);

let signer = PrivateKeySigner::from_bytes(&private_key)
.map_err(|e| format!("Failed to parse private key: {}", e))?;
.map_err(|e| format!("Failed to parse private key: {e}"))?;
let url = Url::parse("http://localhost:8545").unwrap();
let client = GolemBaseClient::builder()
.wallet(signer)
Expand Down
45 changes: 23 additions & 22 deletions flake.lock

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

156 changes: 96 additions & 60 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,76 +1,112 @@
# Nix flake for reproducible Rust development and builds.
# - Uses `crane` for Rust builds and incremental caching.
# - Uses `rust-overlay` for toolchain from `rust-toolchain` file.
# - Provides a `devShell` with all dev dependencies and `pre-commit`.
# - Exposes the built crate as the default package.

{
# Flake inputs: build helpers, overlays, and package set
description = "A Rust SDK for interacting with GolemBase.";

inputs = {
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz";
rust-overlay = {
url = "github:oxalica/rust-overlay";

crane.url = "github:ipetkov/crane";

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};

flake-utils.url = "github:numtide/flake-utils";
};

# Flake outputs: build and dev environments for each system
outputs =
{
nixpkgs,
crane,
rust-overlay,
flake-utils,
...
{ self
, nixpkgs
, crane
, fenix
, flake-utils
, ...
}:
flake-utils.lib.eachDefaultSystem (
system:
let

# Import nixpkgs with Rust overlay
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };

# Rust toolchain and build dependencies
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
nativeBuildInputs = with pkgs; [
rustToolchain
pkg-config
];
buildInputs = with pkgs; [ openssl ];
flake-utils.lib.eachDefaultSystem (system:
let
inherit (pkgs) lib;
pkgs = nixpkgs.legacyPackages.${system};

rustToolchain = fenix.packages.${system}.fromToolchainFile {
file = ./.rust-toolchain.toml;
sha256 = "sha256-Qxt8XAuaUR2OMdKbN4u8dBJOhSHxS+uS06Wl9+flVEk=";
};

# Prepare source and build args using crane
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
inherit src nativeBuildInputs buildInputs;
strictDeps = true;
# The tests don't work in the nix sandbox
doCheck = false;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
src =
let
markdownFilter = path: _type: builtins.match ".*md$" path != null;
markdownOrCargo = path: type:
(markdownFilter path type) || (craneLib.filterCargoSources path type);
in
lib.cleanSourceWith {
src = ./.;
filter = markdownOrCargo;
name = "source";
};

# Build Rust dependencies and crate
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
rustSdk = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
commonArgs = {
inherit src;
strictDeps = true;

in
{
# Expose built crate and devShell
packages = {
default = rustSdk;
# TODO: Check dependencies for rustls, we can potentially
# remove the dependency on pkg-config and openssl
nativeBuildInputs = with pkgs; [ pkg-config ];

buildInputs = with pkgs; [ openssl ];
};

cargoArtifacts = craneLib.buildDepsOnly commonArgs;

golem-base-sdk = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
doCheck = false; # The tests don't work in the nix sandbox
});
in
{
# Additional cargo checks can be found at https://github.com/ipetkov/crane.
#
# These derivations are inherited by the `devShell`.
checks = {
inherit golem-base-sdk;

cargo-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});

cargo-fmt = craneLib.cargoFmt {
inherit src;
};

devShells.default =
with pkgs;
mkShell {
inherit nativeBuildInputs;
buildInputs = buildInputs ++ [ pre-commit ];
shellHook = ''
export PATH=${rustToolchain}/bin:$PATH
'';
};
}
);
taplo-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
};

cargo-doc = craneLib.cargoDoc (commonArgs // {
inherit cargoArtifacts;
cargoDocExtraArgs = "--no-deps --workspace";
# This can be commented out or tweaked as necessary, e.g. set to
# `--deny rustdoc::broken-intra-doc-links` to only enforce that lint
env.RUSTDOCFLAGS = "--deny warnings";
});
};

packages = {
inherit golem-base-sdk;
default = golem-base-sdk;
};

devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [
pre-commit
nil
nixpkgs-fmt
];
};

formatter = pkgs.nixpkgs-fmt;
});
}
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

2 changes: 1 addition & 1 deletion src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl TryFrom<TransactionReceipt> for TransactionResult {
receipt.logs().iter().cloned().try_for_each(|log| {
let log: alloy::primitives::Log = log.into();
let parsed = GolemBaseABI::GolemBaseABIEvents::decode_log(&log).map_err(|e| {
Self::Error::UnexpectedLogDataError(format!("Error decoding event log: {}", e))
Self::Error::UnexpectedLogDataError(format!("Error decoding event log: {e}"))
})?;
match parsed.data {
GolemBaseABI::GolemBaseABIEvents::GolemBaseStorageEntityCreated(data) => {
Expand Down
Loading
Loading