Skip to content

Commit 6faf13b

Browse files
committed
fix: cleanup substrate source and fix build
1 parent 8925496 commit 6faf13b

File tree

3 files changed

+97
-80
lines changed

3 files changed

+97
-80
lines changed

flake.lock

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

flake.nix

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@
1313

1414
flake-utils.url = "github:numtide/flake-utils";
1515

16-
cardano-node = {
17-
url = "github:IntersectMBO/cardano-node/10.1.4";
18-
flake = false;
19-
};
20-
21-
flake-compat = {
22-
url = "github:input-output-hk/flake-compat/fixes";
23-
flake = false;
16+
n2c = {
17+
url = "github:nlewo/nix2container";
18+
inputs.nixpkgs.follows = "nixpkgs";
2419
};
2520
};
2621

27-
outputs = { self, nixpkgs, crane, fenix, flake-utils, ... }:
22+
outputs = { self, nixpkgs, crane, fenix, flake-utils, n2c, ... }:
2823
flake-utils.lib.eachDefaultSystem (system:
2924
let
3025
pkgs = import nixpkgs {
@@ -49,7 +44,9 @@
4944
pkgs.clang
5045
];
5146

52-
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 "";
47+
BINDGEN_EXTRA_CLANG_ARGS = if pkgs.lib.hasSuffix "linux" system
48+
then "-I${pkgs.glibc.dev}/include -I${pkgs.clang.cc.lib}/lib/clang/19/include"
49+
else "";
5350
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
5451

5552
CFLAGS = if pkgs.lib.hasSuffix "linux" system then
@@ -59,9 +56,7 @@
5956

6057
PROTOC = "${pkgs.protobuf}/bin/protoc";
6158
#C_INCLUDE_PATH = "${pkgs.clang.cc.lib}/lib/clang/19/include";
62-
63-
# RocksDB configuration - use system library
64-
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
59+
6560
OPENSSL_NO_VENDOR = 1;
6661
OPENSSL_DIR = "${pkgs.openssl.dev}";
6762
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
@@ -73,18 +68,24 @@
7368

7469
# Common build inputs for all targets
7570
commonArgs = {
76-
pname = "partner-chains-demo-node";
77-
src = pkgs.lib.cleanSourceWith {
78-
src = self;
79-
filter = path: type:
71+
pname = "partner-chains-demo-node";
72+
# Clean the project directory so that the nix hash
73+
# doesn't change when unrelated files to builds update
74+
src = let
75+
jsonFilter = path: _type: builtins.match ".*\\.json$" path != null;
76+
combinedFilter = path: type:
8077
(craneLib.filterCargoSources path type) ||
81-
(pkgs.lib.hasSuffix "examples" path) ||
82-
(pkgs.lib.hasSuffix ".json" path);
78+
(jsonFilter path type);
79+
in pkgs.lib.cleanSourceWith {
80+
src = self;
81+
filter = combinedFilter;
82+
name = "source";
8383
};
8484

8585
buildInputs = with pkgs; [
8686
openssl
8787
libclang.lib
88+
stdenv.cc.cc.lib
8889
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
8990
pkgs.rust-jemalloc-sys-unprefixed
9091
] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
@@ -96,28 +97,42 @@
9697
pkg-config
9798
protobuf
9899
llvmPackages.lld
100+
autoPatchelfHook
99101
];
100102

101103
doCheck = false;
102104
} // shellEnv;
103105

106+
cargoVendorDir = craneLib.vendorCargoDeps {
107+
inherit (commonArgs) src;
108+
# Remove fixture and example directories from Polkadot SDK, don't want them vendored/checked
109+
# https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2412-1/.github/workflows/checks-quick.yml#L91-L97
110+
overrideVendorGitCheckout = let
111+
isPolkadotSdk = p: pkgs.lib.hasPrefix "git+https://github.com/paritytech/polkadot-sdk.git" p.source;
112+
in ps: drv:
113+
if pkgs.lib.any (p: isPolkadotSdk p) ps then
114+
drv.overrideAttrs {
115+
postPatch = ''
116+
rm -rf substrate/frame/contracts/fixtures/build || true
117+
rm -rf substrate/frame/contracts/fixtures/contracts/common || true
118+
rm -rf substrate/primitives/state-machine/fuzz || true
119+
'';
120+
}
121+
else
122+
drv;
123+
};
104124
# Build the workspace dependencies separately
105125
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
106-
pname = "partner-chains-demo-node-deps";
126+
inherit cargoVendorDir;
107127
});
108128

