Last active
March 9, 2024 17:57
-
-
Save straight-shoota/e4393c9e3f0febb7dc290470f92f5c0d to your computer and use it in GitHub Desktop.
Crystal compiler wrapper for Windows Subsystem for Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# MSVC 2017 | |
# MSVC_BUILD_TOOLS="C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\BuildTools\\VC\\Auxiliary\\Build\\vcvarsall.bat" | |
# MSVC 2015 | |
MSVC_BUILD_TOOLS="C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ C++^ Build^ Tools\\vcbuildtools.bat" | |
set -euo pipefail | |
# Catching the result of the program does not play nice with the progress output. Otherwise we could use this: | |
# linker_command=$(bin/crystal build --cross-compile --target x86_64-unknown-windows-msvc "${@}") | |
# name=$(echo $linker_command | sed -E 's/.*\/Fe([^ "]+).*/\1/') | |
# Cross-compile Crystal program | |
bin/crystal build --progress --cross-compile --target x86_64-unknown-windows-msvc "${@}" | |
name=$(basename "${1%.*}") | |
linker_command="cl ${name}.o /Fe${name} pcre.lib gc.lib libcmt.lib" | |
# user32.lib should not be required but libgc expects it | |
linker_command="${linker_command} user32.lib" | |
echo | |
# Run the msvc build tools to link final executable through Windows interoperability | |
cmd.exe /S /c "${MSVC_BUILD_TOOLS} amd64 && cd /D %CD% && ${linker_command}" | |
echo | |
echo "./${name}.exe" | |
# Run the compiled executable through Windows interoperability | |
./${name}.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment