Skip to content

Add MSVC build scripts & fix for MSVC#4

Merged
solardiz merged 6 commits into
openwall:mainfrom
quadcpu:msvc
Jun 15, 2026
Merged

Add MSVC build scripts & fix for MSVC#4
solardiz merged 6 commits into
openwall:mainfrom
quadcpu:msvc

Conversation

@quadcpu

@quadcpu quadcpu commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Adding build scripts for Windows MSVC and applied some fixes for MSVC compiler ( which doesn't support many of C lang keywords and unix apis )

This is implemented because Rust and Node.js still requires MSVC targets for c bindings ( maybe they would add support for clang-cl at the future, but I think it would not happen at least on upcoming years ), and since gcc / clang still remains experimental for windows support :(

Source fixes for MSVC (all guarded so GCC behavior is unchanged):

  • sha256.c — dropped the C99 static keyword from [static restrict N] array parameters, which MSVC rejects (restrict was already macro-empty on MSVC).
  • benchmark.c — added a Win32 shim (<windows.h>-based times/sysconf/geteuid + struct tms) under #ifdef _MSC_VER in place of <unistd.h>/<sys/times.h>/<sched.h>; also moved an OpenMP-only collision-check loop
    (save/nsave) inside the existing #ifdef _OPENMP.
  • tests.c — setvbuf(stdout, NULL, _IOLBF, 0) crashes on MSVC (it needs a non-NULL buffer for line buffering); switched to _IONBF on MSVC.

It builds on Windows like https://github.com/quadcpu/yespower/actions/runs/27429768034/job/81076781413

@solardiz

Copy link
Copy Markdown
Member

Thanks! Clearly, AI was involved. This makes me wonder if the changes could actually be simpler - AI easily writes a lot of code without "thinking" whether that was in fact required. Specifically, is the PowerShell script needed, doesn't MSVC also provide make? If we merge this, who would maintain the PowerShell script?

  • also moved an OpenMP-only collision-check loop (save/nsave) inside the existing #ifdef _OPENMP.

Why do you call it "OpenMP-only"?

@solardiz

Copy link
Copy Markdown
Member

Oh, I see the collision-check was in fact OpenMP only. So it was a bug it wasn't guarded. OK then.

@solardiz solardiz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I request some trivial changes (such as the SCHED_RR check) and make comments for discussion (such as whether we need the PowerShell script).

For the changes, please use force-pushes of the existing commits - don't add more commits.

Comment thread .github/workflows/build.yml Outdated
Comment thread .github/workflows/build.yml Outdated
Comment thread .github/workflows/build.yml Outdated
Comment thread benchmark.c Outdated
Comment thread benchmark.c Outdated
Comment thread build.ps1
@quadcpu

quadcpu commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@solardiz Hello, thank you for quick review.

Of course things would be much easier if MSVC supports make however they doesn't and here is what AI says ( from google search though )

To build projects using Microsoft Visual C++ (MSVC) with a "make" workflow, Microsoft provides its own native clone of the make utility called [NMAKE](https://learn.microsoft.com/en-us/cpp/build/reference/c-cpp-building-reference?view=msvc-170).

Also, the reason that NMAKE or MSYS2 make isn't being used for MSVC is that basically, MSVC doesn't export it's binaries to PATH so the correct method of using them would be, 1. targeting vswhere.exe, a literal MSVC navigator first via known paths ( not envs ), 2. Finding necessary binaries / libraries used for MSVC.

Those two processes are very painful when you do it manually and that is why powershell script, which is something that comes with Windows installation would be here as a perfect solution to handle all this mess.

( You can also see my powershell script for building Bitcoin with MSVC tools here https://github.com/quadcpu/bitcoin/blob/msvc-31.0/build-win.ps1 https://github.com/quadcpu/bitcoin/blob/msvc-31.0/build-win.md, the official bitcoin docs suggest of the simple use of cmake and ctest but it is still a pain when they comes with MSVC installation which doesn't export it's PATH natively https://github.com/quadcpu/bitcoin/blob/msvc-31.0/doc/build-windows-msvc.md. )

- build.yml: use 'make check' instead of a manual build+diff, and drop the
  -lrt/-s linker flags on Linux and macOS (only the benchmark needs them).
- build.yml: build and run the benchmark on Linux and Windows for compile
  coverage of benchmark.c (macOS lacks the OpenMP it needs).
- benchmark.c: lead with the POSIX block (#ifndef _MSC_VER), wrap the
  SCHED_RR block in #ifdef SCHED_RR, and drop the now-unneeded geteuid shim.
- build.ps1: 'benchmark' target now builds and runs benchmark.exe.
@quadcpu quadcpu requested a review from solardiz June 13, 2026 05:52
@quadcpu

quadcpu commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

I have also made some changes that could possibly address the pointed out issues. I will also apply same changes to openwall/yescrypt#11 when this PR is merged

echo PASSED
make check LDFLAGS="" | tee /dev/stderr | grep -qx PASSED
make benchmark
./benchmark

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the purpose of | tee /dev/stderr | grep -qx PASSED to get the exit code right? If so, we should probably enhance Makefile so that make check gives the right exit code directly, if it doesn't already.

Similarly, doesn't make check already build and run benchmark? Do we end up running it twice here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the purpose of | tee /dev/stderr | grep -qx PASSED to get the exit code right?

Yes, and I just fixed the makefile to produce correct error code

Similarly, doesn't make check already build and run benchmark?

It doesn't, I just checked and still we need to run make check , make benchmark and ./benchmark ( for powershell script build.ps1 -Target benchmark does run benchmark.exe though

@solardiz

Copy link
Copy Markdown
Member

Thank you! As I wrote:

For the changes, please use force-pushes of the existing commits - don't add more commits.

Would it be practical for you to roll your changes into the original commit? I don't want a separate "Address PR comments" commit in this project's history, but I do want to include long-term relevant commit info from here.

Make correct exit code for make check
@quadcpu

quadcpu commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

Would it be practical for you to roll your changes into the original commit?

@solardiz Yes, I left commits without squashing it for better review. ( and since that I would reuse commit changes to apply it on other PR as well ). Would be great if you can sqash merge the PR so that it would end up in a single commit merge.

@quadcpu quadcpu requested a review from solardiz June 13, 2026 14:00
Comment thread .github/workflows/build.yml Outdated
# Then build and run "benchmark" to compile-cover its OpenMP/POSIX path
# (it keeps the default -fopenmp and -lrt, which gcc on Linux supports).
# runs the "tests" target, then exits non-zero on a mismatch. The "tests"
# binary needs neither -lrt nor -s, so LDFLAGS="" drops them. Then build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure -s -lrt are unnecessary for tests on recent glibc, but why bother dropping them? Let's not introduce unneeded complexity and unnecessary explanations here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, solved

@solardiz

Copy link
Copy Markdown
Member

OK, this almost looks good. I think we also need your copyright+license statement for the PowerShell script, similar to what I use for other files in here if possible.

* Removed unnecessary comments on build.yml
* Added Copyright Header on PS1
@quadcpu

quadcpu commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

@solardiz Done, I have also added appropriate copyright header on .ps1 file since I am not the repo owner here haha

@quadcpu quadcpu requested a review from solardiz June 14, 2026 05:03
@solardiz

Copy link
Copy Markdown
Member

I have also added appropriate copyright header on .ps1 file since I am not the repo owner here haha

It's weird to have this copyrighted by me when I didn't contribute to it at all. Are you saying you're assigning me the copyright for your (or your AI's) work?

@quadcpu

quadcpu commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@solardiz Yeah, if it is required would be adding "Copyright 2026 CPUchain" on top of the file though

@solardiz

Copy link
Copy Markdown
Member

@quadcpu Copyright assignment is good, but I suggest adding a clarification that this was "Contributed by CPUchain with copyright assigned to the project's original author". Just this additional line.

@solardiz

Copy link
Copy Markdown
Member

Would be great if you can sqash merge the PR so that it would end up in a single commit merge.

I'll plan on doing squash-and-merge, although I'm mildly unhappy this puts GitHub as the committer. I prefer it when the PR contributor uses force-pushes, so that the commits can then be merged as-is.

@quadcpu

quadcpu commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@solardiz I just forgot ps1 file was a transpile of Makefile assisted by AI. I have just added appropriate copyright header onto that file thank you.

I'll plan on doing squash-and-merge, although I'm mildly unhappy this puts GitHub as the committer. I prefer it when the PR contributor uses force-pushes, so that the commits can then be merged as-is.

Sounds good enough, when it is squashed merge I will also update the PR on yescrypt as well

Now added the commit

@solardiz solardiz merged commit 3070b39 into openwall:main Jun 15, 2026
@solardiz

Copy link
Copy Markdown
Member

Merged, thank you! Please proceed with yescrypt now.

@solardiz

Copy link
Copy Markdown
Member

I've just amended the commit in main to correct the "On Windows." heading indentation. I think this project is obscure enough we can do things like that to recently merged commits. ;-)

@quadcpu quadcpu deleted the msvc branch June 15, 2026 18:14
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.

2 participants