Skip to content

Commit

Permalink
flake: add kairos-deposit-contract wasm32 build-output
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp committed Mar 6, 2024
1 parent df5c3f9 commit 189990c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 38 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,45 @@
];
perSystem = { config, self', inputs', system, pkgs, lib, ... }:
let
rustToolchain = inputs'.fenix.packages.stable.toolchain;
rustToolchain = with inputs'.fenix.packages; combine [
complete.toolchain
targets.wasm32-unknown-unknown.latest.rust-std
];
craneLib = inputs.crane.lib.${system}.overrideToolchain rustToolchain;

kairosOnChainAttrs = {
src = lib.cleanSourceWith {
src = craneLib.path ./kairos-deposit-contract;
filter = path: type: craneLib.filterCargoSources path type;
};
cargoExtraArgs = "--target wasm32-unknown-unknown";
nativeBuildInputs = [ pkgs.binaryen ];
doCheck = false;
# Append "-optimized" to wasm files, to make the tests pass
postInstall = ''
directory="$out/bin/"
for file in "$directory"*.wasm; do
if [ -e "$file" ]; then
# Extract the file name without extension
filename=$(basename "$file" .wasm)
# Append "-optimized" to the filename and add back the .wasm extension
new_filename="$directory$filename-optimized.wasm"
wasm-opt --strip-debug --signext-lowering "$file" -o "$new_filename"
#mv "$file" "$new_filename"
fi
done
'';
};

kairosNodeAttrs = {
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type: craneLib.filterCargoSources path type;
};
nativeBuildInputs = with pkgs; [ pkg-config ];

PATH_TO_WASM_BINARIES = "${self'.packages.kairos-deposit-contract}/bin";

buildInputs = with pkgs; [
openssl.dev
] ++ lib.optionals stdenv.isDarwin [
Expand All @@ -73,6 +102,14 @@
cargoArtifacts = self'.packages.kairos-deps;
});

kairos-deposit-contract-deps = craneLib.buildPackage (kairosOnChainAttrs // {
pname = "kairos-deposit-contract";
});

kairos-deposit-contract = craneLib.buildPackage (kairosOnChainAttrs // {
cargoArtifacts = self'.packages.kairos-deposit-contract-deps;
});

default = self'.packages.kairos;

kairos-docs = craneLib.cargoDoc (kairosNodeAttrs // {
Expand Down

0 comments on commit 189990c

Please sign in to comment.