30
30
, # Version of the package and also the version of the Cargo crate.
31
31
# Examples: version = "0.1.0.0"
32
32
version ? "0.1.0"
33
- } : { inherit src imports files classes dependencies configs name version ; } ;
33
+ , # Version of dependencies
34
+ # A package will only be added to Cargo.toml, if the generated code directly depends on it
35
+ # Defaults to version 0.1.0 for all packages
36
+ extraVersions ? { }
37
+ } : { inherit src imports files classes dependencies configs name version extraVersions ; } ;
34
38
35
39
lbf-build = import ./lbf-build.nix pkgs lbf ;
36
40
66
70
} ;
67
71
68
72
cargoTemplate = opts : with ( lbfRustOpts opts ) ;
69
- pkgs . writeTextFile {
70
- name = "lambda-buffers-cargo-template" ;
71
- text = ''
72
- [package]
73
- name = "${ name } "
74
- version = "${ version } "
75
- edition = "2021"
76
-
77
- [dependencies]
78
- '' ;
79
- } ;
73
+ pkgs . writers . writeJSON "lambda-buffers-cargo-template"
74
+ {
75
+ package = {
76
+ inherit name version ;
77
+ edition = "2021" ;
78
+ } ;
79
+ } ;
80
80
81
81
# This is a lookup table of default crate versions used by lamba-buffers modules
82
82
# Based on the contents of `build.json` a subset of these will be attached to the
83
83
# Cargo.toml file
84
- crateVersions = pkgs . writeTextFile {
85
- name = "lambda-buffers-crate-versions" ;
86
- text = ''
87
- num-bigint = "0.4.4"
88
- serde_json = { version = "1.0.107", features = ["arbitrary_precision"] }
89
- plutus-ledger-api = { git = "https://github.com/mlabs-haskell/plutus-ledger-api-rust", features = [ "lbf", ], rev = "d66d39c949f59e543c91ee36377c93422d8e9d75" }
90
- '' ;
91
- } ;
84
+ # Note: lbr-prelude and and plutus prelude versions are pinned here, but can be overridden with `extraVersions`
85
+ versionTable =
86
+ {
87
+ num-bigint = "~0.4" ;
88
+ serde_json = { version = "^1.0" ; features = [ "arbitrary_precision" ] ; } ;
89
+ plutus-ledger-api = { git = "https://github.com/mlabs-haskell/plutus-ledger-api-rust" ; features = [ "lbf" ] ; rev = "d66d39c949f59e543c91ee36377c93422d8e9d75" ; } ;
90
+ } ;
91
+
92
+ crateVersions = opts : with ( lbfRustOpts opts ) ;
93
+ pkgs . writers . writeJSON "lambda-buffers-crate-versions" ( versionTable // extraVersions ) ;
92
94
93
95
build = opts : with ( lbfRustOpts opts ) ;
94
96
let
100
102
outputs = [ "out" "buildjson" ] ;
101
103
buildInputs = [
102
104
pkgs . jq
105
+ pkgs . yj
103
106
] ;
104
107
buildPhase = ''
105
108
ln -s ${ lbfBuilt } autogen;
@@ -109,22 +112,27 @@ let
109
112
# Generating Cargo manifest file
110
113
DEPS=$(echo ${ builtins . concatStringsSep " " dependencies } $(cat build.json | jq -r ".[]" | sort -u));
111
114
echo "Gathered Cargo deps $DEPS";
112
- cat ${ cargoTemplate opts } > Cargo.toml ;
115
+ cat ${ cargoTemplate opts } > Cargo.json ;
113
116
# Using the lookup table `crateVersions`, filling in the library version.
114
117
# If no version is found, we default to a local path dependency, pointing to
115
118
# a sibling directory (directory in extra-sources or .extras)
116
119
# e.g.: for `lbr-prelude` we print `lbr-prelude = { path = "../lbr-prelude" }
117
120
for DEP in $DEPS; do
118
121
if [ $DEP != "std" ]; then
119
- echo "$(cat ${ crateVersions } | grep "$DEP" || echo "$DEP = { path = \"../$DEP\" }")" >> Cargo.toml
122
+ VER=$(cat ${ crateVersions opts } | jq ".\"$DEP\"" -c);
123
+ if [ $VER == "null" ]; then
124
+ VER="{\"path\": \"../$DEP-0.1.0\"}"
125
+ fi
126
+ cat Cargo.json | jq ".dependencies+={\"$DEP\":$VER}" > tmp.json;
127
+ mv tmp.json Cargo.json
120
128
fi
121
129
done
130
+ cat Cargo.json | yj -jt > Cargo.toml;
122
131
'' ;
123
132
124
133
installPhase = ''
125
134
cp build.json $buildjson;
126
135
echo "Dependencies collected"
127
- cat $buildjson;
128
136
129
137
mkdir -p $out/src;
130
138
cp -r autogen/* $out/src
0 commit comments