Skip to content

Commit 64009d3

Browse files
author
jared
committed
Merge branch 'main' into jared/typescript-runtime
2 parents b345827 + 05cdec8 commit 64009d3

File tree

102 files changed

+8545
-6715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+8545
-6715
lines changed

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ shellcheck...........................................(no files to check)Skipped
6969
typos....................................................................Passed
7070
```
7171

72-
To run all the code quality tooling specified in the [pre-commit-check config file](../pre-commit.nix)
72+
To run all the code quality tooling specified in the [pre-commit-check config file](https://github.com/mlabs-haskell/lambda-buffers/blob/main/pre-commit.nix)

docs/haskell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ github:mlabs-haskell/lambda-buffers#lbf-prelude-to-haskell`.
1919

2020
In this chapter, we're going to use the latter option.
2121

22-
Let's now use `lbf-prelude-to-haskell` to process the [Document.lbf](examples/Document.lbf) schema.
22+
Let's now use `lbf-prelude-to-haskell` to process the [Document.lbf](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/examples/Document.lbf) schema.
2323

2424
```purescript
2525
module Document

docs/plutarch.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ For a full example see [Example](#example).
4343

4444
Writing .lbf schemas with API types intended for Plutarch backend will typically use the following LambdaBuffers schema modules:
4545

46-
1. [Prelude](../libs/lbf-prelude/Prelude.lbf),
47-
2. [Plutus.V1](../libs/lbf-plutus/Plutus/V1.lbf),
48-
3. [Plutus.V2](../libs/lbf-plutus/Plutus/V2.lbf).
46+
1. [Prelude](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude/Prelude.lbf),
47+
2. [Plutus.V1](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus/Plutus/V1.lbf),
48+
3. [Plutus.V2](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus/Plutus/V2.lbf).
4949

50-
Take a look at [Example.lbf](./plutarch/api/Example.lbf) schema as an example.
50+
Take a look at [Example.lbf](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch/api/Example.lbf) schema as an example.
5151

5252
## Haskell libraries
5353

5454
The necessary LambdaBuffers runtime libraries a typical Plutarch project needs when working with LambdaBuffers:
5555

56-
1. [lbr-plutarch](../runtimes/haskell/lbr-plutarch) a Haskell runtime library necessary for working with `lbf-xyz` libraries.
57-
2. [lbf-prelude-plutarch](../libs/lbf-prelude) that contains the [LambdaBuffers Prelude](../libs/lbf-prelude) schema library generated by LambdaBuffers.
58-
3. [lbf-plutus-plutarch](../libs/lbf-plutus) that contains the [LambdaBuffers Plutus](../libs/lbf-plutus) schema library generated by LambdaBuffers.
56+
1. [lbr-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/runtimes/haskell/lbr-plutarch) a Haskell runtime library necessary for working with `lbf-xyz` libraries.
57+
2. [lbf-prelude-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude) that contains the [LambdaBuffers Prelude](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude) schema library generated by LambdaBuffers.
58+
3. [lbf-plutus-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus) that contains the [LambdaBuffers Plutus](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus) schema library generated by LambdaBuffers.
5959

60-
Of course, additional imports for Plutarch libraries are also necessary [plutarch](https://github.com/Plutonomicon/plutarch-plutus) and optionally [plutarch-extra](https://github.com/Plutonomicon/plutarch-plutus/plutarch-extra).
60+
Of course, additional imports for Plutarch libraries are also necessary [plutarch](https://github.com/Plutonomicon/plutarch-plutus) and optionally [plutarch-extra](https://github.com/Plutonomicon/plutarch-plutus/tree/master/plutarch-extra).
6161

6262
For a full example see [Example](#example).
6363

@@ -99,10 +99,10 @@ import Plutarch.Api.V1 ()
9999
import Plutarch.Api.V2 ()
100100
```
101101

