LUCK

Difference between version 30 and 33 - Previous - Next
****Lean Undroidwish Construction Kit****

A by-product of [undroidwish], see it in action in http://www.ch-werner.de/LUCK.html,
the available binary templates in http://www.ch-werner.de/LUCK, and the
source code in https://www.androwish.org/home/dir?ci=tip&name=undroid/luck.

!!!!!!

[undroidwish_image]

!!!!!!

Web based (CGI) script to make a taylored undroidwish, vanillawish
or vanillatclsh from binaries which are searched in the same
directory as the tclsh or wish executing this script.
Additionally, prefabricated configurations are presented.
These are searched like the binaries and additionally relative to
the parent directory of this script.

In the first step, the user selects a prefabricated or uploaded
configuration or a binary. In the second step, a selection of
packages derived from the binary's ZIP is presented plus some
other options such as ZIP password and output filename. The
package selection and other options can be primed by the info
from a prefabricated or uploaded configuration. In the last step
the user can generate a new binary and configuration with only
the selected packages and other options, which is downloaded
as a file.

The generation process uses [memchan] channels and ZIP mounts of
memory buffers, i.e. no native filesystem for temporary storage
is required.

****Currently supported/available platforms****
The following table is a snapshot from 20234-083-168.

%|Platform|Machine|Remarks|%
&|FreeBSD|x86||&
&|Haiku|x86, x86_64|undroidwish only|&
&|Illumos|x86||&
&|Linux|x86, x86_64, arm, aarch64, riscv64|glibc and musl, wayland|&
&|MacOSX|x86_64|no builds for Catalina and newer|&
&|OpenBSD|x86_64||&
&|Windows|x86, x86_64||&&|Termux|aarch64||&

****REST interface****

The CGI script is RESTful and can be used as a service from other
Tcl scripts utilizing tcllib's rest package, e.g. to easily
mass produce Tcl apps for a variety of platforms. Here is an
example on how to read out information and make a binary:

======
# Demonstrate usage of LUCK RESTfully, requires a locally running LUCK service on port 8015

package require rest

set luck(list) {
    url http://localhost:8015/cgi-bin/luck.tcl description {list of available templates}
    result raw
    method post static_args {api list} req_args {} opt_args {}
}

# req_args:
#   -template   name of binary template, e.g. vanillawish-linux32
# opt_args:
#   -withtips   when present send alternating lines of extension name and description

set luck(extlist) {
    url http://localhost:8015/cgi-bin/luck.tcl description {list of extensions of given template}
    result raw
    method post static_args {api extlist} req_args {template:} opt_args {withtips}
}

# req_args:
#   -template   name of binary template, e.g. vanillawish-linux32
#   -include    list of extensions to be embedded
# opt_args:
#   -appfile    *.tcl (for app/main.tcl) or *.zip (must have main.tcl),
#               content must be base64 encoded
#   -cmdline    (undroidwish) additional startup arguments
#   -appicon    (undroidwish) BMP (24 bit RGB) icon,
#               content must be base64 encoded
#   -winicon    (Windows binaries) icon (*.ico) for executable,
#               content must be base64 encoded
#   -passwd     ZIP password

set luck(generate) {
    url http://localhost:8015/cgi-bin/luck.tcl description {generate a binary}
    result raw
    method post static_args {api generate} req_args {template: include:} opt_args {appfile: cmdline: appicon: winicon: passwd:}
}

# create REST interface
rest::create_interface luck

# list templates
puts "==== Templates ===="
puts -nonewline [luck::list]

# list extensions of vanillawish-win32.exe
puts "==== Extensions of vanillawish-win32.exe ===="
puts -nonewline [luck::extlist -template vanillawish-win32.exe]

# make tkbugz for win32 from a ZIP which contains main.tcl
# with the single line "source [info nameofexecutable]/tkbugz/tk_bugz.tcl"
set main_tcl_zip {
    UEsDBBQAAAAIAJVmp1I2IJT8MAAAADIAAAAIABwAbWFpbi50Y2xVVAkAA/oblWAL
    HJVgdXgLAAEE6AMAAAToAwAAK84vLUpOVYjOzEvLV8hLzE3NT0utSE0uLUlMykmN
    1S/JTipNrwJS8SBaryQ5hwsAUEsBAh4DFAAAAAgAlWanUjYglPwwAAAAMgAAAAgA
    GAAAAAAAAQAAAKSBAAAAAG1haW4udGNsVVQFAAP6G5VgdXgLAAEE6AMAAAToAwAA
    UEsFBgAAAAABAAEATgAAAHIAAAAAAA==
}
set f [open tkbugz.exe wb]
puts -nonewline $f \
    [luck::generate -template vanillawish-win32.exe \
         -include tkbugz -appfile $main_tcl_zip]
