savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
157 stars 12 forks source link

Add support for (cross-compiling to) Windows. #318

Closed jemc closed 2 years ago

jemc commented 2 years ago

Note that because Crystal doesn't fully support Windows yet, the Savi compiler still cannot run on native Windows. But Savi programs can, after being cross-compiled.

After this change, it is possible to build 64-bit Windows binaries from a Linux host running the Savi compiler, after setting the SDK_ROOT environment variable to point to a directory tree where the Windows SDK libraries can be found (such as an MSVC installation), using a command like this:

savi build --cross-compile=x86_64-unknown-windows-msvc

Note that the Savi compiler includes the lld linker inside it, so it is not necessary to have access to the full MSVC toolchain - only the .lib files must be reachable within the SDK_ROOT tree.

One convenient way to automate the downloading of these libraries on non-Windows platforms is xwin. For example, running the following commands should be sufficient (after reviewing the Windows SDK license and agreeing to its terms):

xwin --accept-license 1 splat --output /tmp/xwin
env SDK_ROOT=/tmp/xwin savi build --cross-compile=x86_64-unknown-windows-msvc

Note that not all of the Savi standard library works on Windows yet - getting this new compiler with cross-compilation support for Windows will allow the Savi team to iterate on bringing each library into full Windows support and adding Windows CI to all repos.