Skip to content

Rust Prelude runtime library #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extras/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
overlayAttrs = {
extras = {
purescriptFlake = import ./flake-purescript.nix pkgs;
rustFlake = import ./flake-rust.nix pkgs;
haskellData = import ./haskell-data.nix pkgs;
};
};
Expand Down
76 changes: 76 additions & 0 deletions extras/flake-rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
pkgs:

{ crane, src, system, crateName, extraSources ? [ ], extraSourcesDir ? ".extras", data ? [ ], dataDir ? "data" }:
let
rustWithTools = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rustfmt" "rust-analyzer" "clippy" ];
};
craneLib = crane.lib.${system}.overrideToolchain rustWithTools;

# Library source code with extra dependencies attached
fullSrc = pkgs.stdenv.mkDerivation {
src = craneLib.cleanCargoSource (craneLib.path src);
name = "lbf-rust-build-env";
unpackPhase = ''
mkdir $out
cp -r $src/* $out
cd $out
${copyExtraSources}
${copyData}
'';
};
commonArgs = {
src = fullSrc;
pname = crateName;
strictDeps = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

# Extra sources
extra-sources = pkgs.linkFarm "extra-sources" extraSources;
hasExtraSources = builtins.length extraSources > 0;
linkExtraSources = pkgs.lib.optionalString hasExtraSources ''
echo "Linking extra sources"
if [ -e ./${extraSourcesDir} ]; then rm ./${extraSourcesDir}; fi
ln -s ${extra-sources} ./${extraSourcesDir}
'';
copyExtraSources = pkgs.lib.optionalString hasExtraSources ''
echo "Copying extra sources"
cp -Lr ${extra-sources} ./${extraSourcesDir}
'';

# Data
data-drv = pkgs.linkFarm "data" data;
hasData = builtins.length data > 0;
linkData = pkgs.lib.optionalString hasData ''
echo "Linking data"
if [ -e ./${dataDir} ]; then rm ./${dataDir}; fi
ln -s ${data-drv} ./${dataDir}
'';
copyData = pkgs.lib.optionalString hasData ''
echo "Copying data"
cp -Lr ${data-drv} ./${dataDir}
'';
in
{
devShells."dev-${crateName}-rust" = craneLib.devShell {
shellHook = ''
${linkExtraSources}
${linkData}
'';
};

packages."${crateName}-rust" = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
doCheck = false;
doInstallCargoArtifacts = true;
});

checks."${crateName}-rust-test" = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
});

checks."${crateName}-rust-clippy" = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
});
}
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
./runtimes/purescript/lbr-prelude/build.nix
./runtimes/purescript/lbr-plutus/build.nix
./runtimes/rust/lbr-prelude/build.nix
./runtimes/rust/lbr-prelude-derive/build.nix
./testsuites/lbt-prelude/api/build.nix
./testsuites/lbt-prelude/golden/build.nix
./testsuites/lbt-prelude/lbt-prelude-haskell/build.nix
Expand Down
2 changes: 2 additions & 0 deletions runtimes/rust/lbr-prelude-derive/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nix_direnv_watch_file ./build.nix
use flake ../../..#dev-lbr-prelude-derive-rust
4 changes: 4 additions & 0 deletions runtimes/rust/lbr-prelude-derive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
/proptest-regressions
/.extras
/data
Loading