From: Jan M. <0x...@gm...> - 2024-09-01 20:43:13
|
Hi list. I'm working on the Go port of Tcl/Tk: https://pkg.go.dev/modernc.org/tk9.0@v0.15.4 (Work in progress, parts of the API are still missing.) Now, I want to add support for Windows. After failed attempts to transpile all of the C code to Go, as is done for other platforms, I'm trying an alternative approach. I am compiling tcl9.0b3 and tk9.0b3 using mingw64 on Windows/amd64. Here's the Makefile target: dlls: download rm -rf ~/tmp/tcl9* ~/tmp/tk9* tar xf tcl9.0b3-src.tar.gz -C ~/tmp tar xf tk9.0b3-src.tar.gz -C ~/tmp sh -c "cd ~/tmp/tcl9.0b3/win ; ./configure" make -C ~/tmp/tcl9.0b3/win cp -v \ ~/tmp/tcl9.0b3/win/libtommath.dll \ ~/tmp/tcl9.0b3/win/tcl90.dll \ embed_$(shell go env GOOS)_$(shell go env GOARCH)/ sh -c "cd ~/tmp/tk9.0b3/win ; ./configure --with-tcl=$$HOME/tmp/tcl9.0b3/win" make -C ~/tmp/tk9.0b3/win cp -v \ ~/tmp/tk9.0b3/win/tcl9tk90.dll \ embed_$(shell go env GOOS)_$(shell go env GOARCH)/ This works well, both of the produced binaries, tclsh90 and wish90 seem to work. For example, if I execute in the Windows box '$ ./wish90 ../library/demos/widget' in the ~/tmp/tk9.0b3/win directory, I get the showcase application window and it responds to all mouse events as expected. In the initialization of the package, I'm doing _at runtime_: - Change the current directory to the one where libtommath.dll, tcl90.dll and tcl9tk90.dll are. - Load the tcl90.dll and tcl9tk90.dll, in that order. - Find the dll procedures I will use: Tcl_CreateInterp, Tcl_Init and Tk_Init and a few others. All are found successfully. - Call Tcl_CreateInterp, get back a new non-NULL interpreter. - Call Tcl_Init(interp), get back TCL_OK. - Call Tk_Init(interp), get back TCL_ERROR. The interpreter result says: """" Can't find a usable tk.tcl in the following directories: //zipfs:/app/tk_library //zipfs:/lib/tk/tk_library //zipfs:/lib/tk //zipfs:/lib/tcl/tcl_library/tk9.0 //zipfs:/lib/tcl/tk9.0 ./lib/tk9.0 ./lib/tk9.0 ./lib/tk9.0 ./library This probably means that tk wasn't installed properly. """" If I use Tcl_EvalEx, after Tcl_Init, to evaluate "zipfs list" I get a list of 874 files, all with a common prefix: '//zipfs:/lib/tcl/tcl_library/'. So the earlier error message is correct, none of the search paths could have worked in the zipfs. Interestingly, the wish90.exe program built previously produces the same list, with no mentions of the tk library. But it works so it probably does something differently. I have not yet tried to dive into the C code for wish and how it initializes itself as I'm not really a C programmer. I tried this: jnml@3900x:~/src/modernc.org/tk9.0$ grep -la 'button.tcl' embed_windows_amd64/*.dll embed_windows_amd64/tcl9tk90.dll jnml@3900x:~/src/modernc.org/tk9.0$ grep -la 'Africa' embed_windows_amd64/*.dll embed_windows_amd64/tcl90.dll jnml@3900x:~/src/modernc.org/tk9.0$ The first grep looks for the file name that's in the Tk library and it seems tcl9tk90.dll has it. The second grep looks for a part of a path from the tzdata directory and finds it in tcl90.dll. So the working hypothesis is that the zipfs in tcl90.dll is getting mounted correctly and automatically, but the one in tcl9tk90.dll does not. Which actually seems logical as tcl90.dll does not really know about the existence of tcl9tk90.dll existing in the same process when Tcl_Init is executed. My questions: - Does the reasoning above make any sense or am I missing something important? - If it makes sense, is there a way and/or what is the way to mount the tk_library zipfs in tcl9tk90.dll _before_ calling Tk_Init, so it will succeed? Thanks in advance for any help. Best regards, Jan |