Skip to content

Commit 063055a

Browse files
authored
Merge pull request #184 from mlabs-haskell/szg251/simplified-rust-flake
Use simplified rustFlake + handle lb package versions
2 parents 7dee7ea + dfca33b commit 063055a

File tree

11 files changed

+99
-232
lines changed

11 files changed

+99
-232
lines changed

extras/build.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Makes a per system `lbf-nix` option.
2525
perSystem = flake-parts-lib.mkPerSystemOption
26-
({ pkgs, config, pkgsForCtl, pkgsForHaskellNix, pkgsForRust, ... }: {
26+
({ pkgs, config, pkgsForCtl, pkgsForHaskellNix, ... }: {
2727

2828
options.lbf-nix = lib.mkOption {
2929
type = lib.types.anything;
@@ -43,7 +43,6 @@
4343

4444
purescriptFlake = import ./flake-purescript.nix pkgsForCtl;
4545

46-
rustFlake = import ./flake-rust.nix pkgsForRust;
4746
haskellData = import ./haskell-data.nix pkgs;
4847
haskellFlake = import ./flake-haskell.nix pkgsForHaskellNix;
4948
haskellPlutusFlake = import ./flake-haskell-plutus.nix inputs.cardano-haskell-packages pkgsForHaskellNix;

extras/flake-rust.nix

Lines changed: 0 additions & 109 deletions
This file was deleted.

extras/lbf-nix/lbf-rust.nix

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ let
3030
, # Version of the package and also the version of the Cargo crate.
3131
# Examples: version = "0.1.0.0"
3232
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; };
3438

3539
lbf-build = import ./lbf-build.nix pkgs lbf;
3640

@@ -66,29 +70,27 @@ let
6670
};
6771

6872
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+
};
8080

8181
# This is a lookup table of default crate versions used by lamba-buffers modules
8282
# Based on the contents of `build.json` a subset of these will be attached to the
8383
# 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);
9294

9395
build = opts: with (lbfRustOpts opts);
9496
let
@@ -100,6 +102,7 @@ let
100102
outputs = [ "out" "buildjson" ];
101103
buildInputs = [
102104
pkgs.jq
105+
pkgs.yj
103106
];
104107
buildPhase = ''
105108
ln -s ${lbfBuilt} autogen;
@@ -109,22 +112,27 @@ let
109112
# Generating Cargo manifest file
110113
DEPS=$(echo ${builtins.concatStringsSep " " dependencies} $(cat build.json | jq -r ".[]" | sort -u));
111114
echo "Gathered Cargo deps $DEPS";
112-
cat ${cargoTemplate opts} > Cargo.toml;
115+
cat ${cargoTemplate opts} > Cargo.json;
113116
# Using the lookup table `crateVersions`, filling in the library version.
114117
# If no version is found, we default to a local path dependency, pointing to
115118
# a sibling directory (directory in extra-sources or .extras)
116119
# e.g.: for `lbr-prelude` we print `lbr-prelude = { path = "../lbr-prelude" }
117120
for DEP in $DEPS; do
118121
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
120128
fi
121129
done
130+
cat Cargo.json | yj -jt > Cargo.toml;
122131
'';
123132

124133
installPhase = ''
125134
cp build.json $buildjson;
126135
echo "Dependencies collected"
127-
cat $buildjson;
128136
129137
mkdir -p $out/src;
130138
cp -r autogen/* $out/src

runtimes/rust/lbr-prelude-derive/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ repository = "https://github.com/mlabs-haskell/lambda-buffers"
1111
proc-macro = true
1212

1313
[dependencies]
14-
proc-macro2 = { version = "1.0.66", default-features = false }
15-
quote = "1.0.33"
16-
syn = { version = "2.0.38", features = ["extra-traits"] }
17-
trybuild = { version = "1.0.49", features = ["diff"] }
14+
proc-macro2 = { version = "^1.0.66", default-features = false }
15+
quote = "^1.0.33"
16+
syn = { version = "^2.0.38", features = ["extra-traits"] }
17+
trybuild = { version = "^1.0.49", features = ["diff"] }
1818

1919
[dev-dependencies]
20-
lbr-prelude = { path = ".extras/lbr-prelude", default-features = false }
21-
num-bigint = "0.4.4"
22-
serde_json = "1.0.107"
20+
lbr-prelude = { path = ".extras/lbr-prelude-0.1.0", default-features = false }
21+
num-bigint = "~0.4"
22+
serde_json = "^1.0"

runtimes/rust/lbr-prelude-derive/build.nix

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
{ inputs, ... }: {
2-
perSystem = { config, ... }:
2+
perSystem = { config, system, ... }:
33
let
44
rustFlake =
5-
config.lbf-nix.rustFlake {
5+
inputs.flake-lang.lib.${system}.rustFlake {
66
src = ./.;
77
inherit (inputs) crane;
88
crateName = "lbr-prelude-derive";
99
extraSources = [
10-
{
11-
name = "lbr-prelude";
12-
path = config.packages.lbr-prelude-rust-src;
13-
}
10+
config.packages.lbr-prelude-rust-src
1411
];
1512
devShellHook = config.settings.shell.hook;
1613
};

runtimes/rust/lbr-prelude/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ description = "LambdaBuffers runtime library for the Prelude schema."
88
repository = "https://github.com/mlabs-haskell/lambda-buffers"
99

1010
[dependencies]
11-
data-encoding = "2.4.0"
12-
num-bigint = "0.4.4"
13-
proptest = "1.3.1"
14-
serde = "1.0.188"
15-
serde_json = { version = "1.0.107", features = ["arbitrary_precision"] }
16-
thiserror = "1.0.49"
17-
lbr-prelude-derive = { version = "0.1.0", path = ".extras/lbr-prelude-derive", optional = true }
11+
data-encoding = "^2.4.0"
12+
num-bigint = "~0.4"
13+
proptest = "^1.3.1"
14+
serde = "^1.0.188"
15+
serde_json = { version = "^1.0", features = ["arbitrary_precision"] }
16+
thiserror = "^1.0.49"
17+
lbr-prelude-derive = { version = "0.1.0", path = ".extras/lbr-prelude-derive-0.1.0", optional = true }
1818

1919
[features]
2020
default = ["derive"]

runtimes/rust/lbr-prelude/build.nix

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
{ inputs, ... }: {
2-
perSystem = { config, ... }:
2+
perSystem = { config, system, ... }:
33
let
44
rustFlake =
5-
config.lbf-nix.rustFlake {
5+
inputs.flake-lang.lib.${system}.rustFlake {
66
src = ./.;
77
inherit (inputs) crane;
88
crateName = "lbr-prelude";
99
extraSources = [
10-
{
11-
name = "lbr-prelude-derive";
12-
path = config.packages.lbr-prelude-derive-rust-src;
13-
}
10+
config.packages.lbr-prelude-derive-rust-src
1411
];
1512
devShellHook = config.settings.shell.hook;
1613
};

testsuites/lbt-plutus/lbt-plutus-rust/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2021"
77
plutus-ledger-api = { git = "https://github.com/mlabs-haskell/plutus-ledger-api-rust", features = [
88
"lbf",
99
], rev = "d66d39c949f59e543c91ee36377c93422d8e9d75" }
10-
lbf-plutus-rust-golden-api = { path = ".extras/lbf-plutus-rust-golden-api" }
11-
lbf-prelude = { path = ".extras/lbf-prelude" }
12-
lbr-prelude = { path = ".extras/lbr-prelude" }
10+
lbf-plutus-rust-golden-api = { path = ".extras/lbf-plutus-rust-golden-api-0.1.0" }
11+
lbf-prelude = { path = ".extras/lbf-prelude-0.1.0" }
12+
lbr-prelude = { path = ".extras/lbr-prelude-0.1.0" }
1313
serde_json = "1.0.108"
1414
num-bigint = "0.4.4"

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

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,29 @@
11
{ inputs, ... }: {
2-
perSystem = { config, ... }:
2+
perSystem = { config, system, ... }:
33

44
let
5-
rustFlake = config.lbf-nix.rustFlake {
6-
src = ./.;
7-
inherit (inputs) crane;
8-
crateName = "lbt-plutus";
5+
rustFlake =
6+
inputs.flake-lang.lib.${system}.rustFlake {
7+
src = ./.;
8+
inherit (inputs) crane;
9+
crateName = "lbt-plutus";
910

10-
extraSources = [
11-
{
12-
name = "lbf-plutus-rust-golden-api";
13-
path = config.packages.lbf-plutus-golden-api-rust;
14-
}
15-
{
16-
name = "lbf-prelude";
17-
path = config.packages.lbf-prelude-rust;
18-
}
19-
{
20-
name = "lbf-plutus";
21-
path = config.packages.lbf-plutus-rust;
22-
}
23-
{
24-
name = "lbr-prelude";
25-
path = config.packages.lbr-prelude-rust-src;
26-
}
27-
{
28-
name = "lbr-prelude-derive";
29-
path = config.packages.lbr-prelude-derive-rust-src;
30-
}
31-
];
32-
data = [
33-
{
34-
name = "lbt-plutus-golden-data";
35-
path = config.packages.lbt-plutus-golden-rust;
36-
}
37-
];
38-
devShellHook = config.settings.shell.hook;
11+
extraSources = [
12+
config.packages.lbf-plutus-golden-api-rust
13+
config.packages.lbf-prelude-rust
14+
config.packages.lbf-plutus-rust
15+
config.packages.lbr-prelude-rust-src
16+
config.packages.lbr-prelude-derive-rust-src
17+
];
18+
data = [
19+
{
20+
name = "lbt-plutus-golden-data";
21+
path = config.packages.lbt-plutus-golden-rust;
22+
}
23+
];
24+
devShellHook = config.settings.shell.hook;
3925

40-
};
26+
};
4127
in
4228
{
4329

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
lbf-prelude-golden-api = { path = ".extras/lbf-prelude-golden-api" }
8-
lbf-prelude = { path = ".extras/lbf-prelude" }
9-
lbr-prelude = { path = ".extras/lbr-prelude" }
7+
lbf-prelude-golden-api = { path = ".extras/lbf-prelude-golden-api-0.1.0" }
8+
lbf-prelude = { path = ".extras/lbf-prelude-0.1.0" }
9+
lbr-prelude = { path = ".extras/lbr-prelude-0.1.0" }
1010
serde_json = "1.0.108"
1111
num-bigint = "0.4.4"

0 commit comments

Comments
 (0)