Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tools/iop_deps.pdf
cscope.out
.*.swp
.vscode/
.vs/
.clangd/
.cache
tags
Expand All @@ -25,3 +26,5 @@ output*png
Brewfile.lock.json
CMakeLists.txt.user
workspace/

CMakeUserPresets.json
23 changes: 23 additions & 0 deletions data/luarc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ ipairs = function(t)
end
end


local dt = require "darktable"
if dt.configuration.running_os == "windows" then
-- Lua on Windows opens a cmd terminal window whenver
-- a subprocess is started. We need to use Win32 APIs
-- which do not do this, and replace the standard Lua functions.

-- os.execute = dt.windows.os_execute

io.close = dt.windows.close
io.flush = dt.windows.flush
io.input = dt.windows.input
io.lines = dt.windows.lines
io.open = dt.windows.open
io.output = dt.windows.output
io.popen = dt.windows.popen
io.read = dt.windows.read
io.tmpfile = dt.windows.tmpfile
io.type = dt.windows.type
io.write = dt.windows.write
end


-- script installer

local _scripts_install = {}
Expand Down
27 changes: 24 additions & 3 deletions packaging/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ The steps to build darktable Windows executable and make installer (Windows 8.1
[UCRT installed](https://support.microsoft.com/en-us/topic/update-for-universal-c-runtime-in-windows-c0514201-7fe6-95a3-b0a5-287930f3560c))
are as follows:

* Install MSYS2 (instructions and prerequisites can be found on the official website: https://www.msys2.org)
A short summary about the installation environment: The compilation is done by MSYS2 (For more background, see the documentation at https://www.msys2.org). In short, MSYS2 provides a Unix development environmnent (binaries, libraries, compilers etc) on Windows. In contrast to WSL, it does not run in a virtual machine. Instead, the binaries are native Windows binaries.

* Start the MSYS terminal and update the base system until no further updates are available by repeating:
We will use the Universal C Runtime (UCRT), which is a newer runtime (in comparison with MSVCRT). See the information about the environments on MSYS at https://www.msys2.org/docs/environments.

Note that there are two terminals. The MSYS terminal is for "normal" system work, and the UCRT64 terminal is for building (this is achived by prepending the MSYS64's `bin` directory to the PATH, thus giving precedence to the UCRT64 toolchain).


* Install MSYS2 (instructions and prerequisites can be found on the official website: https://www.msys2.org). For additional convenience,
configure the Windows terminal (https://www.msys2.org/docs/terminals/#windows-terminal) appropriately.


* Start the MSYS (not UCRT64) terminal and update the base system until no further updates are available by repeating:
```bash
pacman -Syu
```

* From the MSYS terminal, install the toolchain (assuming x64), developer tools and git:
```bash
pacman -S --needed base-devel git intltool po4a
pacman -S --needed mingw-w64-ucrt-x86_64-{cc,cmake,gcc-libs,ninja,omp}
pacman -S --needed mingw-w64-ucrt-x86_64-{cc,cmake,gcc-libs,ninja,omp} #Install the UCRT64 toolchain
```

* Install required and recommended dependencies for darktable:
Expand Down Expand Up @@ -93,3 +102,15 @@ If you like experimenting you could also install `mingw-w64-ucrt-x86_64-{clang,l
Windows on Arm (WoA) users should use the `mingw-w64-clang-aarch64-` prefix when installing packages above and build within the CLANGARM64 environment instead (note that it is not currently possible to build the installer image because of missing `nsis`).

Have fun with this, report back your findings.


## Development with Visual Studio Code

After installing and configuring MSYS2 from above, create a `CMakeUserPresets.json` in the root directory of this repository.



https://cadhut.com/2020/08/02/how-to-set-up-and-use-msys2/
https://www.msys2.org/docs/environments/

https://dominikberner.ch/cmake-presets-best-practices/#:~:text=The%20command%20to%20configure%20a%20project%20using%20a,CMake%20with%20cmake%20--build%20--preset%20%3Cpreset-name%3E%20--target%20test.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ FILE(GLOB SOURCE_FILES
"imageio/imageio_tiff.c"
"libs/lib.c"
"views/view.c"
if(WIN32)
Copy link
Member

@wpferguson wpferguson Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to move this out of the GLOB and into the if(USE_LUA) section.. I tried to compile on Liinux and it tried to include lua/windows.c

After the GLOB command add

if(WIN32)
  list(APPEND SOURCE_FILES_LUA, "lua/windows.c")
endif(WIN32)

"lua/windows.c"
endif(WIN32)
)

FILE(GLOB HEADER_FILES "*.h" "common/*.h" "external/OpenCL/CL/*.h" "control/*.h" "iop/*.h" "libs/*.h" "views/*.h")
Expand Down
2 changes: 1 addition & 1 deletion src/external/lua/src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ LUA_API int lua_absindex (lua_State *L, int idx) {

LUA_API int lua_gettop (lua_State *L) {
return cast_int(L->top.p - (L->ci->func.p + 1));
}
}°
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to get rid of whatever that character is after the curly brace.



LUA_API void lua_settop (lua_State *L, int idx) {
Expand Down
14 changes: 12 additions & 2 deletions src/lua/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "lua/types.h"
#include "lua/util.h"
#include "lua/view.h"
#include "lua/windows.h"
#include "lua/widget/widget.h"

static int _lua_fully_initialized = false;
Expand Down Expand Up @@ -136,14 +137,23 @@ static int run_early_script(lua_State* L)
}


#ifndef WIN32
static lua_CFunction init_funcs[]
= { dt_lua_init_glist, dt_lua_init_image, dt_lua_init_styles, dt_lua_init_print,
dt_lua_init_configuration, dt_lua_init_preferences, dt_lua_init_database, dt_lua_init_gui,
dt_lua_init_luastorages, dt_lua_init_tags, dt_lua_init_film, dt_lua_init_call,
dt_lua_init_view, dt_lua_init_events, dt_lua_init_init, dt_lua_init_widget,
dt_lua_init_lualib, dt_lua_init_gettext, dt_lua_init_guides, dt_lua_init_cairo,
dt_lua_init_password, dt_lua_init_util, NULL };

dt_lua_init_password, NULL };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to keep dt_lua_init_util

#else
static lua_CFunction init_funcs[]
= { dt_lua_init_glist, dt_lua_init_image, dt_lua_init_styles, dt_lua_init_print,
dt_lua_init_configuration, dt_lua_init_preferences, dt_lua_init_database, dt_lua_init_gui,
dt_lua_init_luastorages, dt_lua_init_tags, dt_lua_init_film, dt_lua_init_call,
dt_lua_init_view, dt_lua_init_events, dt_lua_init_init, dt_lua_init_widget,
dt_lua_init_lualib, dt_lua_init_gettext, dt_lua_init_guides, dt_lua_init_cairo,
dt_lua_init_password, dt_lua_init_windows, NULL };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

#endif

void dt_lua_init(lua_State *L, const char *lua_command)
{
Expand Down
Loading