44 inputs = {
55 nixpkgs . url = "github:NixOS/nixpkgs/nixos-unstable" ;
66
7- crane = {
8- url = "github:ipetkov/crane" ;
9- inputs . nixpkgs . follows = "nixpkgs" ;
10- } ;
7+ crane . url = "github:ipetkov/crane" ;
118
129 fenix = {
1310 url = "github:nix-community/fenix" ;
4239
4340 craneLib = ( crane . mkLib pkgs ) . overrideToolchain rustToolchain ;
4441
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 ) ;
55- } ;
56-
57- buildInputs = with pkgs ; [
58- openssl
59- libclang . lib
60- ] ++ pkgs . lib . optionals pkgs . stdenv . hostPlatform . isLinux [
61- pkgs . rust-jemalloc-sys-unprefixed
62- ] ++ pkgs . lib . optionals pkgs . stdenv . hostPlatform . isDarwin [
63- pkgs . darwin . apple_sdk . frameworks . SystemConfiguration
64- pkgs . darwin . apple_sdk . frameworks . Security
65- ] ;
66-
67- nativeBuildInputs = with pkgs ; [
68- pkg-config
69- protobuf
70- llvmPackages . lld
71- ] ;
72-
73- # Environment variables
42+ shellEnv = {
7443 CC_ENABLE_DEBUG_OUTPUT = "1" ;
7544 CRATE_CC_NO_DEFAULTS = 1 ;
7645 LD_LIBRARY_PATH = pkgs . lib . makeLibraryPath [
8352 BINDGEN_EXTRA_CLANG_ARGS = if pkgs . lib . hasSuffix "linux" system then "-I${ pkgs . glibc . dev } /include -I${ pkgs . clang . cc . lib } /lib/clang/19/include" else "" ;
8453 LIBCLANG_PATH = "${ pkgs . clang . cc . lib } /lib" ;
8554
86- # Platform-specific flags
8755 CFLAGS = if pkgs . lib . hasSuffix "linux" system then
8856 "-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE"
8957 else
9058 "" ;
9159
9260 PROTOC = "${ pkgs . protobuf } /bin/protoc" ;
93- doCheck = false ;
9461 #C_INCLUDE_PATH = "${pkgs.clang.cc.lib}/lib/clang/19/include";
9562
9663 # RocksDB configuration - use system library
10269
10370 RUSTFLAGS = pkgs . lib . optionalString pkgs . stdenv . hostPlatform . isDarwin
10471 "--cfg unwinding_backport --cfg unwinding_apple" ;
105-
10672 } ;
10773
108- # Build the workspace dependencies
74+ # Common build inputs for all targets
75+ commonArgs = {
76+ pname = "partner-chains-demo-node" ;
77+ src = pkgs . lib . cleanSourceWith {
78+ src = self ;
79+ filter = path : type :
80+ ( craneLib . filterCargoSources path type ) ||
81+ ( pkgs . lib . hasSuffix "examples" path ) ||
82+ ( pkgs . lib . hasSuffix ".json" path ) ;
83+ } ;
84+
85+ buildInputs = with pkgs ; [
86+ openssl
87+ libclang . lib
88+ ] ++ pkgs . lib . optionals pkgs . stdenv . hostPlatform . isLinux [
89+ pkgs . rust-jemalloc-sys-unprefixed
90+ ] ++ pkgs . lib . optionals pkgs . stdenv . hostPlatform . isDarwin [
91+ pkgs . darwin . apple_sdk . frameworks . SystemConfiguration
92+ pkgs . darwin . apple_sdk . frameworks . Security
93+ ] ;
94+
95+ nativeBuildInputs = with pkgs ; [
96+ pkg-config
97+ protobuf
98+ llvmPackages . lld
99+ ] ;
100+
101+ doCheck = false ;
102+ } // shellEnv ;
103+
104+ # Build the workspace dependencies separately
109105 cargoArtifacts = craneLib . buildDepsOnly ( commonArgs // {
110- pname = "partner-chains-deps" ;
106+ pname = "partner-chains-demo-node- deps" ;
111107 } ) ;
112108
113- # Build the main binary
114- partner-chains = craneLib . buildPackage ( commonArgs // {
115- pname = "partner-chains" ;
109+ partner-chains-demo-node = craneLib . buildPackage ( commonArgs // {
110+ pname = "partner-chains-demo-node" ;
116111 version = ( builtins . fromTOML ( builtins . readFile ./Cargo.toml ) ) . workspace . package . version ;
117112
118113 inherit cargoArtifacts ;
119114
120- # Git commit hash for Substrate CLI
115+ # Git commit hash for partner-chains CLI --version flag
121116 SUBSTRATE_CLI_GIT_COMMIT_HASH = self . dirtyShortRev or self . shortRev ;
122117
123118 postFixup = pkgs . lib . optionalString pkgs . stdenv . hostPlatform . isLinux ''
124119 patchelf --set-rpath "${ pkgs . rocksdb } /lib:${ pkgs . stdenv . cc . cc . lib } /lib" $out/bin/partner-chains-demo-node
125120 '' ;
126121 } ) ;
127122
128- # Run tests
129123 cargoTest = craneLib . cargoTest ( commonArgs // {
130124 inherit cargoArtifacts ;
131125 } ) ;
132126
133- # Run clippy
134127 cargoClippy = craneLib . cargoClippy ( commonArgs // {
135128 inherit cargoArtifacts ;
136129 cargoClippyExtraArgs = "--all-targets -- --deny warnings" ;
137130 } ) ;
138131
139- # Run fmt check
140132 cargoFmt = craneLib . cargoFmt {
141- inherit ( commonArgs ) src ;
133+ inherit ( commonArgs ) pname src ;
142134 } ;
143135
144136 in
145137 {
146- checks = {
138+ checks = {
147139 # Build the crate as part of `nix flake check`
148- inherit partner-chains cargoTest cargoClippy cargoFmt ;
140+ inherit partner-chains-demo-node cargoTest cargoClippy cargoFmt ;
149141 } ;
150142
151143 packages = {
152- default = partner-chains ;
153- inherit partner-chains ;
144+ default = partner-chains-demo-node ;
145+ inherit partner-chains-demo-node ;
154146 } ;
147+ devShells . default = craneLib . devShell ( {
148+ name = "partner-chains-demo-node-shell" ;
149+ # Inherit inputs from checks, which pulls in the build environment from packages.default (and others)
150+ checks = self . checks . ${ system } ;
155151
156- devShells . default = pkgs . mkShell {
152+ # Extra packages for the dev shell
157153 packages = with pkgs ; [
158154 awscli2
159155 bashInteractive
160156 cargo-edit
161157 cargo-license
162158 coreutils
163159 docker-compose
164- earthly
165160 gawk
166161 gnumake
167162 kubectl
177172 rustToolchain
178173 sops
179174 xxd
180- ] ++ ( if pkgs . stdenv . hostPlatform . isDarwin then
181- [ pkgs . darwin . apple_sdk . frameworks . SystemConfiguration ]
182- else
183- [ pkgs . clang ] ) ;
184-
185- shellHook = ''
186- export RUST_SRC_PATH="${ rustToolchain } /lib/rustlib/src/rust/library"
187- export LIBCLANG_PATH="${ pkgs . libclang . lib } /lib"
188- export LD_LIBRARY_PATH="${
189- pkgs . lib . makeLibraryPath [
190- rustToolchain
191- pkgs . libz
192- pkgs . stdenv . cc . cc
193- ]
194- } "
195-
196- export OPENSSL_NO_VENDOR=1
197- export OPENSSL_DIR="${ pkgs . openssl . dev } "
198- export OPENSSL_INCLUDE_DIR="${ pkgs . openssl . dev } /include"
199- export OPENSSL_LIB_DIR="${ pkgs . openssl . out } /lib"
200-
201- export PYTHONNOUSERSITE=1
202- export CRATE_CC_NO_DEFAULTS=1
203- ${ if pkgs . stdenv . hostPlatform . isLinux then "export CFLAGS=-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else "" }
204- '' ;
205- } ;
175+ ] ++ ( if pkgs . stdenv . hostPlatform . isDarwin then
176+ [ pkgs . darwin . apple_sdk . frameworks . SystemConfiguration ]
177+ else
178+ [ pkgs . clang ] ) ;
179+ } // shellEnv ) ;
206180
207181 formatter = pkgs . nixfmt-rfc-style ;
208182 } ) ;
221195 "cache.sc.iog.io:b4YIcBabCEVKrLQgGW8Fylz4W8IvvfzRc+hy0idqrWU="
222196 ] ;
223197 } ;
224- }
198+ }
0 commit comments