|
| 1 | +{ rust_overlay ? import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz") |
| 2 | +, pkgs ? import <nixpkgs> { |
| 3 | + overlays = [ |
| 4 | + rust_overlay |
| 5 | + |
| 6 | + (self: super: { |
| 7 | + rustc = pkgs.rust-bin.stable.latest.minimal.override { |
| 8 | + targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ]; |
| 9 | + }; |
| 10 | + inherit (super.rust-bin.stable.latest) rustfmt; |
| 11 | + }) |
| 12 | + ]; |
| 13 | + } |
| 14 | +}: |
| 15 | +let |
| 16 | + crateOverrides = pkgs: with pkgs; { |
| 17 | + prost-build = attrs: { buildInputs = [ protobuf ]; }; |
| 18 | + libp2p-core = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 19 | + libp2p-plaintext = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 20 | + libp2p-floodsub = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 21 | + libp2p-gossipsub = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 22 | + libp2p-identify = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 23 | + libp2p-kad = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 24 | + libp2p-relay = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 25 | + libp2p-noise = attrs: { buildInputs = [ protobuf ]; PROTOC = "${protobuf}/bin/protoc"; }; |
| 26 | + |
| 27 | + librocksdb-sys = attrs: { |
| 28 | + buildInputs = [ clang rustfmt snappy lz4 zstd zlib bzip2 ]; |
| 29 | + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; |
| 30 | + # rust-rocksdb uses {}_LIB_DIR to determine whether it embeds compression libs in itself. |
| 31 | + # We need to tell it to use libs from the nix store so that we don't get linker errors later on. |
| 32 | + SNAPPY_LIB_DIR = "${snappy}/lib"; |
| 33 | + LZ4_LIB_DIR = "${lz4}/lib"; |
| 34 | + ZSTD_LIB_DIR = "${zstd}/lib"; |
| 35 | + Z_LIB_DIR = "${zlib}/lib"; |
| 36 | + BZ2_LIB_DIR = "${bzip2}/lib"; |
| 37 | + # rust-rocksdb relies on CARGO_CFG_TARGET_FEATURE env variable |
| 38 | + # which is set by cargo. We are using rustc directly here, so |
| 39 | + # we need to set that variable. |
| 40 | + # |
| 41 | + # See: https://github.com/rust-rocksdb/rust-rocksdb/commit/81a9edea83473012378e808606cdd92c1212c076#diff-7377ccc9f5cb3386318bd8afcd84814e7dd6d9b40efa909fb2dc218ecb779499 |
| 42 | + # |
| 43 | + # XXX empty string is the most portable, but it can't take |
| 44 | + # advantage of fast vectorization instructions on newer CPUs. |
| 45 | + CARGO_CFG_TARGET_FEATURE = ""; |
| 46 | + }; |
| 47 | + |
| 48 | + anoma = attrs: { |
| 49 | + buildInputs = [ rustfmt ]; |
| 50 | + patchPhase = '' |
| 51 | + substituteInPlace build.rs --replace ./proto ${./proto} |
| 52 | + ''; |
| 53 | + }; |
| 54 | + |
| 55 | + anoma_apps = attrs: { |
| 56 | + buildInputs = [ rustfmt lz4 zstd zlib bzip2 ]; |
| 57 | + patchPhase = '' |
| 58 | + substituteInPlace build.rs --replace ./proto ${./proto} |
| 59 | + ''; |
| 60 | + }; |
| 61 | + }; |
| 62 | + |
| 63 | + # Generate Cargo.nix with: crate2nix generate |
| 64 | + cargo_nix = import ./Cargo.nix { |
| 65 | + inherit pkgs; |
| 66 | + buildRustCrateForPkgs = pkgs: pkgs.buildRustCrate.override { |
| 67 | + defaultCrateOverrides = pkgs.defaultCrateOverrides // crateOverrides pkgs; |
| 68 | + }; |
| 69 | + }; |
| 70 | + |
| 71 | +in { |
| 72 | + apps = cargo_nix.workspaceMembers.anoma_apps; |
| 73 | +} |
0 commit comments