Layers/build.bat

66 lines
2.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
rem Picks the GNU/MinGW target based on host arch:
rem ARM64 -> aarch64-pc-windows-gnullvm (clangarm64 llvm-mingw toolchain)
rem x86_64 -> x86_64-pc-windows-gnu (ucrt64 gcc-mingw toolchain)
rem LAYERS_RUST_TARGET overrides.
pushd %~dp0
set "ROOT=%CD%"
if defined LAYERS_RUST_TARGET (
set "RUST_TARGET=%LAYERS_RUST_TARGET%"
) else if /I "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
set "RUST_TARGET=aarch64-pc-windows-gnullvm"
) else (
set "RUST_TARGET=x86_64-pc-windows-gnu"
)
echo rust target: %RUST_TARGET%
set "STAGE=%ROOT%\build\bin\com.jesshunter.layers"
set "APPDIR=%STAGE%\bin"
if exist "%STAGE%" rmdir /s /q "%STAGE%"
mkdir "%APPDIR%" >nul 2>&1
mkdir "%STAGE%\resources" >nul 2>&1
where rsvg-convert >nul 2>&1
if %ERRORLEVEL% equ 0 (
for %%s in (24 48 128 256) do (
if not exist "%ROOT%\resources\icon-%%s.png" (
rsvg-convert --width %%s --height %%s "%ROOT%\resources\Layers.svg" -o "%ROOT%\resources\icon-%%s.png"
)
)
)
set "NNG_RELAX=-Wno-error=incompatible-pointer-types -Wno-error=incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-incompatible-function-pointer-types"
if defined CFLAGS (
set "CFLAGS=%CFLAGS% %NNG_RELAX%"
) else (
set "CFLAGS=%NNG_RELAX%"
)
cargo build --release --bin layers --target %RUST_TARGET%
if %ERRORLEVEL% neq 0 (
echo cargo build failed
popd
exit /b 1
)
copy /y "%ROOT%\target\%RUST_TARGET%\release\layers.exe" "%APPDIR%\Layers.exe" >nul
if exist "%ROOT%\LICENCE" copy /y "%ROOT%\LICENCE" "%STAGE%\LICENCE" >nul
xcopy /e /i /y /q "%ROOT%\resources" "%STAGE%\resources" >nul
if not exist "%ROOT%\plugin.json.in" (
echo ERROR: %ROOT%\plugin.json.in not found
popd
exit /b 1
)
powershell -NoProfile -Command "(Get-Content -Raw -LiteralPath '%ROOT%\plugin.json.in') -replace '@ENTRYPOINT@', 'bin/Layers.exe' | Set-Content -LiteralPath '%STAGE%\plugin.json' -NoNewline"
echo.
echo staged: %STAGE%
echo exe: %APPDIR%\Layers.exe
popd
endlocal