nandi/clonimpublic Fork
⑂ 2ee9b31
Commits
⬇ Clone ▾
git clone https://git.rickub.com/nandi/clonim.git
git clone ssh://git@rickub.com/nandi/clonim.git

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

Download ZIP

release: bundle Zig C toolchain

nandithebull committed 2026-09-20T23:29:00-07:00 Browse files
2ee9b31 parent: a146865
modified .github/workflows/release.yml +15 -12
@@ -67,13 +67,6 @@ jobs:
6767
6868 - name: Build optimized compiler
6969 run: |
70- mkdir -p lib
71- nim c --app:staticlib --nimMainPrefix:ClonimRuntime \
72- --hints:off --warnings:off --nimcache:lib/nimcache-debug \
73- -o:lib/libclonim_runtime_debug.a src/runtime_lib.nim
74- nim c -d:release --app:staticlib --nimMainPrefix:ClonimRuntime \
75- --hints:off --warnings:off --nimcache:lib/nimcache-release \
76- -o:lib/libclonim_runtime.a src/runtime_lib.nim
7770 nim c -d:release -d:releaseCompiler --hints:off --warnings:off \
7871 -o:bin/clonim src/clonim.nim
7972
@@ -81,13 +74,23 @@ jobs:
8174 run: |
8275 appdir=dist/clonim.AppDir
8376 install -Dm755 bin/clonim "$appdir/usr/bin/clonim"
84- install -Dm644 lib/libclonim_runtime.a \
85- "$appdir/usr/bin/libclonim_runtime.a"
8677 nim_bin=$(readlink -f "$(command -v nim)")
8778 nim_root=$(dirname "$(dirname "$nim_bin")")
8879 install -Dm755 "$nim_bin" "$appdir/usr/bin/nim"
8980 cp -a "$nim_root/lib/." "$appdir/usr/lib/"
9081 cp -a "$nim_root/config" "$appdir/usr/config"
82+ install -Dm755 packaging/appimage/gcc "$appdir/usr/bin/gcc"
83+ ln -s gcc "$appdir/usr/bin/cc"
84+
85+ curl --fail --location --silent --show-error \
86+ https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz \
87+ -o /tmp/zig-x86_64-linux-0.15.2.tar.xz
88+ echo "02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239 /tmp/zig-x86_64-linux-0.15.2.tar.xz" \
89+ | sha256sum --check
90+ mkdir -p "$appdir/usr/lib/zig"
91+ tar --extract --xz --file /tmp/zig-x86_64-linux-0.15.2.tar.xz \
92+ --strip-components=1 --directory "$appdir/usr/lib/zig"
93+
9194 install -Dm755 packaging/appimage/AppRun "$appdir/AppRun"
9295 install -Dm644 packaging/appimage/clonim.desktop \
9396 "$appdir/clonim.desktop"
@@ -121,9 +124,9 @@ jobs:
121124 Linux x86_64 release of clonim.
122125
123126 Download the AppImage, make it executable, and run it. It contains
124- the compiler, Nim 2.2.12, and clonim's private static runtime.
125- Generated programs statically link the runtime and are standalone.
126- A system C compiler and linker are required to build programs.
127+ clonim, Nim 2.2.12, Zig 0.15.2 as its C compiler/linker, and clonim's
128+ private static runtime. It has no external build dependencies, and
129+ generated programs statically link the clonim runtime.
127130 draft: false
128131 prerelease: false
129132 files: dist/clonim-linux-x86_64.AppImage
@@ -67,13 +67,6 @@ jobs:
67 67
68 - name: Build optimized compiler68 - name: Build optimized compiler
69 run: |69 run: |
70- mkdir -p lib
71- nim c --app:staticlib --nimMainPrefix:ClonimRuntime \
72- --hints:off --warnings:off --nimcache:lib/nimcache-debug \
73- -o:lib/libclonim_runtime_debug.a src/runtime_lib.nim
74- nim c -d:release --app:staticlib --nimMainPrefix:ClonimRuntime \
75- --hints:off --warnings:off --nimcache:lib/nimcache-release \
76- -o:lib/libclonim_runtime.a src/runtime_lib.nim
77 nim c -d:release -d:releaseCompiler --hints:off --warnings:off \70 nim c -d:release -d:releaseCompiler --hints:off --warnings:off \
78 -o:bin/clonim src/clonim.nim71 -o:bin/clonim src/clonim.nim
79 72
@@ -81,13 +74,23 @@ jobs:
81 run: |74 run: |
82 appdir=dist/clonim.AppDir75 appdir=dist/clonim.AppDir
83 install -Dm755 bin/clonim "$appdir/usr/bin/clonim"76 install -Dm755 bin/clonim "$appdir/usr/bin/clonim"
84- install -Dm644 lib/libclonim_runtime.a \
85- "$appdir/usr/bin/libclonim_runtime.a"
86 nim_bin=$(readlink -f "$(command -v nim)")77 nim_bin=$(readlink -f "$(command -v nim)")
87 nim_root=$(dirname "$(dirname "$nim_bin")")78 nim_root=$(dirname "$(dirname "$nim_bin")")
88 install -Dm755 "$nim_bin" "$appdir/usr/bin/nim"79 install -Dm755 "$nim_bin" "$appdir/usr/bin/nim"
89 cp -a "$nim_root/lib/." "$appdir/usr/lib/"80 cp -a "$nim_root/lib/." "$appdir/usr/lib/"
90 cp -a "$nim_root/config" "$appdir/usr/config"81 cp -a "$nim_root/config" "$appdir/usr/config"
82+ install -Dm755 packaging/appimage/gcc "$appdir/usr/bin/gcc"
83+ ln -s gcc "$appdir/usr/bin/cc"
84+
85+ curl --fail --location --silent --show-error \
86+ https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz \
87+ -o /tmp/zig-x86_64-linux-0.15.2.tar.xz
88+ echo "02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239 /tmp/zig-x86_64-linux-0.15.2.tar.xz" \
89+ | sha256sum --check
90+ mkdir -p "$appdir/usr/lib/zig"
91+ tar --extract --xz --file /tmp/zig-x86_64-linux-0.15.2.tar.xz \
92+ --strip-components=1 --directory "$appdir/usr/lib/zig"
93+
91 install -Dm755 packaging/appimage/AppRun "$appdir/AppRun"94 install -Dm755 packaging/appimage/AppRun "$appdir/AppRun"
92 install -Dm644 packaging/appimage/clonim.desktop \95 install -Dm644 packaging/appimage/clonim.desktop \
93 "$appdir/clonim.desktop"96 "$appdir/clonim.desktop"
@@ -121,9 +124,9 @@ jobs:
121 Linux x86_64 release of clonim.124 Linux x86_64 release of clonim.
122 125
123 Download the AppImage, make it executable, and run it. It contains126 Download the AppImage, make it executable, and run it. It contains
124- the compiler, Nim 2.2.12, and clonim's private static runtime.127+ clonim, Nim 2.2.12, Zig 0.15.2 as its C compiler/linker, and clonim's
125- Generated programs statically link the runtime and are standalone.128+ private static runtime. It has no external build dependencies, and
126- A system C compiler and linker are required to build programs.129+ generated programs statically link the clonim runtime.
127 draft: false130 draft: false
128 prerelease: false131 prerelease: false
129 files: dist/clonim-linux-x86_64.AppImage132 files: dist/clonim-linux-x86_64.AppImage
modified README.md +3 -3
@@ -25,9 +25,9 @@ see [benchmark history](bench/README.md) for metrics and exit codes.
2525
2626 `just release` builds the compiler and its private static runtime. Version tags
2727 matching `v*` trigger the release workflow, which packages both into a single
28-Linux x86_64 AppImage together with Nim 2.2.12. Generated programs statically
29-link the runtime and are standalone. The build machine needs a system C
30-compiler and linker, but does not need Nim installed separately.
28+Linux x86_64 AppImage together with Nim 2.2.12 and Zig 0.15.2 as the private C
29+compiler/linker. The AppImage has no external build dependencies. Generated
30+programs statically link the clonim runtime and are standalone.
3131
3232 Source-level libraries are loaded explicitly. Use
3333 `(require '[clonim.core :refer [now-ms]])` to load `stdlib/clonim/core.clj`. Host-dependent operations remain small runtime primitives; for
@@ -25,9 +25,9 @@ see [benchmark history](bench/README.md) for metrics and exit codes.
25 25
26 `just release` builds the compiler and its private static runtime. Version tags26 `just release` builds the compiler and its private static runtime. Version tags
27 matching `v*` trigger the release workflow, which packages both into a single27 matching `v*` trigger the release workflow, which packages both into a single
28-Linux x86_64 AppImage together with Nim 2.2.12. Generated programs statically28+Linux x86_64 AppImage together with Nim 2.2.12 and Zig 0.15.2 as the private C
29-link the runtime and are standalone. The build machine needs a system C29+compiler/linker. The AppImage has no external build dependencies. Generated
30-compiler and linker, but does not need Nim installed separately.30+programs statically link the clonim runtime and are standalone.
31 31
32 Source-level libraries are loaded explicitly. Use32 Source-level libraries are loaded explicitly. Use
33 `(require '[clonim.core :refer [now-ms]])` to load `stdlib/clonim/core.clj`. Host-dependent operations remain small runtime primitives; for33 `(require '[clonim.core :refer [now-ms]])` to load `stdlib/clonim/core.clj`. Host-dependent operations remain small runtime primitives; for
added packaging/appimage/gcc +11 -0
new file mode 100755
@@ -0,0 +1,11 @@
1+#!/bin/sh
2+set -eu
3+
4+zig_root=$(CDPATH= cd -- "$(dirname -- "$0")/../lib/zig" && pwd)
5+cache_root=${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}
6+ZIG_GLOBAL_CACHE_DIR="$cache_root/clonim-zig/global"
7+ZIG_LOCAL_CACHE_DIR="$cache_root/clonim-zig/local"
8+export ZIG_GLOBAL_CACHE_DIR ZIG_LOCAL_CACHE_DIR
9+mkdir -p "$ZIG_GLOBAL_CACHE_DIR" "$ZIG_LOCAL_CACHE_DIR"
10+
11+exec "$zig_root/zig" cc -target x86_64-linux-gnu "$@"
new file mode 100755
@@ -0,0 +1,11 @@
1+#!/bin/sh
2+set -eu
3+
4+zig_root=$(CDPATH= cd -- "$(dirname -- "$0")/../lib/zig" && pwd)
5+cache_root=${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}
6+ZIG_GLOBAL_CACHE_DIR="$cache_root/clonim-zig/global"
7+ZIG_LOCAL_CACHE_DIR="$cache_root/clonim-zig/local"
8+export ZIG_GLOBAL_CACHE_DIR ZIG_LOCAL_CACHE_DIR
9+mkdir -p "$ZIG_GLOBAL_CACHE_DIR" "$ZIG_LOCAL_CACHE_DIR"
10+
11+exec "$zig_root/zig" cc -target x86_64-linux-gnu "$@"
added src/app_runtime_source.nim +7 -0
new file mode 100644
@@ -0,0 +1,7 @@
1+## Private source interface used by the self-contained release compiler.
2+## Nim compiles these modules together with the generated program, avoiding a
3+## second copy of Nim's support runtime while keeping the result standalone.
4+import runtime, core, namespaces
5+export runtime, core, namespaces
6+
7+proc initClonimRuntime*() = discard
new file mode 100644
@@ -0,0 +1,7 @@
1+## Private source interface used by the self-contained release compiler.
2+## Nim compiles these modules together with the generated program, avoiding a
3+## second copy of Nim's support runtime while keeping the result standalone.
4+import runtime, core, namespaces
5+export runtime, core, namespaces
6+
7+proc initClonimRuntime*() = discard
modified src/clonim.nim +25 -14
@@ -8,8 +8,12 @@ import runtime, compiler
88
99 when defined(releaseCompiler):
1010 const
11- EmbeddedAppRuntime = staticRead("app_runtime.nim")
11+ EmbeddedAppRuntime = staticRead("app_runtime_source.nim")
1212 EmbeddedRuntimeTypes = staticRead("runtime_types.nim")
13+ EmbeddedRuntime = staticRead("runtime.nim")
14+ EmbeddedCore = staticRead("core.nim")
15+ EmbeddedNamespaces = staticRead("namespaces.nim")
16+ EmbeddedReader = staticRead("reader.nim")
1317 EmbeddedCoreStdlib = staticRead("../stdlib/clonim/core.clj")
1418
1519 proc embeddedRoot(): string =
@@ -17,16 +21,24 @@ when defined(releaseCompiler):
1721 ## runtime implementation remains the separately shipped static archive.
1822 var h: Hash = hash(EmbeddedAppRuntime)
1923 h = h !& hash(EmbeddedRuntimeTypes)
24+ h = h !& hash(EmbeddedRuntime)
25+ h = h !& hash(EmbeddedCore)
26+ h = h !& hash(EmbeddedNamespaces)
27+ h = h !& hash(EmbeddedReader)
2028 h = h !& hash(EmbeddedCoreStdlib)
2129 result = getTempDir() / "clonim-runtime" / $(!$h)
2230 let files = [
2331 (result / "src" / "app_runtime.nim", EmbeddedAppRuntime),
2432 (result / "src" / "runtime_types.nim", EmbeddedRuntimeTypes),
33+ (result / "src" / "runtime.nim", EmbeddedRuntime),
34+ (result / "src" / "core.nim", EmbeddedCore),
35+ (result / "src" / "namespaces.nim", EmbeddedNamespaces),
36+ (result / "src" / "reader.nim", EmbeddedReader),
2537 (result / "stdlib" / "clonim" / "core.clj", EmbeddedCoreStdlib),
2638 ]
2739 for (path, contents) in files:
2840 createDir(path.parentDir)
29- if not fileExists(path) or getFileSize(path) != contents.len:
41+ if not fileExists(path) or readFile(path) != contents:
3042 writeFile(path, contents)
3143
3244 proc usage() =
@@ -56,11 +68,6 @@ proc srcDir(): string =
5668 proc runtimeLib(release: bool): string =
5769 ## Release archives place the private runtime beside bin/. A source checkout
5870 ## builds the same archive into lib/ on first use.
59- when defined(releaseCompiler):
60- let shipped = getAppDir() / "libclonim_runtime.a"
61- if fileExists(shipped): return shipped
62- raise newException(IOError,
63- "missing runtime library beside compiler: " & shipped)
6471 let libName = (if release: "libclonim_runtime.a" else: "libclonim_runtime_debug.a")
6572 let installed = getAppDir().parentDir / "lib" / libName
6673 let source = srcDir() / "runtime_lib.nim"
@@ -98,7 +105,8 @@ proc buildKey(nimSrc: string, release: bool, rtLib: string): string =
98105 let nimExe = findExe("nim")
99106 if nimExe.len > 0:
100107 h = h !& hash($getLastModificationTime(nimExe))
101- h = h !& hash($getLastModificationTime(rtLib))
108+ if rtLib.len > 0:
109+ h = h !& hash($getLastModificationTime(rtLib))
102110 $(!$h)
103111
104112 proc main() =
@@ -179,18 +187,21 @@ proc main() =
179187 # and the Nim compiler itself.
180188 let stamp = work / "stamp"
181189 var rtLib = ""
182- try:
183- rtLib = runtimeLib(release)
184- except IOError, OSError:
185- stderr.writeLine("clonim: " & getCurrentExceptionMsg())
186- quit(1)
190+ when not defined(releaseCompiler):
191+ try:
192+ rtLib = runtimeLib(release)
193+ except IOError, OSError:
194+ stderr.writeLine("clonim: " & getCurrentExceptionMsg())
195+ quit(1)
187196 let cached = cmd == "run" and fileExists(outBin) and fileExists(stamp) and
188197 readFile(stamp) == buildKey(nimSrc, release, rtLib)
189198
190199 var nimCmd = @["nim", "c", "--hints:off", "--warnings:off",
191200 "--path:" & srcDir(), "--nimcache:" & (work / "cache"),
192- "--passL:-Wl,--allow-multiple-definition", "--passL:" & rtLib,
193201 "--passL:-lm", "-o:" & outBin]
202+ when not defined(releaseCompiler):
203+ nimCmd.add "--passL:-Wl,--allow-multiple-definition"
204+ nimCmd.add "--passL:" & rtLib
194205 if release: nimCmd.add "-d:release"
195206 nimCmd.add nimFile
196207 if verbose and not cached: echo "clonim: " & nimCmd.join(" ")
@@ -8,8 +8,12 @@ import runtime, compiler
8 8
9 when defined(releaseCompiler):9 when defined(releaseCompiler):
10 const10 const
11- EmbeddedAppRuntime = staticRead("app_runtime.nim")11+ EmbeddedAppRuntime = staticRead("app_runtime_source.nim")
12 EmbeddedRuntimeTypes = staticRead("runtime_types.nim")12 EmbeddedRuntimeTypes = staticRead("runtime_types.nim")
13+ EmbeddedRuntime = staticRead("runtime.nim")
14+ EmbeddedCore = staticRead("core.nim")
15+ EmbeddedNamespaces = staticRead("namespaces.nim")
16+ EmbeddedReader = staticRead("reader.nim")
13 EmbeddedCoreStdlib = staticRead("../stdlib/clonim/core.clj")17 EmbeddedCoreStdlib = staticRead("../stdlib/clonim/core.clj")
14 18
15 proc embeddedRoot(): string =19 proc embeddedRoot(): string =
@@ -17,16 +21,24 @@ when defined(releaseCompiler):
17 ## runtime implementation remains the separately shipped static archive.21 ## runtime implementation remains the separately shipped static archive.
18 var h: Hash = hash(EmbeddedAppRuntime)22 var h: Hash = hash(EmbeddedAppRuntime)
19 h = h !& hash(EmbeddedRuntimeTypes)23 h = h !& hash(EmbeddedRuntimeTypes)
24+ h = h !& hash(EmbeddedRuntime)
25+ h = h !& hash(EmbeddedCore)
26+ h = h !& hash(EmbeddedNamespaces)
27+ h = h !& hash(EmbeddedReader)
20 h = h !& hash(EmbeddedCoreStdlib)28 h = h !& hash(EmbeddedCoreStdlib)
21 result = getTempDir() / "clonim-runtime" / $(!$h)29 result = getTempDir() / "clonim-runtime" / $(!$h)
22 let files = [30 let files = [
23 (result / "src" / "app_runtime.nim", EmbeddedAppRuntime),31 (result / "src" / "app_runtime.nim", EmbeddedAppRuntime),
24 (result / "src" / "runtime_types.nim", EmbeddedRuntimeTypes),32 (result / "src" / "runtime_types.nim", EmbeddedRuntimeTypes),
33+ (result / "src" / "runtime.nim", EmbeddedRuntime),
34+ (result / "src" / "core.nim", EmbeddedCore),
35+ (result / "src" / "namespaces.nim", EmbeddedNamespaces),
36+ (result / "src" / "reader.nim", EmbeddedReader),
25 (result / "stdlib" / "clonim" / "core.clj", EmbeddedCoreStdlib),37 (result / "stdlib" / "clonim" / "core.clj", EmbeddedCoreStdlib),
26 ]38 ]
27 for (path, contents) in files:39 for (path, contents) in files:
28 createDir(path.parentDir)40 createDir(path.parentDir)
29- if not fileExists(path) or getFileSize(path) != contents.len:41+ if not fileExists(path) or readFile(path) != contents:
30 writeFile(path, contents)42 writeFile(path, contents)
31 43
32 proc usage() =44 proc usage() =
@@ -56,11 +68,6 @@ proc srcDir(): string =
56 proc runtimeLib(release: bool): string =68 proc runtimeLib(release: bool): string =
57 ## Release archives place the private runtime beside bin/. A source checkout69 ## Release archives place the private runtime beside bin/. A source checkout
58 ## builds the same archive into lib/ on first use.70 ## builds the same archive into lib/ on first use.
59- when defined(releaseCompiler):
60- let shipped = getAppDir() / "libclonim_runtime.a"
61- if fileExists(shipped): return shipped
62- raise newException(IOError,
63- "missing runtime library beside compiler: " & shipped)
64 let libName = (if release: "libclonim_runtime.a" else: "libclonim_runtime_debug.a")71 let libName = (if release: "libclonim_runtime.a" else: "libclonim_runtime_debug.a")
65 let installed = getAppDir().parentDir / "lib" / libName72 let installed = getAppDir().parentDir / "lib" / libName
66 let source = srcDir() / "runtime_lib.nim"73 let source = srcDir() / "runtime_lib.nim"
@@ -98,7 +105,8 @@ proc buildKey(nimSrc: string, release: bool, rtLib: string): string =
98 let nimExe = findExe("nim")105 let nimExe = findExe("nim")
99 if nimExe.len > 0:106 if nimExe.len > 0:
100 h = h !& hash($getLastModificationTime(nimExe))107 h = h !& hash($getLastModificationTime(nimExe))
101- h = h !& hash($getLastModificationTime(rtLib))108+ if rtLib.len > 0:
109+ h = h !& hash($getLastModificationTime(rtLib))
102 $(!$h)110 $(!$h)
103 111
104 proc main() =112 proc main() =
@@ -179,18 +187,21 @@ proc main() =
179 # and the Nim compiler itself.187 # and the Nim compiler itself.
180 let stamp = work / "stamp"188 let stamp = work / "stamp"
181 var rtLib = ""189 var rtLib = ""
182- try:190+ when not defined(releaseCompiler):
183- rtLib = runtimeLib(release)191+ try:
184- except IOError, OSError:192+ rtLib = runtimeLib(release)
185- stderr.writeLine("clonim: " & getCurrentExceptionMsg())193+ except IOError, OSError:
186- quit(1)194+ stderr.writeLine("clonim: " & getCurrentExceptionMsg())
195+ quit(1)
187 let cached = cmd == "run" and fileExists(outBin) and fileExists(stamp) and196 let cached = cmd == "run" and fileExists(outBin) and fileExists(stamp) and
188 readFile(stamp) == buildKey(nimSrc, release, rtLib)197 readFile(stamp) == buildKey(nimSrc, release, rtLib)
189 198
190 var nimCmd = @["nim", "c", "--hints:off", "--warnings:off",199 var nimCmd = @["nim", "c", "--hints:off", "--warnings:off",
191 "--path:" & srcDir(), "--nimcache:" & (work / "cache"),200 "--path:" & srcDir(), "--nimcache:" & (work / "cache"),
192- "--passL:-Wl,--allow-multiple-definition", "--passL:" & rtLib,
193 "--passL:-lm", "-o:" & outBin]201 "--passL:-lm", "-o:" & outBin]
202+ when not defined(releaseCompiler):
203+ nimCmd.add "--passL:-Wl,--allow-multiple-definition"
204+ nimCmd.add "--passL:" & rtLib
194 if release: nimCmd.add "-d:release"205 if release: nimCmd.add "-d:release"
195 nimCmd.add nimFile206 nimCmd.add nimFile
196 if verbose and not cached: echo "clonim: " & nimCmd.join(" ")207 if verbose and not cached: echo "clonim: " & nimCmd.join(" ")