diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4106ff..e17afd4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,16 +10,28 @@ env: CARGO_TERM_COLOR: always jobs: + cli: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Check rgb-wallet + run: nix run .#rgb -- -V | grep rgb-wallet default: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + # NOTE: Dont use nix here everything should be based on the ubuntu-latest - name: Install rust stable uses: actions-rs/toolchain@v1 with: toolchain: stable override: true - - name: Default build + - name: Latest Ubuntu build check uses: actions-rs/cargo@v1 with: command: check @@ -27,17 +39,11 @@ jobs: no-default: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install rust stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - name: No features - uses: actions-rs/cargo@v1 - with: - command: check - args: --workspace --no-default-features + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Latest Ubuntu build check no features + run: nix develop .#stable -c cargo check --workspace --no-default-features features: runs-on: ubuntu-latest strategy: @@ -48,22 +54,14 @@ jobs: - log - serde steps: - - uses: actions/checkout@v3 - - name: Install rust stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - name: Feature ${{ matrix.feature }} - uses: actions-rs/cargo@v1 - with: - command: check - args: --no-default-features --features=${{ matrix.feature }} - - name: Defaults + ${{ matrix.feature }} - uses: actions-rs/cargo@v1 - with: - command: check - args: --features=${{ matrix.feature }} + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Check feature ${{ matrix.feature }} only + run: nix develop .#stable -c cargo check --no-default-features --features=${{ matrix.feature }} + - name: Check feature ${{ matrix.feature }} with defaults + run: nix develop .#stable -c cargo check --features=${{ matrix.feature }} platforms: runs-on: ${{ matrix.os }} strategy: @@ -71,7 +69,8 @@ jobs: matrix: os: [ ubuntu-20.04, ubuntu-22.04, macos-11, macos-12, windows-2019, windows-2022 ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + # NOTE: Dont use nix in platform checks everything should based on the host system - name: Install rust stable uses: actions-rs/toolchain@v1 with: @@ -87,16 +86,11 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [ nightly, beta, stable, 1.70.0 ] + toolchain: [ nightly, beta, stable, msrv ] steps: - - uses: actions/checkout@v3 - - name: Install rust ${{ matrix.toolchain }} - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.toolchain }} - override: true - - name: All features - uses: actions-rs/cargo@v1 - with: - command: check - args: --workspace --all-targets --all-features + - name: checkout + uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Check rgb + run: nix develop ".#${{ matrix.toolchain }}" -c cargo check --workspace --all-targets --all-features diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 2077319..cbb6d3a 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -13,39 +13,23 @@ jobs: codecov: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, llvm-tools-preview + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release - env: - CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Cinstrument-coverage" - RUSTDOCFLAGS: "-Cinstrument-coverage" + run: nix develop .#codecov -c cargo build --release - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features --no-fail-fast - env: - CARGO_INCREMENTAL: "0" - RUSTFLAGS: "-Cinstrument-coverage" - RUSTDOCFLAGS: "-Cinstrument-coverage" + run: nix develop .#codecov -c cargo test --all-features --no-fail-fast --tests - name: Install grcov - run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi + run: nix develop .#codecov -c cargo install grcov - name: Generate coverage - run: grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov + run: nix develop .#codecov -c grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: files: ./coverage.lcov flags: rust - fail_ci_if_error: true + # TODO: set true when CODECOV_TOKEN is set + fail_ci_if_error: false + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e31e8bd..eabfd50 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,45 +13,27 @@ jobs: fmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install rustc nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rustfmt - - uses: actions-rs/cargo@v1 - name: Formatting - with: - command: fmt - args: --all -- --check + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Formatting + run: nix develop .#nightly -c cargo fmt --all -- --check clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install rustc stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - components: clippy - - uses: actions-rs/cargo@v1 - name: Clippy - with: - command: clippy - args: --workspace --all-features --all-targets -- -D warnings + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Clippy + run: nix develop .#stable -c cargo clippy --workspace --all-features --all-targets -- -D warnings doc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install rustc nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rust-docs - - uses: actions-rs/cargo@v1 - name: Doc - with: - command: doc - args: --workspace --all-features + - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 + - name: Doc + run: nix develop .#nightly -c cargo doc --workspace --all-features diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7748a76..f642bca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,14 +13,8 @@ jobs: testing: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install latest stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true + - uses: actions/checkout@v4 + - name: Install Nix + uses: cachix/install-nix-action@v26 - name: Build & test - uses: actions-rs/cargo@v1 - with: - command: test - args: --workspace --all-features --no-fail-fast + run: nix develop .#stable -c cargo test --workspace --all-features --no-fail-fast --tests diff --git a/.gitignore b/.gitignore index 653cfce..8507b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ *.swp /dep_test +result diff --git a/Cargo.toml b/Cargo.toml index afbfcc3..6c4dd43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ categories = ["cryptography::cryptocurrencies"] authors = ["Dr Maxim Orlovsky "] homepage = "https://lnp-bp.org" repository = "https://github.com/RGB-WG/rgb" -rust-version = "1.67" # Due to strict encoding library +rust-version = "1.75.0" edition = "2021" license = "Apache-2.0" diff --git a/MANIFEST.yml b/MANIFEST.yml index b86aec3..4d6c120 100644 --- a/MANIFEST.yml +++ b/MANIFEST.yml @@ -3,7 +3,7 @@ Type: Binary Kind: Free software License: Apache-2.0 Language: Rust -Compiler: 1.67 +Compiler: 1.75 Author: Maxim Orlovsky Maintained: LNP/BP Standards Association, Switzerland Maintainers: diff --git a/README.md b/README.md index 103240d..5ab5aec 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ and RGB as "assets for bitcoin and LN" by [Peter Todd][Todd] and ## Installing First, you need to install [cargo](https://doc.rust-lang.org/cargo/). -Minimum supported rust compiler version (MSRV): 1.66, rust 2021 edition. +Minimum supported rust compiler version (MSRV) is shown in `rust-version` of `Cargo.toml`. Next, you need to install developer components, which are OS-specific: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5131a9d --- /dev/null +++ b/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713979152, + "narHash": "sha256-apdecPuh8SOQnkEET/kW/UcfjCRb8JbV5BKjoH+DcP4=", + "owner": "ipetkov", + "repo": "crane", + "rev": "a5eca68a2cf11adb32787fc141cddd29ac8eb79c", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712439257, + "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712542394, + "narHash": "sha256-UZebDBECRSrJqw4K+LxZ6qFdYnScu6q1XCwqtsu1cas=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ece8bdb3c3b58def25f204b9a1261dee55d7c9c0", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0d8c593 --- /dev/null +++ b/flake.nix @@ -0,0 +1,98 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, crane, rust-overlay, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + commonPackages = with pkgs; [ + openssl + pkg-config + ]; + workspaceToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-bin.stable.latest.default; + + stableWithLlvm = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ "rustfmt" "llvm-tools-preview" ]; + targets = [ ]; + }; + in + with pkgs; + { + packages = rec { + default = rgb; + rgb = craneLib.buildPackage rec { + pname = "rgb"; + cargoToml = ./Cargo.toml; + nativeBuildInputs = commonPackages; + cargoExtraArgs = "-p rgb-wallet"; + outputHashes = {}; + src = self; + buildInputs = with pkgs; [ + openssl + ]; + cargoArtifacts = craneLib.buildDepsOnly { + inherit src cargoToml buildInputs nativeBuildInputs cargoExtraArgs outputHashes; + }; + strictDeps = true; + doCheck = false; + }; + }; + + devShells = rec { + default = msrv; + + msrv = mkShell { + buildInputs = commonPackages ++ [ + rust-bin.stable."${workspaceToml.workspace.package."rust-version"}".default + ]; + }; + + stable = mkShell { + buildInputs = commonPackages ++ [ + rust-bin.stable.latest.default + ]; + }; + + beta = mkShell { + buildInputs = commonPackages ++ [ + rust-bin.beta.latest.default + ]; + }; + + nightly = mkShell { + buildInputs = commonPackages ++ [ + rust-bin.nightly.latest.default + ]; + }; + + codecov = mkShell { + buildInputs = commonPackages ++ [ + stableWithLlvm + ]; + CARGO_INCREMENTAL = "0"; + RUSTFLAGS = "-Cinstrument-coverage"; + RUSTDOCFLAGS = "-Cinstrument-coverage"; + }; + }; + } + ); +}