nandi/libjavapublic Fork 0
5ccc9c1
Commits
Clone
git clone https://git.rickub.com/nandi/libjava.git
git clone ssh://git@rickub.com/nandi/libjava.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add a justfile wrapping the nimble tasks

`just test`, `just demo` and `just java` defer to nimble, which stays the
source of truth. The additions are `check`, `docs`, `clean`, and `jdk`
(prints the JDK that will be linked).

`check` resolves the JDK home in the shell and passes `-d:javaHome`:
`nim check` does not run `staticExec`, so config.nim's PATH-based fallback
is unavailable under it and discovery would otherwise fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nandithebull committed 2026-09-20T14:20:25-07:00 Browse files
5ccc9c1 parent: 963f309
modified README.md +4 -0
@@ -25,6 +25,10 @@ nimble test
2525 nimble demo
2626 ```
2727
28+There is also a `justfile` wrapping these, plus `just check`, `just docs`,
29+`just clean` and `just jdk` (prints the JDK that will be linked). `just -l`
30+lists them; the nimble tasks stay the source of truth.
31+
2832 Pass `-d:libjavaNoLink` if your process already has the JVM symbols — when
2933 this code is itself a shared library loaded *by* a JVM.
3034
@@ -25,6 +25,10 @@ nimble test
25 nimble demo25 nimble demo
26 ```26 ```
27 27
28+There is also a `justfile` wrapping these, plus `just check`, `just docs`,
29+`just clean` and `just jdk` (prints the JDK that will be linked). `just -l`
30+lists them; the nimble tasks stay the source of truth.
31+
28 Pass `-d:libjavaNoLink` if your process already has the JVM symbols — when32 Pass `-d:libjavaNoLink` if your process already has the JVM symbols — when
29 this code is itself a shared library loaded *by* a JVM.33 this code is itself a shared library loaded *by* a JVM.
30 34
added justfile +45 -0
new file mode 100644
@@ -0,0 +1,45 @@
1+# libjava — embed a JVM in a Nim process and call Java from it, via JNI
2+#
3+# The nimble tasks remain the source of truth; these recipes are thin wrappers
4+# so the common loop is one word. `just -l` lists everything.
5+
6+default: test
7+
8+# Compile the example Java classes into build/classes
9+java:
10+ nimble java
11+
12+# Run the test suite (compiles the Java fixtures first)
13+test:
14+ nimble test
15+
16+# Run the example program
17+demo:
18+ nimble demo
19+
20+# Type-check the library without producing a binary.
21+# `nim check` does not run `staticExec`, so config.nim's PATH-based JDK
22+# fallback is unavailable there — resolve the home here and pass it in.
23+check:
24+ #!/usr/bin/env bash
25+ set -euo pipefail
26+ home="${JAVA_HOME:-$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")}"
27+ nim check --path:src -d:javaHome="$home" src/libjava.nim
28+
29+# Build the library's documentation into build/docs
30+docs:
31+ nim doc --project --index:on --outdir:build/docs --path:src src/libjava.nim
32+
33+# Remove build outputs and compiled test/example binaries
34+clean:
35+ rm -rf build nimcache
36+ rm -f tests/tlibjava examples/demo
37+
38+# Print the JDK this build will link against
39+jdk:
40+ #!/usr/bin/env bash
41+ set -euo pipefail
42+ d=$(mktemp -d)
43+ trap 'rm -rf "$d"' EXIT
44+ printf 'import libjava/config\necho javaHome\n' > "$d/jdk.nim"
45+ nim c -r --path:src --hints:off -d:libjavaNoLink --nimcache:"$d/cache" -o:"$d/jdk" "$d/jdk.nim"
new file mode 100644
@@ -0,0 +1,45 @@
1+# libjava — embed a JVM in a Nim process and call Java from it, via JNI
2+#
3+# The nimble tasks remain the source of truth; these recipes are thin wrappers
4+# so the common loop is one word. `just -l` lists everything.
5+
6+default: test
7+
8+# Compile the example Java classes into build/classes
9+java:
10+ nimble java
11+
12+# Run the test suite (compiles the Java fixtures first)
13+test:
14+ nimble test
15+
16+# Run the example program
17+demo:
18+ nimble demo
19+
20+# Type-check the library without producing a binary.
21+# `nim check` does not run `staticExec`, so config.nim's PATH-based JDK
22+# fallback is unavailable there — resolve the home here and pass it in.
23+check:
24+ #!/usr/bin/env bash
25+ set -euo pipefail
26+ home="${JAVA_HOME:-$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")}"
27+ nim check --path:src -d:javaHome="$home" src/libjava.nim
28+
29+# Build the library's documentation into build/docs
30+docs:
31+ nim doc --project --index:on --outdir:build/docs --path:src src/libjava.nim
32+
33+# Remove build outputs and compiled test/example binaries
34+clean:
35+ rm -rf build nimcache
36+ rm -f tests/tlibjava examples/demo
37+
38+# Print the JDK this build will link against
39+jdk:
40+ #!/usr/bin/env bash
41+ set -euo pipefail
42+ d=$(mktemp -d)
43+ trap 'rm -rf "$d"' EXIT
44+ printf 'import libjava/config\necho javaHome\n' > "$d/jdk.nim"
45+ nim c -r --path:src --hints:off -d:libjavaNoLink --nimcache:"$d/cache" -o:"$d/jdk" "$d/jdk.nim"