Skip to content

Commit 73d78a3

Browse files
committed
chore: using flake and upgrade lean4
1 parent 75d0dab commit 73d78a3

File tree

9 files changed

+85
-19
lines changed

9 files changed

+85
-19
lines changed

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use nix
1+
use flake

Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ def main : IO Unit := do
5858
match ← conn.prepare "select * from users;" with
5959
| Except.error e => println e
6060
| Except.ok c =>
61-
printUser count.toNat c
61+
printUser count.toNatClampNeg c
6262
| Except.error e => println s!"error: {e}"
6363
println s!"Hello, {conn}"

Sqlite/FFI.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ structure Cursor where
6666
cursor : RawCursor
6767
step : IO Bool
6868
bindText : UInt32 → String → IO Unit
69-
bindInt : UInt32 → Int → IO Unit
69+
bindInt : UInt32 → Int32 → IO Unit
7070
reset : IO Unit
7171
columnsCount : IO UInt32
7272
columnText : UInt32 → IO String
73-
columnInt : UInt32 → IO Int
73+
columnInt : UInt32 → IO Int32
7474
cursorExplain : UInt32 → IO Int
7575

7676
structure Connection where
@@ -83,6 +83,7 @@ instance : ToString Connection where
8383

8484
@[extern "lean_sqlite_initialize"]
8585
private opaque sqliteInit : IO Unit
86+
8687
builtin_initialize sqliteInit
8788

8889
@[extern "lean_sqlite_open"]

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
4+
flake-utils.url = "github:numtide/flake-utils";
5+
};
6+
7+
outputs = { self, nixpkgs, flake-utils }:
8+
flake-utils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" "i686-linux" ] (system:
9+
let pkgs = import nixpkgs { inherit system; };
10+
in {
11+
defaultPackage = pkgs.mkShell {
12+
buildInputs = with pkgs; [ sqlite lean4 ];
13+
};
14+
}
15+
);
16+
}

lakefile.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ target sqliteffi.o pkg : FilePath := do
1717
let oFile := pkg.buildDir / "native" / "sqliteffi.o"
1818
let srcJob ← inputTextFile <| pkg.dir / "native" / "ffi.c"
1919
let weakArgs := #["-I", (← getLeanIncludeDir).toString, "-I/nix/store/8r55amvr43sm771rgm0sszd05rm8j1cr-sqlite-3.46.0-dev/include/"]
20-
buildO oFile srcJob weakArgs #["-fPIC"] "clang" getLeanTrace
20+
buildO oFile srcJob weakArgs #["-fPIC"] "gcc" getLeanTrace
2121

2222
extern_lib libsqliteffi pkg := do
2323
let ffiO ← sqliteffi.o.fetch
2424
let name := nameToStaticLib "sqliteffi"
25-
buildStaticLib (pkg.nativeLibDir / name) #[ffiO]
25+
buildStaticLib (pkg.staticLibDir / name) #[ffiO]
2626

2727
require LSpec from git
2828
"https://github.com/argumentcomputer/lspec/" @ "8a51034d049c6a229d88dd62f490778a377eec06"

lean-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
leanprover/lean4:4.10.0
1+
leanprover/lean4:4.20.0

native/ffi.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ sqlite3_stmt* unbox_cursor(lean_object* o) {
2626
void connection_finalize(void* conn) {
2727
if (!conn) return;
2828

29-
printf("connection_finalize: %x\n", conn);
30-
3129
sqlite3_close(conn);
3230
}
3331

3432
void cursor_finalize(void* cursor) {
3533
if (!cursor) return;
3634

37-
printf("cursor_finalize: %x\n", cursor);
38-
3935
sqlite3_finalize(cursor);
4036
}
4137

@@ -49,8 +45,6 @@ lean_obj_res lean_sqlite_open(b_lean_obj_arg path, uint32_t flags) {
4945
const char* path_str = lean_string_cstr(path);
5046
sqlite3* conn = malloc(sizeof(sqlite3*));
5147

52-
printf("initialize_connection: %x\n", conn);
53-
5448
int32_t c = sqlite3_open_v2(path_str, &conn, flags, NULL);
5549

5650
if (c == SQLITE_OK)
@@ -69,8 +63,6 @@ lean_obj_res lean_sqlite_prepare(b_lean_obj_arg conn_box, b_lean_obj_arg query_s
6963

7064
sqlite3_stmt* cursor = malloc(sizeof(sqlite3_stmt*));
7165

72-
printf("initialize_cursor: %x\n", cursor);
73-
7466
int32_t c = sqlite3_prepare_v2(conn, query, -1, &cursor, NULL);
7567

7668
if (c != SQLITE_OK) {

shell.nix

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

0 commit comments

Comments
 (0)