Build scripts for Windows

This commit is contained in:
Jack Grigg 2018-11-21 13:41:07 +00:00
parent 8a5997b158
commit d1560687f3
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
3 changed files with 136 additions and 2 deletions

87
build-ndk-standalone.bat Normal file
View File

@ -0,0 +1,87 @@
@if "%DEBUG%" == "" @echo off
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
@rem put this somewhere that's often ignored by git
set output_dir=%DIRNAME%\out\ndk\standalone
@rem check for NDK standalone
if exist "%output_dir%" echo Standalone NDK files found! && exit /b 0
cd %ANDROID_HOME%
for /f "tokens=* usebackq" %%F in (`dir "*make_standalone_toolchain.py" /s /b`) do (
set standalone_script=%%F
)
cd %DIRNAME%
@rem Try to find and print some info about the NDK based on the location of the toolchain script
if exist "%standalone_script%" goto standaloneScriptFound
echo NDK not found. Please make sure that ANDROID_HOME is set and the NDK has been installed there
exit 1
:standaloneScriptFound
echo Standalone NDK files appear to be missing.
echo Attempting to install them...
for %%F in (%standalone_script%) do set tools_dir=%%~dpF
set tools_dir=%tools_dir:~0,-1%
for %%F in (%tools_dir%) do set build_dir=%%~dpF
set build_dir=%build_dir:~0,-1%
for %%F in (%build_dir%) do set ndk_dir=%%~dpF
for /f "tokens=* usebackq" %%F in (`findstr "[0-9.]{5,}" %ndk_dir%\source.properties`) do (
set ndk_version=%%F
)
echo NDK version %ndk_version% found at %ndk_dir%
echo Installing the standalone NDK for "x86|arm|arm64" into %output_dir%
mkdir %output_dir%
"%standalone_script%" --arch x86 --api 16 --install-dir "%output_dir%\x86"
"%standalone_script%" --arch arm --api 16 --install-dir "%output_dir%\arm"
"%standalone_script%" --arch arm64 --api 21 --install-dir "%output_dir%\arm64"
@rem check for our generated cargo file
set cargo_dir=%DIRNAME%\..\.cargo
set generated_cargo_config=%cargo_dir%\config
if exist "%generated_cargo_config%" goto backup
goto generate
:backup
set backup_config=%cargo_dir%\config.backup
echo existing config found. Backing it up from %generated_cargo_config% to %backup_config%
copy %generated_cargo_config% %backup_config%
:generate
echo generating cargo config at %generated_cargo_config%
mkdir %cargo_dir% 2>NUL
@rem Cargo needs forward slashes
set output_dir=%output_dir:\=/%
(
echo #auto-generated by build-ndk-standalone.bat
echo.
echo [target.i686-linux-android]
echo ar = "%output_dir%/x86/bin/i686-linux-android-ar.exe"
echo linker = "%output_dir%/x86/bin/i686-linux-android-clang.cmd"
echo.
echo [target.armv7-linux-androideabi]
echo ar = "%output_dir%/arm/bin/arm-linux-androideabi-ar.exe"
echo linker = "%output_dir%/arm/bin/arm-linux-androideabi-clang.cmd"
echo.
echo [target.aarch64-linux-android]
echo ar = "%output_dir%/arm64/bin/aarch64-linux-android-ar.exe"
echo linker = "%output_dir%/arm64/bin/aarch64-linux-android-clang.cmd"
) > %generated_cargo_config%
echo Done
exit /b 0

41
build-rust.bat Normal file
View File

@ -0,0 +1,41 @@
@if "%DEBUG%" == "" @echo off
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem check for cargo installation
cargo --version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto cargoFound
echo Cargo appears to be missing.
echo Go to https://rustup.rs/ to install it, and then run this script again.
exit /b 1
:cargoFound
echo Cargo found!
@rem update android targets
echo Updating android targets...
echo rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android
echo Done.
@rem check for standalone NDK
call build-ndk-standalone.bat
if %ERRORLEVEL% neq 0 exit /b 1
echo Building...
echo building aarch64...
cargo build --target aarch64-linux-android --release
if %ERRORLEVEL% neq 0 exit /b 10
echo building i686...
cargo build --target i686-linux-android --release
if %ERRORLEVEL% neq 0 exit /b 20
echo building armv7...
cargo build --target armv7-linux-androideabi --release
if %ERRORLEVEL% neq 0 exit /b 30
echo Done.

View File

@ -49,8 +49,14 @@ tasks.register("generateJniLibs").configure {
}
description = "Generate *.so files for connecting to the Rust wallet logic through the JNI"
doLast {
exec {
commandLine("./build-rust.sh")
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
exec {
commandLine("./build-rust.bat")
}
} else {
exec {
commandLine("./build-rust.sh")
}
}
}
inputs.files(fileTree(dir: jniSrcDir, include: '**/*'))