justfile (5214B)
1 # Standard recipes: build, release, clean, test, install, plus check and example. 2 # 3 # just build debug odin-run -> build/debug/odin-run 4 # just release optimised odin-run -> build/release/odin-run 5 # just test run every package's tests 6 # just check type-check every package for linux, darwin and windows 7 # just sqlite compile the vendored SQLite amalgamation into sqlite3/lib 8 # just fuzz run the jm:sqlite3 property fuzzer for thirty seconds 9 # just install release odin-run into ~/.local/bin with this checkout baked in 10 # just example compile and run examples/hello.odin through the collection 11 # just clean remove build/ 12 13 odin := env("ODIN", "odin") 14 root := justfile_directory() 15 flags := "-vet -strict-style -collection:jm=" + root 16 exe := if os() == "windows" { ".exe" } else { "" } 17 bindir := env("BINDIR", home_directory() / ".local" / "bin") 18 packages := "prelude sh http path timefmt debug flow tar sqlite3 sqlite3/fuzz" 19 cc := env("CC", "cc") 20 sqlite_lib := if os() == "windows" { "sqlite3/lib/sqlite3.lib" } else { "sqlite3/lib/sqlite3.a" } 21 22 # SQLite compile-time options. sqlite.org's recommended set for 3.53.4, with 23 # three deliberate changes: THREADSAFE=1 rather than 0, so a connection per 24 # jm:flow worker is safe; OMIT_AUTOINIT left off, because omitting it makes 25 # any call before sqlite3_initialize a segfault; and FTS5 compiled in for a 26 # full-text index. OMIT_LOAD_EXTENSION keeps the build from needing libdl. 27 sqlite_defines := "-DSQLITE_DQS=0 -DSQLITE_THREADSAFE=1 -DSQLITE_DEFAULT_MEMSTATUS=0 " + \ 28 "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS " + \ 29 "-DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED " + \ 30 "-DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_STRICT_SUBTYPE=1 " + \ 31 "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS" 32 targets := "linux_amd64 darwin_arm64 windows_amd64" 33 34 # `just` alone lists the recipes. 35 default: 36 @just --list --unsorted 37 38 # Debug odin-run -> build/debug/odin-run 39 build: 40 mkdir -p build/debug 41 {{odin}} build tools/odin-run -debug {{flags}} -define:JM_COLLECTION={{root}} -out:build/debug/odin-run{{exe}} 42 43 # Optimised odin-run -> build/release/odin-run 44 release: 45 mkdir -p build/release 46 {{odin}} build tools/odin-run -o:speed {{flags}} -define:JM_COLLECTION={{root}} -out:build/release/odin-run{{exe}} 47 48 # The archive lands in sqlite3/lib rather than build/ because foreign import 49 # resolves relative to the package directory. `just check` never needs it: 50 # odin check does not open a foreign import, which is how one machine 51 # type-checks all three targets without building for any of them. 52 53 # Compile the vendored SQLite amalgamation into sqlite3/lib if it is stale 54 [unix] 55 sqlite: 56 @mkdir -p sqlite3/lib 57 @if [ ! -f {{sqlite_lib}} ] || [ sqlite3/vendor/sqlite3.c -nt {{sqlite_lib}} ]; then \ 58 echo "{{cc}} sqlite3 amalgamation -> {{sqlite_lib}}"; \ 59 {{cc}} -O2 -fPIC -c sqlite3/vendor/sqlite3.c -o sqlite3/lib/sqlite3.o {{sqlite_defines}}; \ 60 ar rcs {{sqlite_lib}} sqlite3/lib/sqlite3.o; \ 61 fi 62 63 [windows] 64 sqlite: 65 @if (!(Test-Path {{sqlite_lib}}) -or (Get-Item sqlite3/vendor/sqlite3.c).LastWriteTime -gt (Get-Item {{sqlite_lib}}).LastWriteTime) { \ 66 cl /nologo /O2 /c sqlite3/vendor/sqlite3.c /Fosqlite3/lib/sqlite3.obj {{sqlite_defines}}; \ 67 lib /nologo /OUT:{{sqlite_lib}} sqlite3/lib/sqlite3.obj \ 68 } 69 70 # Run every package's tests 71 test: sqlite 72 mkdir -p build/test 73 for p in {{packages}}; do \ 74 {{odin}} test $p {{flags}} -out:build/test/$(echo $p | tr / -){{exe}} || exit 1; \ 75 done 76 77 # Type-check every package and the runner for each target 78 check: 79 for t in {{targets}}; do \ 80 for p in {{packages}}; do {{odin}} check $p {{flags}} -no-entry-point -target:$t || exit 1; done; \ 81 {{odin}} check tools/odin-run {{flags}} -target:$t || exit 1; \ 82 {{odin}} check tools/sqlite3-fuzz {{flags}} -target:$t || exit 1; \ 83 {{odin}} check examples/hello.odin -file {{flags}} -target:$t || exit 1; \ 84 done 85 86 # Install odin-run into ~/.local/bin (override with BINDIR) 87 install: release 88 mkdir -p {{bindir}} 89 cp build/release/odin-run{{exe}} {{bindir}}/odin-run{{exe}} 90 91 # `just fuzz` runs the default bound; `just fuzz "-for=5m"` or 92 # `just fuzz "-seed=12345"` passes arguments straight through. 93 94 # Throw generated values and damaged SQL at jm:sqlite3 until something gives 95 fuzz args="-for=30s": sqlite 96 mkdir -p build/debug 97 {{odin}} build tools/sqlite3-fuzz -debug {{flags}} -out:build/debug/sqlite3-fuzz{{exe}} 98 build/debug/sqlite3-fuzz{{exe}} {{args}} 99 100 # The same, with the FFI boundary under AddressSanitizer 101 [unix] 102 fuzz-asan args="-for=30s": sqlite 103 mkdir -p build/debug 104 {{odin}} build tools/sqlite3-fuzz -debug -sanitize:address {{flags}} -out:build/debug/sqlite3-fuzz-asan 105 build/debug/sqlite3-fuzz-asan {{args}} 106 107 # Compile and run the example script 108 example: build sqlite 109 ODIN_RUN_VERBOSE=1 build/debug/odin-run{{exe}} examples/hello.odin 110 111 # Remove build/ and the compiled SQLite archive 112 clean: 113 rm -rf build sqlite3/lib