Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bladyjoker/flake-lang…
Browse files Browse the repository at this point in the history
…-migration
  • Loading branch information
jared committed Feb 6, 2024
2 parents 52daf94 + 063055a commit 17241ef
Show file tree
Hide file tree
Showing 48 changed files with 4,153 additions and 383 deletions.
4 changes: 2 additions & 2 deletions docs/typescript-plutus/api/lbf/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _:
{
perSystem = { config, ... }:
let
tsFlake =
lbf-plutus-sample-project-typescript =
config.lbf-nix.lbfPlutusTypescript {
name = "lbf-plutus-sample-project";
src = ./.;
Expand All @@ -11,7 +11,7 @@ _:
in
{
packages = {
inherit (tsFlake.packages) lbf-plutus-sample-project-typescript lbf-plutus-sample-project-typescript-tgz;
inherit lbf-plutus-sample-project-typescript;
};
};
}
2 changes: 1 addition & 1 deletion docs/typescript-plutus/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
src = ./.;

npmExtraDependencies = [
config.packages.lbf-plutus-sample-project-typescript-tgz
config.packages.lbf-plutus-sample-project-typescript
];

devShellTools = config.settings.shell.tools;
Expand Down
4 changes: 2 additions & 2 deletions docs/typescript-prelude/api/lbf/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _:
{
perSystem = { config, ... }:
let
tsFlake =
lbf-prelude-sample-project-typescript =
config.lbf-nix.lbfPreludeTypescript {
name = "lbf-prelude-sample-project";
src = ./.;
Expand All @@ -11,7 +11,7 @@ _:
in
{
packages = {
inherit (tsFlake.packages) lbf-prelude-sample-project-typescript lbf-prelude-sample-project-typescript-tgz;
inherit lbf-prelude-sample-project-typescript;
};
};
}
2 changes: 1 addition & 1 deletion docs/typescript-prelude/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name = "prelude-sample-project";
src = ./.;
npmExtraDependencies = [
config.packages.lbf-prelude-sample-project-typescript-tgz
config.packages.lbf-prelude-sample-project-typescript
];

devShellTools = config.settings.shell.tools;
Expand Down
7 changes: 1 addition & 6 deletions extras/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Makes a per system `lbf-nix` option.
perSystem = flake-parts-lib.mkPerSystemOption
({ pkgs, config, pkgsForRust, ... }: {
({ pkgs, config, ... }: {

options.lbf-nix = lib.mkOption {
type = lib.types.anything;
Expand All @@ -38,11 +38,6 @@
buildInputs = config.settings.shell.tools;
};

lbf-nix = {
# NOTE(bladyjoker): If you need to add a function the export externally and use internally via config.lbf-nix, add it here.
rustFlake = import ./flake-rust.nix pkgsForRust;
};

# Makes it available in the per system `lib` argument.
_module.args.lib = lib // {
inherit (config) lbf-nix;
Expand Down
109 changes: 0 additions & 109 deletions extras/flake-rust.nix

This file was deleted.

54 changes: 31 additions & 23 deletions extras/lbf-nix/lbf-rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ let
, # Version of the package and also the version of the Cargo crate.
# Examples: version = "0.1.0.0"
version ? "0.1.0"
}: { inherit src imports files classes dependencies configs name version; };
, # Version of dependencies
# A package will only be added to Cargo.toml, if the generated code directly depends on it
# Defaults to version 0.1.0 for all packages
extraVersions ? { }
}: { inherit src imports files classes dependencies configs name version extraVersions; };

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

Expand Down Expand Up @@ -66,29 +70,27 @@ let
};

cargoTemplate = opts: with (lbfRustOpts opts);
pkgs.writeTextFile {
name = "lambda-buffers-cargo-template";
text = ''
[package]
name = "${name}"
version = "${version}"
edition = "2021"
[dependencies]
'';
};
pkgs.writers.writeJSON "lambda-buffers-cargo-template"
{
package = {
inherit name version;
edition = "2021";
};
};

# This is a lookup table of default crate versions used by lamba-buffers modules
# Based on the contents of `build.json` a subset of these will be attached to the
# Cargo.toml file
crateVersions = pkgs.writeTextFile {
name = "lambda-buffers-crate-versions";
text = ''
num-bigint = "0.4.4"
serde_json = { version = "1.0.107", features = ["arbitrary_precision"] }
plutus-ledger-api = { git = "https://github.com/mlabs-haskell/plutus-ledger-api-rust", features = [ "lbf", ], rev = "d66d39c949f59e543c91ee36377c93422d8e9d75" }
'';
};
# Note: lbr-prelude and and plutus prelude versions are pinned here, but can be overridden with `extraVersions`
versionTable =
{
num-bigint = "~0.4";
serde_json = { version = "^1.0"; features = [ "arbitrary_precision" ]; };
plutus-ledger-api = { git = "https://github.com/mlabs-haskell/plutus-ledger-api-rust"; features = [ "lbf" ]; rev = "d66d39c949f59e543c91ee36377c93422d8e9d75"; };
};

crateVersions = opts: with (lbfRustOpts opts);
pkgs.writers.writeJSON "lambda-buffers-crate-versions" (versionTable // extraVersions);

build = opts: with (lbfRustOpts opts);
let
Expand All @@ -100,6 +102,7 @@ let
outputs = [ "out" "buildjson" ];
buildInputs = [
pkgs.jq
pkgs.yj
];
buildPhase = ''
ln -s ${lbfBuilt} autogen;
Expand All @@ -109,22 +112,27 @@ let
# Generating Cargo manifest file
DEPS=$(echo ${builtins.concatStringsSep " " dependencies} $(cat build.json | jq -r ".[]" | sort -u));
echo "Gathered Cargo deps $DEPS";
cat ${cargoTemplate opts} > Cargo.toml;
cat ${cargoTemplate opts} > Cargo.json;
# Using the lookup table `crateVersions`, filling in the library version.
# If no version is found, we default to a local path dependency, pointing to
# a sibling directory (directory in extra-sources or .extras)
# e.g.: for `lbr-prelude` we print `lbr-prelude = { path = "../lbr-prelude" }
for DEP in $DEPS; do
if [ $DEP != "std" ]; then
echo "$(cat ${crateVersions} | grep "$DEP" || echo "$DEP = { path = \"../$DEP\" }")" >> Cargo.toml
VER=$(cat ${crateVersions opts} | jq ".\"$DEP\"" -c);
if [ $VER == "null" ]; then
VER="{\"path\": \"../$DEP-0.1.0\"}"
fi
cat Cargo.json | jq ".dependencies+={\"$DEP\":$VER}" > tmp.json;
mv tmp.json Cargo.json
fi
done
cat Cargo.json | yj -jt > Cargo.toml;
'';

installPhase = ''
cp build.json $buildjson;
echo "Dependencies collected"
cat $buildjson;
mkdir -p $out/src;
cp -r autogen/* $out/src
Expand Down
2 changes: 1 addition & 1 deletion extras/lbf-nix/lbf-typescript.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,4 @@ let
});
});
in
lbTypescriptFlake
lbTypescriptFlake.packages."${name}-typescript-tgz"
Loading

0 comments on commit 17241ef

Please sign in to comment.