Skip to content

Win32 support #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Win32 support #118

wants to merge 13 commits into from

Conversation

cyanidle
Copy link

@cyanidle cyanidle commented May 14, 2025

Hello. I am another poor soul trying to add windows support.

I got basic stuff working: os-dependent jobs stuff is separated into os.h. I also fixed lots of memory leaks found with -fsanitize-address. Posix side with new abstractions seems to work OK.

Things that need fixing before windows support can be declared:

  • deps = msvc
  • $variable substitutions are escaped with quotes, which works fine with /usr/bin/sh -c, but fails on Windows (CreateProcess does no CLI processing), when MSVC tries to compile something (cl.exe ... -c '<file') -> causes warning D9027 : source file ''samurai\os-win32.c'' ignored
  • Parsing .ninja_deps from ninja causes segfault in depsinit() (node->gen is null for some reason)
  • jobs/osjobs array seems to never shrink. On huge number of jobs in build this will cause lots of iterations over these two arrays. Perf hit is probably not very big, but this is very O(n^2)
  • Makefile should be modified to support .exe suffix and use mt.exe to add manifest file -> important for UTF-8 and long paths. NMake does not support Gnu Make's ifeq(), it has its own syntax for conditionals. May be easier to have two Makefiles, for make and nmake
  • setvbuf() is disabled in win32, bc it causes assert with bufsize zero
  • canonpath() and other path related APIS

CMakefile and related gitignores are for development only, it helps with IDE support.

There seem to be issues with formatting caused by said IDEs and TABS. Idk how to fix that :D

@tritao
Copy link

tritao commented May 15, 2025

I'm just a passer by, just want to say nice work, hope this can be completed and Win32 support added 👍

There seem to be issues with formatting caused by said IDEs and TABS. Idk how to fix that :D

Left a few comments related to this before reading this, but seems like you're already aware.

Copy link

@TomasBorquez TomasBorquez left a comment

Choose a reason for hiding this comment

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

left comments on some warning you were getting, also i think you can fix the indentation with clang-format project settings:

clang-format -i -style=file $(find ./ -name "*.c" -o -name "*.h")

@TomasBorquez
Copy link

First test - simplest

Simple ninja file:

cc = gcc
target = main.exe

rule link
  command = $cc $flags -o $out $in

rule compile
  command = $cc $flags -c $in -o $out

build main.o: compile main.c
build $target: link main.o

default $target

Ran it on the same folder:

Lewboski@DESKTOP-CK46RK4 MINGW64  /c/Users/Lewboski/Desktop/Programming/learn/mate/tests/01-basic-build/build
$ ./samu.exe 
[1/2] gcc  -c main.c -o main.o
C:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build\samu.exe: CreateProcess: No such file or directory
C:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build\samu.exe: job failed to start

Second test - vars

I tested it with some variables on a single source:

cc = gcc
flags = -Wall -g
cwd = C$:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build
builddir = C$:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build
target = $builddir/main.exe

rule link
  command = $cc $flags -o $out $in

rule compile
  command = $cc $flags -c $in -o $out

build $builddir/main.o: compile $cwd/src/main.c
build $target: link $builddir/main.o

default $target

Ran it with -f, and got:

Lewboski@DESKTOP-CK46RK4 MINGW64  /c/Users/Lewboski/Desktop/Programming/learn/mate/tests/01-basic-build
$ ./build/samu.exe -f ./build/build.ninja
C:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build\samu.exe: mkdirs C:\: No error
C:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build\samu.exe: job failed to start
C:\Users\Lewboski\Desktop\Programming\learn\mate\tests\01-basic-build\build\samu.exe: subcommand failed

you can use these as reference meanwhile testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants