Skip to content

Commit 5e3e3a9

Browse files
authored
Merge pull request #118 from mlabs-haskell/szg251/lbr-plutus-rust
Rust Prelude runtime library
2 parents 37df08d + 5091fcb commit 5e3e3a9

24 files changed

+1217
-40
lines changed

extras/build.nix

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
overlayAttrs = {
1010
extras = {
1111
purescriptFlake = import ./flake-purescript.nix pkgs;
12+
rustFlake = import ./flake-rust.nix pkgs;
1213
haskellData = import ./haskell-data.nix pkgs;
1314
};
1415
};

extras/flake-rust.nix

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
pkgs:
2+
3+
{ crane, src, system, crateName, extraSources ? [ ], extraSourcesDir ? ".extras", data ? [ ], dataDir ? "data" }:
4+
let
5+
rustWithTools = pkgs.rust-bin.stable.latest.default.override {
6+
extensions = [ "rustfmt" "rust-analyzer" "clippy" ];
7+
};
8+
craneLib = crane.lib.${system}.overrideToolchain rustWithTools;
9+
10+
# Library source code with extra dependencies attached
11+
fullSrc = pkgs.stdenv.mkDerivation {
12+
src = craneLib.cleanCargoSource (craneLib.path src);
13+
name = "lbf-rust-build-env";
14+
unpackPhase = ''
15+
mkdir $out
16+
cp -r $src/* $out
17+
cd $out
18+
${copyExtraSources}
19+
${copyData}
20+
'';
21+
};
22+
commonArgs = {
23+
src = fullSrc;
24+
pname = crateName;
25+
strictDeps = true;
26+
};
27+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
28+
29+
# Extra sources
30+
extra-sources = pkgs.linkFarm "extra-sources" extraSources;
31+
hasExtraSources = builtins.length extraSources > 0;
32+
linkExtraSources = pkgs.lib.optionalString hasExtraSources ''
33+
echo "Linking extra sources"
34+
if [ -e ./${extraSourcesDir} ]; then rm ./${extraSourcesDir}; fi
35+
ln -s ${extra-sources} ./${extraSourcesDir}
36+
'';
37+
copyExtraSources = pkgs.lib.optionalString hasExtraSources ''
38+
echo "Copying extra sources"
39+
cp -Lr ${extra-sources} ./${extraSourcesDir}
40+
'';
41+
42+
# Data
43+
data-drv = pkgs.linkFarm "data" data;
44+
hasData = builtins.length data > 0;
45+
linkData = pkgs.lib.optionalString hasData ''
46+
echo "Linking data"
47+
if [ -e ./${dataDir} ]; then rm ./${dataDir}; fi
48+
ln -s ${data-drv} ./${dataDir}
49+
'';
50+
copyData = pkgs.lib.optionalString hasData ''
51+
echo "Copying data"
52+
cp -Lr ${data-drv} ./${dataDir}
53+
'';
54+
in
55+
{
56+
devShells."dev-${crateName}-rust" = craneLib.devShell {
57+
shellHook = ''
58+
${linkExtraSources}
59+
${linkData}
60+
'';
61+
};
62+
63+
packages."${crateName}-rust" = craneLib.buildPackage (commonArgs // {
64+
inherit cargoArtifacts;
65+
doCheck = false;
66+
doInstallCargoArtifacts = true;
67+
});
68+
69+
checks."${crateName}-rust-test" = craneLib.cargoNextest (commonArgs // {
70+
inherit cargoArtifacts;
71+
});
72+
73+
checks."${crateName}-rust-clippy" = craneLib.cargoClippy (commonArgs // {
74+
inherit cargoArtifacts;
75+
});
76+
}

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
./runtimes/purescript/lbr-prelude/build.nix
4646
./runtimes/purescript/lbr-plutus/build.nix
4747
./runtimes/rust/lbr-prelude/build.nix
48+
./runtimes/rust/lbr-prelude-derive/build.nix
4849
./testsuites/lbt-prelude/api/build.nix
4950
./testsuites/lbt-prelude/golden/build.nix
5051
./testsuites/lbt-prelude/lbt-prelude-haskell/build.nix
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nix_direnv_watch_file ./build.nix
2+
use flake ../../..#dev-lbr-prelude-derive-rust
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target
2+
/proptest-regressions
3+
/.extras
4+
/data

0 commit comments

Comments
 (0)