Skip to content

Commit 92ec42c

Browse files
committed
Rust nix: read import packages with Nix
1 parent 0feee71 commit 92ec42c

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

extras/lbf-nix/lbf-prelude-rust.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ let
77
lbfRustOptsForPrelude = utils.overrideAttrs
88
{
99
imports = {
10-
default = [ ];
11-
override = libs: libs ++ [ ../../libs/lbf-prelude ];
12-
};
13-
dependencies = {
14-
default = [ ];
15-
override = deps: deps ++ [ "lbf-prelude" ];
10+
default = { };
11+
override = libs: libs // { lbf-prelude = ../../libs/lbf-prelude; };
1612
};
1713
classes = {
1814
default = [ ];

extras/lbf-nix/lbf-rust.nix

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ let
1313
# Examples: src = ./api
1414
src
1515
, # Additional sources that are passed to `lbf` as the `--import-path` flag.
16-
# Examples: imports = [ lbf-prelude ]
17-
imports ? [ ]
16+
# Examples: imports = { lbf-prelude = ./lbf-prelude; }
17+
imports ? { }
1818
, # .lbf files in `src` to compile and codegen.
1919
# Examples: files = [ "Foo.lbf" "Foo/Bar.lbf" ]
2020
files
@@ -35,16 +35,32 @@ let
3535
lbf-build = import ./lbf-build.nix pkgs lbf;
3636

3737
lbfBuild = opts: with (lbfRustOpts opts);
38+
let
39+
findModules = root: map
40+
(path: builtins.replaceStrings [ "/" ] [ "." ]
41+
(pkgs.lib.strings.removePrefix "./" (pkgs.lib.strings.removeSuffix ".lbf"
42+
(pkgs.lib.path.removePrefix root path))))
43+
(builtins.filter (pkgs.lib.hasSuffix ".lbf")
44+
(pkgs.lib.filesystem.listFilesRecursive root));
45+
packageSet =
46+
pkgs.writeTextFile {
47+
name = "lb-packages";
48+
text =
49+
builtins.toJSON
50+
({ crate = findModules src; } // builtins.mapAttrs (_: findModules) imports);
51+
};
52+
53+
in
3854
lbf-build.build
3955
{
4056
inherit src;
4157
opts = {
4258
inherit files;
43-
import-paths = imports;
59+
import-paths = pkgs.lib.attrsets.attrValues imports;
4460
gen = lbg-rust;
4561
gen-classes = classes;
4662
gen-dir = "autogen";
47-
gen-opts = builtins.map (c: "--config=${c}") configs; # WARN(bladyjoker): If I put quotes here everything breaks.
63+
gen-opts = [ "--packages=${builtins.trace "${packageSet}" packageSet}" ] ++ builtins.map (c: "--config=${c}") configs; # WARN(bladyjoker): If I put quotes here everything breaks.
4864
work-dir = ".work";
4965
};
5066
};
@@ -62,14 +78,13 @@ let
6278
'';
6379
};
6480

81+
#
6582
crateVersions = pkgs.writeTextFile {
6683
name = "lambda-buffers-crate-versions";
6784
text = ''
6885
num-bigint = "0.4.4"
6986
serde_json = { version = "1.0.107", features = ["arbitrary_precision"] }
7087
plutus-ledger-api = { github = "https://github.com/mlabs-haskell/plutus-ledger-api-rust", features = ["lbf"] }
71-
lbr-prelude = { path = "../lbr-prelude" }
72-
lbr-prelude-derive = { path = "../lbr-prelude-derive" }
7388
'';
7489
};
7590

@@ -108,6 +123,7 @@ let
108123
mkdir -p $out/src;
109124
cp -r autogen/* $out/src
110125
cp Cargo.toml $out/Cargo.toml;
126+
cp build.json $out/build.json;
111127
112128
# Generating module files
113129
chmod -R u+w $out/src

lambda-buffers-codegen/lambda-buffers-codegen.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ library
104104
, prettyprinter
105105
, proto-lens
106106
, text
107+
, vector
107108

108109
hs-source-dirs: src
109110
exposed-modules:

lambda-buffers-codegen/src/LambdaBuffers/Codegen/Rust/Print/LamVal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module LambdaBuffers.Codegen.Rust.Print.LamVal (printValueE, printInstance) where
22

33
import Control.Lens ((&), (.~))
4+
import Control.Monad (replicateM)
45
import Control.Monad.Error.Class (MonadError (throwError))
5-
import Control.Monad.Except (replicateM)
66
import Data.Foldable (Foldable (toList))
77
import Data.List (sortOn)
88
import Data.Map qualified as Map
@@ -316,7 +316,7 @@ printTupleE pkgs iTyDefs l r = do
316316
printTextE :: MonadPrint m => Text.Text -> m (Doc ann)
317317
printTextE = return . fromStr . dquotes . pretty
318318

319-
printCaseTextE :: (MonadPrint m) => R.PkgMap -> PC.TyDefs -> LV.ValueE -> [(LV.ValueE, LV.ValueE)] -> (LV.ValueE -> LV.ValueE) -> m (Doc ann)
319+
printCaseTextE :: MonadPrint m => R.PkgMap -> PC.TyDefs -> LV.ValueE -> [(LV.ValueE, LV.ValueE)] -> (LV.ValueE -> LV.ValueE) -> m (Doc ann)
320320
printCaseTextE pkgs iTyDefs txtVal cases otherCase = do
321321
caseValDoc <- printValueE pkgs iTyDefs txtVal
322322
caseDocs <-

testsuites/lbt-prelude/lbt-prelude-rust/Cargo.lock

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

testsuites/lbt-prelude/lbt-prelude-rust/build.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{
1212
name = "lbf-prelude-golden-api";
1313
path = config.packages.lbf-prelude-golden-api-rust;
14-
1514
}
1615
{
1716
name = "lbf-prelude";

0 commit comments

Comments
 (0)