I was doing some looping recently with tcl and comparing against another implementation (called Jim [1], a very cool project in its own right) and wondered why datetime formatting was so slow when using `clock format`.
The code at [2] provided an alternative approach using C via critcl. It was interesting to see how malleable tcl can be.
Somewhat related, it is something I have been trying to figure out, and I did, successfully! This information might help others.
You can create a standalone binary from .tcl files by using KitCreator and sdx (Starkit Developer eXtension). You need to wrap your Tcl script into a .kit file (a virtual filesystem), then combine it with a Tcl runtime to produce a native ELF (or Windows) binary. Optionally, you can encrypt your Tcl code with AES (e.g., using openssl enc) before embedding it, and decrypt it at runtime via a custom loader. The result is a self-contained executable that runs anywhere Tcl is supported. :)
I have a script for it!
Standalone encrypted application created:
-> /tmp/tcl/app.run
-> AES KEY (hex): 95a8a95e8322344b808ebd3fd3986b5b
-> AES IV (hex): 69eac67341d2657a0b00d3006addb131
-> To run it: ./app.run
$ ./app.run
Hello world from binary!
$ file app.run
app.run: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=f3fabb748cc7e61c2fafc7c288f282db2f6de0c7, for GNU/Linux 3.2.0, stripped
The generated app.run is 10 MB and ldd shows it only needs "linux-vdso", "libm", "libc", and "ld-linux-*".
I wonder if there is a more recent sdx, although it still works.
FWIW, the steps are:
1. Download and build Tcl
2. Clone KitCreator and build Tclkit
3. Download SDX
4. Create the loader ($VFS_DIR/main.tcl)
5. Download and extract Tcllib (optional)
6. Copy any modules you want from Tcllib (optional)
7. Add dummy assets to $VFS_DIR/assets/data.json (has a specific format) (probably optional)
8. Wrap and generate .kit and final .run ELF (you need 2 Tclkit binaries, just duplicate it)
If you have any questions, let me know!
---
I have used critcl before, but can't find my code anymore. :( It is good stuff though.
7 comments
[ 2.8 ms ] story [ 24.6 ms ] threadIt makes more sense to me to embed Tk into a C program.
The code at [2] provided an alternative approach using C via critcl. It was interesting to see how malleable tcl can be.
[1] https://github.com/msteveb/jimtcl [2] https://wiki.tcl-lang.org/page/speed+up+clock+format+and+clo...
You can create a standalone binary from .tcl files by using KitCreator and sdx (Starkit Developer eXtension). You need to wrap your Tcl script into a .kit file (a virtual filesystem), then combine it with a Tcl runtime to produce a native ELF (or Windows) binary. Optionally, you can encrypt your Tcl code with AES (e.g., using openssl enc) before embedding it, and decrypt it at runtime via a custom loader. The result is a self-contained executable that runs anywhere Tcl is supported. :)
I have a script for it!
The generated app.run is 10 MB and ldd shows it only needs "linux-vdso", "libm", "libc", and "ld-linux-*".Useful links (taken from my script):
I wonder if there is a more recent sdx, although it still works.FWIW, the steps are:
If you have any questions, let me know!---
I have used critcl before, but can't find my code anymore. :( It is good stuff though.