109129
partner-chains-demo-node = craneLib.buildPackage (commonArgs // {
110130
pname = "partner-chains-demo-node";
111131
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
112-
113132
inherit cargoArtifacts;
114133

115134
# Git commit hash for partner-chains CLI --version flag
116-
SUBSTRATE_CLI_GIT_COMMIT_HASH = self.dirtyShortRev or self.shortRev;
117-
118-
postFixup = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
119-
patchelf --set-rpath "${pkgs.rocksdb}/lib:${pkgs.stdenv.cc.cc.lib}/lib" $out/bin/partner-chains-demo-node
120-
'';
135+
SUBSTRATE_CLI_GIT_COMMIT_HASH = "dev"; # self.dirtyShortRev or self.shortRev;
121136
});
122137

123138
cargoTest = craneLib.cargoTest (commonArgs // {
@@ -126,31 +141,20 @@
126141

127142
cargoClippy = craneLib.cargoClippy (commonArgs // {
128143
inherit cargoArtifacts;
129-
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
130144
});
131145

132146
cargoFmt = craneLib.cargoFmt {
133147
inherit (commonArgs) pname src;
134148
};
135149

136-
in
137-
{
138-
checks = {
139-
# Build the crate as part of `nix flake check`
140-
inherit partner-chains-demo-node cargoTest cargoClippy cargoFmt;
141-
};
142-
143-
packages = {
144-
default = partner-chains-demo-node;
145-
inherit partner-chains-demo-node;
146-
};
147-
devShells.default = craneLib.devShell ({
150+
devShell = craneLib.devShell ({
148151
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};
152+
# Inherit inputs from other build artifacts
153+
inputsFrom = [ partner-chains-demo-node ];
151154

152155
# Extra packages for the dev shell
153156
packages = with pkgs; [
157+
attic-client
154158
awscli2
155159
bashInteractive
156160
cargo-edit
@@ -178,6 +182,32 @@
178182
[pkgs.clang]);
179183
} // shellEnv);
180184

185+
in { # Main flake outputs section
186+
checks = {
187+
# Build the crate as part of `nix flake check'
188+
inherit partner-chains-demo-node cargoTest cargoFmt devShell;
189+
};
190+
191+
packages = {
192+
inherit partner-chains-demo-node;
193+
default = partner-chains-demo-node;
194+
oci-image = n2c.packages.${system}.nix2container.buildImage {
195+
name = "partner-chains-demo-node";
196+
config = {
197+
Entrypoint = [ "${partner-chains-demo-node}/bin/partner-chains-demo-node" ];
198+
Expose = [
199+
"30333/tcp"
200+
"9615/tcp"
201+
"9933/tcp"
202+
"9944/tcp"
203+
];
204+
Volumes = { "/data" = {}; };
205+
};
206+
};
207+
};
208+
209+
devShells.default = devShell;
210+
181211
formatter = pkgs.nixfmt-rfc-style;
182212
});
183213

@@ -187,12 +217,12 @@
187217
extra-substituters = [
188218
"https://nix-community.cachix.org"
189219
"https://cache.iog.io"
190-
"https://cache.sc.iog.io"
220+
"https://ci.sc.iog.io/partner-chains"
191221
];
192222
extra-trusted-public-keys = [
193223
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
194224
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
195-
"cache.sc.iog.io:b4YIcBabCEVKrLQgGW8Fylz4W8IvvfzRc+hy0idqrWU="
225+
"partner-chains:j9StpxUY/znqFqaevhQRxCH4Hi0F4rCGXDiUSjz+kew="
196226
];
197227
};
198-
}
228+
}

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ components = [
44
"cargo",
55
"clippy",
66
"rust-analyzer",
7+
"rust-src",
8+
"rust-std",
79
"rustc-dev",
810
"rustc",
911
"rustfmt",

0 commit comments

Comments
 (0)