kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 9242af272b569d2335834ab5c18eb2130e870e46
parent 128504789846f077dc83cd5a54b2d05dbf9083a0
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Tue,  9 Jun 2026 08:47:17 -0700

driver/runtime: accept backslash path separator on Windows

kit locates its runtime support tree (rt/, which it compiles libkit_rt from)
by splitting argv[0] on the directory separator to derive <bindir>/../rt and
<bindir>/support/rt. The splitter only recognized '/', but Windows argv[0] /
GetModuleFileNameW use '\', so binary-relative discovery always failed on
Windows and only the cwd-relative ./rt fallback worked -- kit.exe printed
'cc: support dir not found' unless run from the directory holding rt. Treat
'\' as a separator too (gated to _WIN32; POSIX paths are unaffected) so the
standard <bindir>/support/rt install layout resolves from any cwd.

Diffstat:
Mdriver/lib/runtime.c | 16++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/driver/lib/runtime.c b/driver/lib/runtime.c @@ -282,6 +282,18 @@ static int rt_try_support_root(DriverEnv* env, const char* root, return ok ? 0 : 1; } +/* Directory-separator test for splitting a program path. On Windows the image + * path (argv[0] / GetModuleFileNameW) uses '\\', so binary-relative rt + * discovery must accept it as well as '/'; otherwise kit.exe never finds its + * <bindir>/support/rt or <bindir>/../rt and falls back to the cwd-only ./rt. */ +static int rt_is_path_sep(char c) { +#if defined(_WIN32) + return c == '/' || c == '\\'; +#else + return c == '/'; +#endif +} + static int rt_try_argv0_support(DriverEnv* env, const char* argv0, DriverRuntimeSupport* out) { const char* slash; @@ -294,7 +306,7 @@ static int rt_try_argv0_support(DriverEnv* env, const char* argv0, if (!argv0) return 1; slash = argv0 + driver_strlen(argv0); - while (slash > argv0 && slash[-1] != '/') --slash; + while (slash > argv0 && !rt_is_path_sep(slash[-1])) --slash; if (slash == argv0) return 1; dir_len = (size_t)(slash - argv0); if (dir_len == 0) return 1; @@ -325,7 +337,7 @@ static int rt_try_argv0_checkout_root(DriverEnv* env, const char* argv0, if (!argv0) return 1; slash = argv0 + driver_strlen(argv0); - while (slash > argv0 && slash[-1] != '/') --slash; + while (slash > argv0 && !rt_is_path_sep(slash[-1])) --slash; if (slash == argv0) return 1; dir_len = (size_t)(slash - argv0); if (dir_len == 0) return 1;