Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade Rust and dependencies #1552

Merged
merged 8 commits into from
Sep 20, 2024
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
File renamed without changes.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ database/
.*.swp
/.vscode

# Don't ignore the config.toml file
!/.cargo/config.toml

# Local Cargo cache
/.cargo/

Expand Down
3 changes: 2 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ lint:
cd rust && time cargo {{nightly_if_required}} fmt --all --check
cd rust && time cargo clippy --all-targets --all-features -- -D warnings
@echo "--- Linting Nix configs"
[ "$(nixfmt < flake.nix)" == "$(cat flake.nix)" ]
alejandra --check flake.nix
@echo "--- Linting Cargo dependencies"
cd rust && cargo machete Cargo.toml

format:
cd rust && cargo {{nightly_if_required}} fmt --all
alejandra flake.nix

# Perform a fast verification of whether the source compiles.
check:
Expand Down
155 changes: 83 additions & 72 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,77 +1,85 @@
{
inputs = {
rust-overlay.url = "github:oxalica/rust-overlay";
nixpkgs.url =
"github:NixOS/nixpkgs?ref=931494da4b60fb26719e231d6de4b2c96167a1ce";
nixpkgs.url = "github:NixOS/nixpkgs?ref=931494da4b60fb26719e231d6de4b2c96167a1ce";
};

outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
outputs = {
self,
nixpkgs,
rust-overlay,
flake-utils,
...
}:
flake-utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
] (system:
let
overlays = [ (import rust-overlay) ];

pkgs = import nixpkgs { inherit system overlays; };

rust = pkgs.rust-bin.fromRustupToolchainFile ./rust/rust-toolchain.toml;

rustPlatform = pkgs.makeRustPlatform {
cargo = rust;
rustc = rust;
};

runtimeDependencies = with pkgs; [ openssl zstd ];

frameworks = pkgs.darwin.apple_sdk.frameworks;

buildDependencies = with pkgs;
[
cargo-nextest
clang
libclang.lib
mold-wrapped # https://github.com/rui314/mold#mold-a-modern-linker
pkg-config
rustPlatform.bindgenHook
] ++ runtimeDependencies ++ lib.optionals stdenv.isDarwin [
frameworks.Security
frameworks.CoreServices
zld
];

# used to ensure rustfmt is nightly version to support unstable features
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.minimal.override { extensions = [ "rustfmt" ]; });

developmentDependencies = with pkgs;
[
cargo-audit
cargo-machete
curl
check-jsonschema
git # Needed but not declared by Nix's 'stdenv' build.
google-cloud-sdk # Required only to use O1's bucket.
hurl
jq
just
nightlyToolchain.passthru.availableComponents.rustfmt
nix-output-monitor # Use 'nom' in place of 'nix' to use this.
nixfmt-classic
rclone
ruby
rubyPackages.standard
rubyPackages.rspec
rust
shellcheck
shfmt
] ++ buildDependencies;

cargo-toml = builtins.fromTOML (builtins.readFile ./rust/Cargo.toml);

in with pkgs; {
] (system: let
overlays = [(import rust-overlay)];

pkgs = import nixpkgs {inherit system overlays;};

rust = pkgs.rust-bin.fromRustupToolchainFile ./rust/rust-toolchain.toml;

rustPlatform = pkgs.makeRustPlatform {
cargo = rust;
rustc = rust;
};

runtimeDependencies = with pkgs; [openssl zstd];

frameworks = pkgs.darwin.apple_sdk.frameworks;

buildDependencies = with pkgs;
[
cargo-nextest
clang
libclang.lib
mold-wrapped # https://github.com/rui314/mold#mold-a-modern-linker
pkg-config
rustPlatform.bindgenHook
]
++ runtimeDependencies
++ lib.optionals stdenv.isDarwin [
frameworks.Security
frameworks.CoreServices
zld
];

# used to ensure rustfmt is nightly version to support unstable features
nightlyToolchain =
pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.minimal.override {extensions = ["rustfmt"];});

developmentDependencies = with pkgs;
[
alejandra
cargo-audit
cargo-machete
curl
check-jsonschema
git # Needed but not declared by Nix's 'stdenv' build.
google-cloud-sdk # Required only to use O1's bucket.
hurl
jq
just
nightlyToolchain.passthru.availableComponents.rustfmt
nix-output-monitor # Use 'nom' in place of 'nix' to use this.
rclone
ruby
rubyPackages.standard
rubyPackages.rspec
rust
shellcheck
shfmt
]
++ buildDependencies;

cargo-toml = builtins.fromTOML (builtins.readFile ./rust/Cargo.toml);
in
with pkgs; {
packages = flake-utils.lib.flattenTree rec {
mina-indexer = rustPlatform.buildRustPackage rec {
meta = with lib; {
Expand All @@ -82,7 +90,7 @@
license = licenses.asl20;
mainProgram = "mina-indexer";
platforms = platforms.all;
maintainers = [ ];
maintainers = [];
};

pname = cargo-toml.package.name;
Expand All @@ -92,11 +100,14 @@
src = lib.cleanSourceWith {
src = lib.cleanSource ./.;
filter = path: type:
(path != ".direnv") && (path != "rust/target")
&& (path != "ops") && (path != "Justfile") && (path != "tests");
(path != ".direnv")
&& (path != "rust/target")
&& (path != "ops")
&& (path != "Justfile")
&& (path != "tests");
};

cargoLock = { lockFile = ./rust/Cargo.lock; };
cargoLock = {lockFile = ./rust/Cargo.lock;};

nativeBuildInputs = buildDependencies;

Expand Down Expand Up @@ -129,16 +140,16 @@
created = "now";
tag = builtins.substring 0 8 (self.rev or "dev");
copyToRoot = pkgs.buildEnv {
paths = with pkgs; [ mina-indexer openssl zstd bash self ];
paths = with pkgs; [mina-indexer openssl zstd bash self];
name = "mina-indexer-root";
pathsToLink = [ "/bin" "/share" ];
pathsToLink = ["/bin" "/share"];
};
config.Cmd = [ "${pkgs.lib.getExe mina-indexer}" ];
config.Cmd = ["${pkgs.lib.getExe mina-indexer}"];
};
};

devShells.default = mkShell {
env = { LIBCLANG_PATH = "${libclang.lib}/lib"; };
env = {LIBCLANG_PATH = "${libclang.lib}/lib";};
buildInputs = developmentDependencies;
shellHook = "export TMPDIR=/var/tmp";
};
Expand Down
Loading