-
Notifications
You must be signed in to change notification settings - Fork 0
lbf-nix for Rust #164
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
lbf-nix for Rust #164
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19e4e9a
Rust lbf-nix scaffolding
szg251 ef80479
Rust codegen: add CLI argument
szg251 0feee71
Merge branch 'bladyjoker/update-haskell' of github.com:mlabs-haskell/…
szg251 92ec42c
Rust nix: read import packages with Nix
szg251 a09df29
Remove nix trace
szg251 7ccaa1c
Wire up lbt-plutus-rust
szg251 adc70bc
Merge branch 'szg251/rust-codegen' of github.com:mlabs-haskell/lambda…
szg251 8752148
Merge branch 'szg251/rust-codegen' of github.com:mlabs-haskell/lambda…
szg251 7173e0c
Rust codegen: recursively checking for phantom type arguments
szg251 5961690
Rust codegen: use to_owned instead of clone
szg251 5232f44
Rust codegen: fix Plutus Interval mapping in config
szg251 286c76f
Merge branch 'main' of github.com:mlabs-haskell/lambda-buffers into s…
szg251 45e556b
Update plutus-ledger-api-rust to latest master revision
szg251 2730faf
lbt-prelude-purescript: Ignore linked data
szg251 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Build .lbf schemas that use LB Plutus (and by extension LB Prelude) package and targets Rust's plutus-ledger-api library. | ||
pkgs: lbf: lbg-rust: lbfRustOpts: | ||
let | ||
utils = import ./utils.nix pkgs; | ||
|
||
lbfRust = import ./lbf-rust.nix pkgs lbf lbg-rust; | ||
lbfRustOptsForPlutus = utils.overrideAttrs | ||
{ | ||
imports = { | ||
default = { }; | ||
override = libs: libs // { | ||
lbf-prelude = ../../libs/lbf-prelude; | ||
lbf-plutus = ../../libs/lbf-plutus; | ||
}; | ||
}; | ||
classes = { | ||
default = [ ]; | ||
override = cls: cls ++ [ "Prelude.Eq" "Plutus.V1.PlutusData" ]; | ||
}; | ||
configs = { | ||
default = [ ]; | ||
override = _: [ ../../lambda-buffers-codegen/data/rust-prelude-base.json ../../lambda-buffers-codegen/data/rust-plutus-pla.json ]; | ||
}; | ||
} | ||
lbfRustOpts; | ||
in | ||
lbfRust lbfRustOptsForPlutus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Build .lbf schemas that use LB Prelude package and targets Rust's std (and friends) library. | ||
pkgs: lbf: lbg-rust: lbfRustOpts: | ||
let | ||
utils = import ./utils.nix pkgs; | ||
|
||
lbfRs = import ./lbf-rust.nix pkgs lbf lbg-rust; | ||
lbfRustOptsForPrelude = utils.overrideAttrs | ||
{ | ||
imports = { | ||
default = { }; | ||
override = libs: libs // { lbf-prelude = ../../libs/lbf-prelude; }; | ||
}; | ||
classes = { | ||
default = [ ]; | ||
override = cls: cls ++ [ "Prelude.Eq" "Prelude.Json" ]; | ||
}; | ||
configs = { | ||
default = [ ]; | ||
override = cfgs: cfgs ++ [ ../../lambda-buffers-codegen/data/rust-prelude-base.json ]; | ||
}; | ||
} | ||
lbfRustOpts; | ||
|
||
in | ||
lbfRs lbfRustOptsForPrelude |
szg251 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# Base API for constructing Rust packages given .lbf schemas | ||
|
||
# Nixpkgs | ||
pkgs: | ||
# LambdaBuffers Frontend | ||
lbf: | ||
# LambdaBuffers Rust Codegen | ||
lbg-rust: | ||
let | ||
lbfRustOpts = | ||
{ | ||
# Source that is passed to `lbf` as the `--import-path` flag and used to find `files`. | ||
# Examples: src = ./api | ||
src | ||
, # Additional sources that are passed to `lbf` as the `--import-path` flag. | ||
# Examples: imports = { lbf-prelude = ./lbf-prelude; } | ||
imports ? { } | ||
, # .lbf files in `src` to compile and codegen. | ||
# Examples: files = [ "Foo.lbf" "Foo/Bar.lbf" ] | ||
files | ||
# Classes for which to generate implementations for (default lbf-prelude classes). | ||
, classes ? [ ] | ||
, # Dependencies to include in the Cabal's `build-depends` stanza. | ||
# examples: dependencies = [ "lbf-prelude" ] | ||
dependencies ? [ ] | ||
, configs ? [ ] | ||
, # Name of the package and also the name of the Cabal package. | ||
# Examples: name = "lbf-myproject" | ||
name | ||
, # Version of the package and also the version of the Cabal package. | ||
# Examples: version = "0.1.0.0" | ||
szg251 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
version ? "0.1.0" | ||
}: { inherit src imports files classes dependencies configs name version; }; | ||
|
||
lbf-build = import ./lbf-build.nix pkgs lbf; | ||
|
||
lbfBuild = opts: with (lbfRustOpts opts); | ||
let | ||
findModules = root: map | ||
(path: builtins.replaceStrings [ "/" ] [ "." ] | ||
(pkgs.lib.strings.removePrefix "./" (pkgs.lib.strings.removeSuffix ".lbf" | ||
(pkgs.lib.path.removePrefix root path)))) | ||
(builtins.filter (pkgs.lib.hasSuffix ".lbf") | ||
(pkgs.lib.filesystem.listFilesRecursive root)); | ||
packageSet = | ||
pkgs.writeTextFile { | ||
name = "lb-packages"; | ||
text = | ||
builtins.toJSON | ||
({ crate = findModules src; } // builtins.mapAttrs (_: findModules) imports); | ||
}; | ||
|
||
in | ||
lbf-build.build | ||
{ | ||
inherit src; | ||
opts = { | ||
inherit files; | ||
import-paths = pkgs.lib.attrsets.attrValues imports; | ||
gen = lbg-rust; | ||
gen-classes = classes; | ||
gen-dir = "autogen"; | ||
gen-opts = [ "--packages=${packageSet}" ] ++ builtins.map (c: "--config=${c}") configs; # WARN(bladyjoker): If I put quotes here everything breaks. | ||
szg251 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
work-dir = ".work"; | ||
}; | ||
}; | ||
|
||
cargoTemplate = opts: with (lbfRustOpts opts); | ||
pkgs.writeTextFile { | ||
name = "lambda-buffers-cabal-template"; | ||
szg251 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
text = '' | ||
[package] | ||
name = "${name}" | ||
version = "${version}" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
''; | ||
}; | ||
|
||
# | ||
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 = "fb93fa590908580eb40368369bf6614d42ce9a95" } | ||
''; | ||
szg251 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
build = opts: with (lbfRustOpts opts); | ||
let | ||
lbfBuilt = lbfBuild opts; | ||
in | ||
pkgs.stdenv.mkDerivation { | ||
inherit src version; | ||
pname = name; | ||
outputs = [ "out" "buildjson" ]; | ||
buildInputs = [ | ||
pkgs.jq | ||
]; | ||
buildPhase = '' | ||
ln -s ${lbfBuilt} autogen; | ||
ln -s ${lbfBuilt.workdir} .work-dir; | ||
ln -s ${lbfBuilt.buildjson} build.json; | ||
|
||
# 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; | ||
for DEP in $DEPS; do | ||
if [ $DEP != "std" ]; then | ||
echo "$(cat ${crateVersions} | grep "$DEP" || echo "$DEP = { path = \"../$DEP\" }")" >> Cargo.toml | ||
fi | ||
done | ||
''; | ||
|
||
installPhase = '' | ||
cp build.json $buildjson; | ||
echo "Dependencies collected" | ||
cat $buildjson; | ||
|
||
mkdir -p $out/src; | ||
cp -r autogen/* $out/src | ||
cp Cargo.toml $out/Cargo.toml; | ||
|
||
# Generating module files | ||
chmod -R u+w $out/src | ||
pushd $out/src | ||
|
||
MODS=$(find . -type f -name "*.rs") | ||
MODS+=" " | ||
MODS+=$(find . -type d) | ||
|
||
for MOD in $MODS; do | ||
if [ "$MOD" != "." ]; then | ||
if [ $(dirname $MOD) = "." ]; | ||
then MODFILE="lib.rs"; | ||
else MODFILE=$(dirname $MOD).rs; | ||
fi | ||
DOC="pub mod $(basename $MOD .rs);" | ||
|
||
if [ ! $(grep "$DOC" $MODFILE) ]; then | ||
echo $DOC >> $MODFILE; | ||
fi | ||
fi | ||
done | ||
|
||
echo "Files generated" | ||
find $out/; | ||
''; | ||
}; | ||
in | ||
build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
"char" | ||
], | ||
"Prelude.Integer": [ | ||
"num_bigint", | ||
"num-bigint", | ||
"BigInt" | ||
], | ||
"Prelude.Bool": [ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.