102-
1. LambdaBuffers.Plutus.V1.Plutarch is a module generated from [Plutus.V1](../libs/lbf-plutus/Plutus/V1.lbf) LambdaBuffers schema and provided by the [lbf-plutus-plutarch](../libs/lbf-plutus) runtime library.
103-
2. LambdaBuffers.Plutus.V2.Plutarch is a module generated from [Plutus.V2](../libs/lbf-plutus/Plutus/V2.lbf) LambdaBuffers schema and provided by the [lbf-plutus-plutarch](../libs/lbf-plutus) runtime library.
104-
3. LambdaBuffers.Prelude.Plutarch is a module generated from [Prelude](../libs/lbf-prelude/Prelude.lbf) LambdaBuffers schema and provided by the [lbf-prelude-plutarch](../libs/lbf-prelude) runtime library.
105-
4. LambdaBuffers.Runtime.Plutarch is a module provided by the [lbr-plutarch](../runtimes/haskell/lbr-plutarch) runtime library.
102+
1. LambdaBuffers.Plutus.V1.Plutarch is a module generated from [Plutus.V1](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus/Plutus/V1.lbf) LambdaBuffers schema and provided by the [lbf-plutus-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus) runtime library.
103+
2. LambdaBuffers.Plutus.V2.Plutarch is a module generated from [Plutus.V2](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus/Plutus/V2.lbf) LambdaBuffers schema and provided by the [lbf-plutus-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus) runtime library.
104+
3. LambdaBuffers.Prelude.Plutarch is a module generated from [Prelude](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude/Prelude.lbf) LambdaBuffers schema and provided by the [lbf-prelude-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude) runtime library.
105+
4. LambdaBuffers.Runtime.Plutarch is a module provided by the [lbr-plutarch](https://github.com/mlabs-haskell/lambda-buffers/tree/main/runtimes/haskell/lbr-plutarch) runtime library.
106106

107107
> Generated Plutarch module for a LambdaBuffers schema `Foo/Bar.lbf` (ie. `Foo.Bar`) is stored at `Foo/Bar/Plutarch.hs`
108108

@@ -147,15 +147,15 @@ For example the `Foo` record defined above would have no difference in Plutarch
147147
prod Foo = Integer Bool
148148
```
149149

150-
The Plutarch backend doesn't support the use of `Char`, `Text`, `Bytes` (there's a Plutus.V1.Bytes), `Set` and `Map` (there's a Plutus.V1.Map) from [LambdaBuffers Prelude](../libs/lbf-prelude/Prelude.lbf) module.
150+
The Plutarch backend doesn't support the use of `Char`, `Text`, `Bytes` (there's a Plutus.V1.Bytes), `Set` and `Map` (there's a Plutus.V1.Map) from [LambdaBuffers Prelude](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude/Prelude.lbf) module.
151151

152152
## Plutarch
153153

154154
### Type definition mapping
155155

156-
Plutarch backend supports all types from the [LambdaBuffers Plutus](../libs/lbf-plutus) schema library, as to enable full featured Plutus script development.
156+
Plutarch backend supports all types from the [LambdaBuffers Plutus](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-plutus) schema library, as to enable full featured Plutus script development.
157157

158-
Additionally, it also supports some types from the [LambdaBuffers Prelude](../libs/lbf-prelude) schema library, namely `Bool`, `Integer`, `Maybe`, `Either` and `List`.
158+
Additionally, it also supports some types from the [LambdaBuffers Prelude](https://github.com/mlabs-haskell/lambda-buffers/tree/main/libs/lbf-prelude) schema library, namely `Bool`, `Integer`, `Maybe`, `Either` and `List`.
159159

160160
```lbf
161161
module Foo
@@ -318,7 +318,7 @@ All generated types have a PShow instance derived using the internal Plutarch de
318318

319319
## Example
320320

321-
Let work through the [Plutarch example](./plutarch) available in the repo.
321+
Let work through the [Plutarch example](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch) available in the repo.
322322

323323
First, please check the [Getting started](getting-started.md) guide on how to prepare to work with the repo and setup Nix.
324324

@@ -340,8 +340,8 @@ lambda-buffers/docs/plutarch ❯ find
340340

341341
The salient bits we should focus on are:
342342

343-
1. The LambdaBuffers .lbf schema in [./api/Example.lbf](./plutarch/api/Example.lbf) that describes the API types used by our little program,
344-
2. The Haskell Plutarch program in [./app/Example.hs](./plutarch/app/Example.hs) that works with the API types.
343+
1. The LambdaBuffers .lbf schema in [./api/Example.lbf](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch/api/Example.lbf) that describes the API types used by our little program,
344+
2. The Haskell Plutarch program in [./app/Example.hs](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch/app/Example.hs) that works with the API types.
345345

346346
To inspect the generated library:
347347

@@ -359,7 +359,7 @@ autogen/LambdaBuffers/Example/Plutarch.hs
359359
360360
However, it's not expected for users to need to do this. If you have any issue please reach out.
361361

362-
Inspecting the [Cabal file](./plutarch/plutarch-example.cabal) shows the standard runtime libraries we need:
362+
Inspecting the [Cabal file](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch/plutarch-example.cabal) shows the standard runtime libraries we need:
363363

364364
```shell
365365
lambda-buffers/docs/plutarch ❯ cabal info .
@@ -388,4 +388,4 @@ lambda-buffers/docs/plutarch ❯ cabal run
388388
"Friends, peace and love!!!"
389389
```
390390

391-
Take a look at the [Example.hs](./plutarch/app/Example.hs) to see how generated types are used, namely how they are constructed with `pcon` and deconstructed with `pmatch` (or `pmatchC`).
391+
Take a look at the [Example.hs](https://github.com/mlabs-haskell/lambda-buffers/tree/main/docs/plutarch/app/Example.hs) to see how generated types are used, namely how they are constructed with `pcon` and deconstructed with `pmatch` (or `pmatchC`).

docs/plutarch/build.nix

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{ inputs, ... }:
22
{
3-
perSystem = { pkgs, config, ... }:
3+
perSystem = { config, ... }:
44
let
5-
project = { lib, ... }: {
5+
hsFlake = config.lbf-nix.haskellPlutusFlake {
66
src = ./.;
77

88
name = "plutarch-example";
99

1010
inherit (config.settings.haskell) index-state compiler-nix-name;
1111

12-
extraHackage = [
12+
dependencies = [
1313
# Load Plutarch support
1414
"${config.packages.lbf-prelude-plutarch}"
1515
"${config.packages.lbf-plutus-plutarch}"
@@ -22,49 +22,18 @@
2222
"${inputs.plutarch}/plutarch-extra"
2323
];
2424

25-
modules = [
26-
(_: {
27-
packages = {
28-
allComponent.doHoogle = true;
29-
allComponent.doHaddock = true;
30-
31-
# Enable strict compilation
32-
plutarch-example.configureFlags = [ "-f-dev" ];
33-
};
34-
})
35-
];
36-
37-
shell = {
38-
39-
withHoogle = true;
40-
41-
exactDeps = true;
42-
43-
nativeBuildInputs = config.settings.shell.tools ++ [ config.packages.lbf-plutus-to-plutarch ];
44-
45-
tools = {
46-
cabal = { };
47-
haskell-language-server = { };
48-
};
49-
50-
shellHook = lib.mkForce config.settings.shell.hook;
51-
};
25+
devShellTools = config.settings.shell.tools;
26+
devShellHook = config.settings.shell.hook;
5227
};
53-
hsNixFlake = (pkgs.haskell-nix.cabalProject' [
54-
inputs.mlabs-tooling.lib.mkHackageMod
55-
inputs.mlabs-tooling.lib.moduleMod
56-
project
57-
]).flake { };
58-
5928
in
6029

6130
{
62-
devShells.dev-plutarch-example = hsNixFlake.devShell;
31+
devShells.dev-plutarch-example = hsFlake.devShell;
6332

6433
packages = {
65-
plutarch-example-cli = hsNixFlake.packages."plutarch-example:exe:plutarch-example";
34+
plutarch-example-cli = hsFlake.packages."plutarch-example:exe:plutarch-example";
6635

67-
lbf-plutarch-example-api = config.overlayAttrs.lbf-nix.lbfPlutarch {
36+
lbf-plutarch-example-api = config.lbf-nix.lbfPlutarch {
6837
name = "lbf-plutarch-example-api";
6938
src = ./api;
7039
files = [ "Example.lbf" ];

docs/purescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ github:mlabs-haskell/lambda-buffers#lbf-prelude-to-purescript`.
1919

2020
In this chapter, we're going to use the latter option.
2121

22-
Let's now use `lbf-prelude-to-purescript` to process the [Document.lbf](examples/Document.lbf) schema
22+
Let's now use `lbf-prelude-to-purescript` to process the [Document.lbf](https://github.com/mlabs-haskell/lambda-buffers/blob/main/docs/examples/Document.lbf) schema
2323

2424
```purescript
2525
module Document

extras/build.nix

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1-
# TODO(bladyjoker): Using overlayAttrs here as a hack to share functions -.- Do this properly.
2-
{ inputs, ... }: {
3-
imports = [
4-
inputs.flake-parts.flakeModules.easyOverlay # Adds perSystem.overlayAttrs
5-
];
6-
perSystem = { pkgs, ... }:
7-
{
8-
9-
overlayAttrs = {
10-
extras = {
11-
purescriptFlake = import ./flake-purescript.nix pkgs;
12-
rustFlake = import ./flake-rust.nix pkgs;
13-
typescriptFlake = import ./flake-typescript.nix pkgs;
14-
haskellData = import ./haskell-data.nix pkgs;
1+
{ config, inputs, flake-parts-lib, lib, ... }: {
2+
3+
# Makes a system agnostic option (dunno why I needed this).
4+
options.lbf-nix = lib.mkOption {
5+
type = lib.types.anything; # probably not the best type
6+
default = { };
7+
};
8+
9+
# Makes it available in the system agnostic `lib` argument.
10+
config._module.args.lib = config.flake.lib // {
11+
inherit (config) lbf-nix;
12+
};
13+
14+
# Sets the above set option to system ones.
15+
config.lbf-nix = lib.genAttrs config.systems (system: (config.perSystem system).lbf-nix);
16+
17+
# Makes `lib.x86_64-linux.xyz` available
18+
config.flake.lib = config.lbf-nix;
19+
20+
options = {
21+
22+
# Makes a per system `lbf-nix` option.
23+
perSystem = flake-parts-lib.mkPerSystemOption
24+
({ pkgs, config, ... }: {
25+
26+
options.lbf-nix = lib.mkOption {
27+
type = lib.types.anything;
28+
default = { };
29+
};
30+
31+
# Sets a per system `lbf-nix` option.
32+
config = {
33+
lbf-nix = {
34+
# NOTE(bladyjoker): If you need to add a function the export externally and use internally via config.lbf-nix, add it here.
35+
purescriptFlake = import ./flake-purescript.nix pkgs;
36+
rustFlake = import ./flake-rust.nix pkgs;
37+
haskellData = import ./haskell-data.nix pkgs;
38+
haskellFlake = import ./flake-haskell.nix pkgs;
39+
haskellPlutusFlake = import ./flake-haskell-plutus.nix inputs.cardano-haskell-packages pkgs;
40+
typescriptFlake = import ./flake-typescript.nix pkgs;
41+
};
42+
43+
# Makes it available in the per system `lib` argument.
44+
_module.args.lib = lib // {
45+
inherit (config) lbf-nix;
46+
};
47+
1548
};
16-
};
1749

18-
};
50+
});
51+
52+
};
1953
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;;; lambda-buffers-mode.el --- SUMMARY -*- lexical-binding: t -*-
2+
3+
(require 'haskell-mode)
4+
5+
(define-derived-mode lambda-buffers-mode haskell-mode "lambda-buffers"
6+
"haskell-mode pretending to be lambda-buffers-mode"
7+
(haskell-indent-mode)
8+
(font-lock-add-keywords
9+
nil
10+
'(("\\<\\(record\\|sum\\|derive\\|opaque\\|prod\\)\\>" . 'font-lock-keyword-face)))
11+
(setq lsp-warn-no-matched-clients nil))
12+
13+
(add-to-list 'auto-mode-alist '("\\.lbf$" . lambda-buffers-mode))
14+
15+
(provide 'lambda-buffers-mode)
16+
;;; lambda-buffers-mode.el ends here

extras/flake-haskell-plutus.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Makes a Haskell Flake using haskell.nix with a simplified interface with support for Plutus development.
2+
cardano-haskell-packages: pkgs: opts:
3+
let
4+
plutusMod = (import ./haskell.nix/plutus.nix) opts.compiler-nix-name cardano-haskell-packages;
5+
opts' =
6+
if "modules" ? opts then opts // {
7+
modules = opts.modules ++ [ plutusMod ];
8+
}
9+
else opts // { modules = [ plutusMod ]; };
10+
in
11+
(import ./flake-haskell.nix pkgs) opts'

extras/flake-haskell.nix

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Makes a Haskell Flake using haskell.nix with a simplified interface.
2+
pkgs:
3+
let
4+
haskellNixOpts =
5+
{ src
6+
, name
7+
, dependencies ? [ ]
8+
, devShellTools ? [ ]
9+
, devShellHook
10+
, devShellAdditionalPackages ? _: [ ]
11+
, index-state
12+
, compiler-nix-name
13+
, modules ? [ ]
14+
}: {
15+
inherit src name dependencies devShellTools devShellHook index-state compiler-nix-name modules devShellAdditionalPackages;
16+
};
17+
18+
hsNixProj = opts: with (haskellNixOpts opts);
19+
let
20+
proj = { lib, ... }: {
21+
inherit src name index-state compiler-nix-name;
22+
extraHackage = dependencies;
23+
modules = [
24+
(_: {
25+
packages = {
26+
allComponent.doHoogle = true;
27+
allComponent.doHaddock = true;
28+
29+
# Enable strict compilation
30+
"${name}".configureFlags = [ "-f-dev" ];
31+
};
32+
})
33+
];
34+
35+
shell = {
36+
withHoogle = true;
37+
exactDeps = true;
38+
nativeBuildInputs = devShellTools;
39+
additional = devShellAdditionalPackages;
40+
41+
tools = {
42+
cabal = { };
43+
haskell-language-server = { };
44+
};
45+
46+
shellHook = lib.mkForce devShellHook;
47+
};
48+
49+
};
50+
in
51+
proj;
52+
53+
hsNixFlake = opts: with (haskellNixOpts opts);
54+
(pkgs.haskell-nix.cabalProject' ([
55+
((import ./haskell.nix/extra-hackage.nix) compiler-nix-name)
56+
(hsNixProj opts)
57+
]
58+
++ modules
59+
)
60+
).flake { };
61+
62+
in
63+
hsNixFlake

0 commit comments

Comments
 (0)