From ac46b6631ecb485ee8a91d4b2734d259bafc60ce Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sun, 20 Mar 2022 14:26:37 -0700 Subject: [PATCH] Add Windows building --- build/.gitignore | 4 +++- build/windows.bat | 49 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 build/windows.bat diff --git a/build/.gitignore b/build/.gitignore index e82c8dc..7ac0045 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,3 +1,5 @@ septadrop *.deb -DEBIAN/usr/games/septadrop \ No newline at end of file +DEBIAN/usr/games/septadrop +windows +upx.exe \ No newline at end of file diff --git a/build/windows.bat b/build/windows.bat new file mode 100644 index 0000000..b56eefb --- /dev/null +++ b/build/windows.bat @@ -0,0 +1,49 @@ +@echo off +SET TARGET=windows +SET REQUIRED_DLLS=csfml-audio-2.dll csfml-graphics-2.dll csfml-system-2.dll openal32.dll +REM Using UPX 3.96 results in the executable being marked as a virus by Windows. +SET USE_UPX="n" +IF %USE_UPX% == "y" ( + IF NOT EXIST upx.exe ( + ECHO Can't find upx.exe. You can download the latest UPX release from GitHub: https://github.com/upx/upx/releases + EXIT /b + ) +) +SET missing_ddls="n" +for %%a in (%REQUIRED_DLLS%) do ( + IF NOT EXIST ..\target\release\%%a ( + ECHO Can't find %%a in target\release. + SET missing_ddls="y" + ) +) +IF %missing_ddls% == "y" ( + ECHO You can download the required DDLs from SFML's website. + ECHO SFML 2.5.1: https://www.sfml-dev.org/download/sfml/2.5.1/ + ECHO CSFML 2.5.1: https://www.sfml-dev.org/download/csfml/ + ECHO After downloading, copy them to target\debug and target\release, then try running this script again. + EXIT /b +) +IF EXIST %TARGET% ( + RMDIR /S /Q %TARGET% +) +MD %TARGET% +CD .. +cargo build --release || ( + ECHO Seems like something went wrong building the project, even though all required DDLs were found. + ECHO Have you copied all the appropriate .lib files for SFML and CSFML into your Rust toolchain's libraries folder? + ECHO If you're having trouble, please take a look at the following guides. + ECHO Rust SFML MSCV Windows Setup: https://www.youtube.com/watch?v=nnojR-8PT4M + ECHO rust-sfml Windows wiki page: https://github.com/jeremyletang/rust-sfml/wiki/Windows + CD build + EXIT /b +) +COPY target\release\septadrop.exe build\%TARGET%\septadrop.exe > NUL +for %%a in (%REQUIRED_DLLS%) do ( + COPY target\release\%%a build\%TARGET% > NUL +) +XCOPY /E /D res build\%TARGET%\res\ > NUL +CD build +IF %USE_UPX% == "y" ( + upx.exe --best --lzma %TARGET%/septadrop.exe +) +ECHO Finished building and packaging successfully! \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 23aa90f..e796a94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + use gcd::Gcd; use rand::seq::SliceRandom; use sfml::audio::*;