close $f
======

Most vanillatclsh-en from the web site contain a REST based TUI ([CUI])
frontend called `lucktui` which is available in the luck package,
e.g. by running `vanillatclsh... builtin:luck/lucktui.tcl` or
`vanillatclsh... builtin:lucktui` for short. Here's a sample session
as an https://asciinema.org/a/gNg7QznCHEql74SPLo9mcPSst%|%ASCII screencast%|%.

****How to roll your own build service****

   * fetch the relevant (or all) binary templates from http://www.ch-werner.de/LUCK
   * store these in one directory
   * execute `vanillawish... builtin:LUCK` with a vanillawish runnable on your platform; this starts a local [tclhttpd] on port 8015 and tries to invoke a web browser on its LUCK page
   * or execute `vanillatclsh... builtin:lucktui` with a vanillatclsh runnable on your platform; this presents the TUI with a local [tclhttpd] on port 8015
   * begin mass production of single file self contained Tcl/Tk apps; the world is your oyster!

****Build service (advanced)****

   * thanks to [tclvfs] and [SQLite], the above mentioned binaries can be wrapped up, compressed, and deduplicated into a virtual filesystem based on a [SQLite] database
   * this shrinks the required disk space down from 900 MByte to about 300 MByte
   * the current database is in http://www.ch-werner.de/LUCK/luck.tdd
   * the source code of the VFS module is in https://www.androwish.org/home/file?name=undroid/luck/cgi-bin/luckvfs.tcl&ci=tip
   * if `luck.tdd` is placed in the same directory as the CGI script `luck.tcl` it is preferred over the (undroidwish|vanilla(tclsh|wish)) binaries serving all alternatives contained in the database 
   * (experimental) when using `luck.tdd` and the prefabricated configuration `luck.cfg` a big fat binary can be produced which serves as the CGI program and has that database integrated
   * (experimental, self referential) when using a big fat binary and the prefabricated configuration `luck.cfg` another big fat binary for another platform can be produced 

----

****LUCK(y) success story: with light speed to slow trains****

The LUCKy steps to a train application: Try it, it is fun!

   1. Open the [trains3.tcl] wiki page , section "Code"
   2. Copy the Code snippet in the "Code" box by pressing the small right icon on the upper-right corner of the big grey code box.
   3. Go to the LUCK(y) page: http://www.ch-werner.de/LUCK.html
   4. Select a *vanillawish* suitable for your platform, for example "vanillawish-win32.exe".
   5. Scroll down to the entry box titled "Application app/main.tcl" and paste the code snippet (Press Ctrl/Apple+v)
   6. Press button "generate binary". The binary is downloaded. Start the binary and enjoy the movie.

----
'''[aplsimple] - 2022-04-02 06:35:27'''

Thank you, Christian, for your smart interface to construct stand-alone executables, including vanilla tclsh and wish by themselves.

I wonder why this work is so poorly announced and promoted.

LUCK is one of Tcl/Tk gems that deserves to be included in the wiki's start page, side by side with Tcl Developer Xchange link. [APN] I agree along with Paul's [BAWT] and Roy's build farm. I've tweeted a couple of times on all these but that's ephemeral, they should be somewhere front and center as development resources.


'''[nb] - 17/03/2023'''

I am trying to shift from starkits/packs to using this LUCK system which looks way cool...
I am not able to generate an exe with my app and libraries in the 
correct place in the tree...

I guess what I'm asking is how to add own libraries (or libraries not in the LUCK page) under the executable under the root directory 

tx

'''[chw] 2023-03-17'''

This is not possible. But you can have those things as subdirectories of the application folder. And address them easily
from your startup script by using [file dirname [info script]] plus name of subdirectory.
Other alternative is rebuilding LUCK from scratch with your own things included.

----
'''[rz] - 2023-09-20 13:25:52'''

Hi Christian, I tried LUCK with the tksqlite.cfg. It was missing the tclsqlite2/3 packages. I think this was working before. Could you add these packages again. Thank you
'''[chw] - 2023-09-20 14:08:11Z'''

Done, thanks for reporting. BTW: there will be no SQLite version 2 package, since that version is EOL for many years.

<<categories>>SDL|AndroWish|Windows|Distribution