Skip to content
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

docs: Add FFI template #7

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions templates/ffi/FFI.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This module serves as the root of the `FFI` library.
-- Import modules here that should be built as part of the library.
import FFI.Basic
5 changes: 5 additions & 0 deletions templates/ffi/FFI/Basic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Blake3

abbrev input : ByteArray := ⟨#[0]⟩

def myHash := (Blake3.hash input).val.data
5 changes: 5 additions & 0 deletions templates/ffi/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import FFI

def main : IO Unit :=
IO.println s!"Hash of [0]: {myHash}"

233 changes: 233 additions & 0 deletions templates/ffi/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions templates/ffi/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
description = "Lean 4 Example Project";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
lean4-nix = {
url = "github:argumentcomputer/lean4-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
blake3-lean = {
url = "github:argumentcomputer/Blake3.lean?rev=29018d578b043f6638907f3425af839eec345361";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {
nixpkgs,
flake-parts,
lean4-nix,
blake3-lean,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];

perSystem = {
system,
pkgs,
...
}:
let
blake3 = blake3-lean.inputs.blake3;
blake3Mod = (blake3-lean.lib { inherit pkgs lean4-nix blake3; }).lib;
blake3Lib = blake3Mod.blake3-lib;
blake3C = blake3Mod.blake3-c;
in
{
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [(lean4-nix.readToolchainFile ./lean-toolchain)];
};

packages.default = (pkgs.lean.buildLeanPackage {
name = "ffi";
src = ./.;
roots = ["FFI" "Main"];
deps = [ blake3Lib ];
staticLibDeps = [ blake3C ];
linkFlags = [ "-L${blake3C}/lib" "-lblake3" ];
}).executable;

devShells.default = pkgs.mkShell {
packages = with pkgs.lean; [lean lean-all];
};
};
};
}
15 changes: 15 additions & 0 deletions templates/ffi/lake-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{"version": "1.1.0",
"packagesDir": ".lake/packages",
"packages":
[{"url": "https://github.com/argumentcomputer/Blake3.lean",
"type": "git",
"subDir": null,
"scope": "",
"rev": "29018d578b043f6638907f3425af839eec345361",
"name": "Blake3",
"manifestFile": "lake-manifest.json",
"inputRev": "29018d578b043f6638907f3425af839eec345361",
"inherited": false,
"configFile": "lakefile.lean"}],
"name": "ffi",
"lakeDir": ".lake"}
15 changes: 15 additions & 0 deletions templates/ffi/lakefile.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Lake
open Lake DSL

require Blake3 from git
"https://github.com/argumentcomputer/Blake3.lean" @ "29018d578b043f6638907f3425af839eec345361"

package "ffi" where
version := v!"0.1.0"

lean_lib «FFI» where
-- add library configuration options here

@[default_target]
lean_exe "ffi" where
root := `Main
1 change: 1 addition & 0 deletions templates/ffi/lean-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leanprover/lean4:v4.17.0