Skip to content

Commit b854ceb

Browse files
committed
fix: don't clean up some essential files
1 parent 68ba270 commit b854ceb

File tree

2 files changed

+165
-120
lines changed

2 files changed

+165
-120
lines changed

flake.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 149 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
description = "Your devShell environment using flake-utils";
2+
description = "Partner Chains - A Substrate-based blockchain with Cardano integration";
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
crane = {
8+
url = "github:ipetkov/crane";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
611

712
fenix = {
813
url = "github:nix-community/fenix";
@@ -22,139 +27,163 @@
2227
};
2328
};
2429

25-
outputs =
26-
{
27-
self,
28-
nixpkgs,
29-
fenix,
30-
flake-utils,
31-
...
32-
}:
33-
flake-utils.lib.eachDefaultSystem (
34-
system:
30+
outputs = { self, nixpkgs, crane, fenix, flake-utils, ... }:
31+
flake-utils.lib.eachDefaultSystem (system:
3532
let
3633
pkgs = import nixpkgs {
3734
inherit system;
3835
config.allowUnfree = true;
3936
};
37+
4038
rustToolchain = fenix.packages.${system}.fromToolchainFile {
4139
file = ./rust-toolchain.toml;
4240
sha256 = "Qxt8XAuaUR2OMdKbN4u8dBJOhSHxS+uS06Wl9+flVEk=";
4341
};
4442

45-
isLinux = pkgs.stdenv.isLinux;
46-
isDarwin = pkgs.stdenv.isDarwin;
47-
customRustPlatform = pkgs.makeRustPlatform {
48-
cargo = rustToolchain;
49-
rustc = rustToolchain;
50-
};
51-
in
52-
{
53-
packages.partner-chains = customRustPlatform.buildRustPackage rec {
54-
pname = "partner-chains";
55-
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
56-
src = ./.;
57-
preBuild = ''
58-
export SUBSTRATE_CLI_GIT_COMMIT_HASH=${self.dirtyShortRev or self.shortRev}
59-
'';
60-
61-
useFetchCargoVendor = false;
62-
cargoLock = {
63-
lockFile = ./Cargo.lock;
64-
outputHashes = {
65-
"binary-merkle-tree-16.0.0" = "sha256-Yt0KWRMOG53hxdMZvYA60hQ4Vsfkk1R5lv+dd+mzcNI=";
66-
"raw-scripts-7.2.1" = "sha256-HTi/mubyBz7dAeLXekexikZZaOHkoI32oUQgmnFe2YM=";
43+
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
44+
45+
# Common build inputs for all targets
46+
commonArgs = {
47+
src = pkgs.lib.cleanSourceWith {
48+
src = self;
49+
filter = path: type:
50+
# Include all files that crane normally includes
51+
(craneLib.filterCargoSources path type) ||
52+
# Also include examples directories and JSON files
53+
(pkgs.lib.hasSuffix "examples" path) ||
54+
(pkgs.lib.hasSuffix ".json" path);
6755
};
68-
};
69-
buildType = "production";
70-
doCheck = false;
71-
patches = [];
72-
73-
nativeBuildInputs = [
74-
pkgs.pkg-config
75-
pkgs.protobuf
76-
77-
pkgs.llvmPackages.lld
78-
customRustPlatform.bindgenHook
79-
];
80-
buildInputs = [
81-
pkgs.rocksdb
82-
pkgs.openssl
83-
pkgs.libclang.lib
84-
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
85-
pkgs.rust-jemalloc-sys-unprefixed
86-
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
87-
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
88-
pkgs.darwin.apple_sdk.frameworks.Security
89-
];
90-
91-
postFixup = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
92-
patchelf --set-rpath "${pkgs.rocksdb}/lib:${pkgs.stdenv.cc.cc.lib}/lib" $out/bin/partner-chains-demo-node
93-
'';
94-
95-
# Force skip support check in CC crate
96-
#CRATE_CC_NO_DEFAULTS = "1";
97-
98-
# Platform-specific features
99-
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin
100-
"--cfg unwinding_backport --cfg unwinding_apple";
101-
102-
# Existing environment variables
103-
CC_ENABLE_DEBUG_OUTPUT = "1";
104-
#CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "${pkgs.llvmPackages.lld}/bin/lld";
105-
#RUST_SRC_PATH = "${customRustPlatform.rustLibSrc}";
106-
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
107-
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
108-
rustToolchain
109-
pkgs.stdenv.cc.cc
110-
pkgs.libz
111-
pkgs.clang
112-
];
113-
114-
# Platform-specific flags
115-
CFLAGS =
116-
if pkgs.lib.hasSuffix "linux" system then
56+
57+
# Build inputs
58+
buildInputs = with pkgs; [
59+
openssl
60+
libclang.lib
61+
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
62+
pkgs.rust-jemalloc-sys-unprefixed
63+
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
64+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
65+
pkgs.darwin.apple_sdk.frameworks.Security
66+
];
67+
68+
# Native build inputs
69+
nativeBuildInputs = with pkgs; [
70+
pkg-config
71+
protobuf
72+
llvmPackages.lld
73+
];
74+
75+
# Environment variables
76+
CC_ENABLE_DEBUG_OUTPUT = "1";
77+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
78+
rustToolchain
79+
pkgs.stdenv.cc.cc
80+
pkgs.libz
81+
pkgs.clang
82+
];
83+
84+
# Bindgen configuration
85+
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/19/include";
86+
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
87+
88+
# Platform-specific flags
89+
CFLAGS = if pkgs.lib.hasSuffix "linux" system then
11790
"-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE"
11891
else
11992
"";
12093

121-
PROTOC = "${pkgs.protobuf}/bin/protoc";
122-
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
123-
OPENSSL_NO_VENDOR = 1;
124-
OPENSSL_DIR = "${pkgs.openssl.dev}";
125-
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
126-
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
127-
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.stdenv.cc.cc}/include -std=c++17";
94+
PROTOC = "${pkgs.protobuf}/bin/protoc";
95+
doCheck = false;
96+
#C_INCLUDE_PATH = "${pkgs.clang.cc.lib}/lib/clang/19/include";
97+
98+
# RocksDB configuration - use system library
99+
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
100+
OPENSSL_NO_VENDOR = 1;
101+
OPENSSL_DIR = "${pkgs.openssl.dev}";
102+
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
103+
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
104+
105+
# Platform-specific RUSTFLAGS
106+
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin
107+
"--cfg unwinding_backport --cfg unwinding_apple";
108+
109+
# Git commit hash for Substrate CLI
110+
SUBSTRATE_CLI_GIT_COMMIT_HASH = self.dirtyShortRev or self.shortRev;
111+
};
112+
113+
# Build the workspace dependencies
114+
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
115+
pname = "partner-chains-deps";
116+
});
117+
118+
# Build the main binary
119+
partner-chains = craneLib.buildPackage (commonArgs // {
120+
pname = "partner-chains";
121+
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
122+
123+
inherit cargoArtifacts;
124+
125+
# Post-fixup for Linux
126+
postFixup = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
127+
patchelf --set-rpath "${pkgs.rocksdb}/lib:${pkgs.stdenv.cc.cc.lib}/lib" $out/bin/partner-chains-demo-node
128+
'';
129+
});
130+
131+
# Run tests
132+
cargoTest = craneLib.cargoTest (commonArgs // {
133+
inherit cargoArtifacts;
134+
});
135+
136+
# Run clippy
137+
cargoClippy = craneLib.cargoClippy (commonArgs // {
138+
inherit cargoArtifacts;
139+
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
140+
});
141+
142+
# Run fmt check
143+
cargoFmt = craneLib.cargoFmt {
144+
inherit (commonArgs) src;
145+
};
146+
147+
in
148+
{
149+
checks = {
150+
# Build the crate as part of `nix flake check`
151+
inherit partner-chains cargoTest cargoClippy cargoFmt;
152+
};
153+
154+
packages = {
155+
default = partner-chains;
156+
inherit partner-chains;
157+
};
128158

129-
};
130159
devShells.default = pkgs.mkShell {
131-
packages =
132-
with pkgs;
133-
[
134-
awscli2
135-
bashInteractive
136-
cargo-edit
137-
cargo-license
138-
coreutils
139-
docker-compose
140-
earthly
141-
gawk
142-
gnumake
143-
kubectl
144-
libiconv
145-
nixfmt-rfc-style
146-
openssl
147-
patchelf
148-
pkg-config
149-
protobuf
150-
python312
151-
python312Packages.pip
152-
python312Packages.virtualenv
153-
rustToolchain
154-
sops
155-
xxd
156-
]
157-
++ (if isDarwin then [ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ] else [ pkgs.clang ]);
160+
packages = with pkgs; [
161+
awscli2
162+
bashInteractive
163+
cargo-edit
164+
cargo-license
165+
coreutils
166+
docker-compose
167+
earthly
168+
gawk
169+
gnumake
170+
kubectl
171+
libiconv
172+
nixfmt-rfc-style
173+
openssl
174+
patchelf
175+
pkg-config
176+
protobuf
177+
python312
178+
python312Packages.pip
179+
python312Packages.virtualenv
180+
rustToolchain
181+
sops
182+
xxd
183+
] ++ (if pkgs.stdenv.hostPlatform.isDarwin then
184+
[ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ]
185+
else
186+
[ pkgs.clang ]);
158187

159188
shellHook = ''
160189
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"
@@ -174,12 +203,12 @@
174203
175204
export PYTHONNOUSERSITE=1
176205
export CRATE_CC_NO_DEFAULTS=1
177-
${if isLinux then "export CFLAGS=-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else ""}
206+
${if pkgs.stdenv.hostPlatform.isLinux then "export CFLAGS=-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else ""}
178207
'';
179208
};
209+
180210
formatter = pkgs.nixfmt-rfc-style;
181-
}
182-
);
211+
});
183212

184213
nixConfig = {
185214
allow-import-from-derivation = true;

0 commit comments

Comments
 (0)