Skip to content

Commit

Permalink
Updating build scripts targeting android (#161)
Browse files Browse the repository at this point in the history
Made changes to build scripts to make the process between Windows and Linux hosts more similar. Also updated documentation.

Now in both scripts:
* ability to pass a parameter to specify build for only one type (Debug/Release) with basic input validation
* gfxr replay files are copied to build_android/<BUILD_TYPE>/third_party/gfxreconstruct/android/tools/replay
* start and end time is reported at the end of execution
* gradle is passed the flag --console=verbose for more descriptive and permanent output

Remaining differences:
* where gradle builds for gfxr are triggered
  * on Windows this is triggered from build_android.bat
  * on Linux this is triggered from cmake
  • Loading branch information
angela28chen authored Jan 15, 2025
1 parent 696d6f4 commit 79e7368
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 32 deletions.
34 changes: 17 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ if(MSVC)
endif()
set(THIRDPARTY_DIRECTORY "${CMAKE_SOURCE_DIR}/third_party")
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_BUILD_TYPE_LOWERCASE "release")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_BUILD_TYPE_LOWERCASE "debug")
endif()

if(ANDROID)
add_subdirectory(third_party/freedreno)
Expand Down Expand Up @@ -107,28 +112,23 @@ else()
if(NOT CMAKE_HOST_WIN32)
message(CHECK_START "Build gfxr for android")
execute_process(
COMMAND ./gradlew assembleDebug
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
)

execute_process(
COMMAND ./gradlew assembleRelease
COMMAND ./gradlew assemble${CMAKE_BUILD_TYPE} --console=verbose
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android
COMMAND_ERROR_IS_FATAL ANY
)
message(CHECK_PASS "successful")

file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-debug.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/layer"
message(CHECK_START "Move gfxr files")
file(
ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-${CMAKE_BUILD_TYPE_LOWERCASE}.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/layer"
)

file(ARCHIVE_EXTRACT
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-release.aar"
DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/layer"
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/tools/replay)
file(
COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/${CMAKE_BUILD_TYPE_LOWERCASE}/.
DESTINATION ${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/tools/replay
)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release)
message(CHECK_PASS "successful")
endif()
endif()
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@ Run the script

On Linux, run:
```
./scripts/build_android.sh
./scripts/build_android.sh Debug
```
And on Windows, Open Developer Command Prompt for VS 2022(or 2019) and run

```
scripts\build_android.bat
scripts\build_android.bat Debug
```

It will build both debug and release version of the libraries under `build_android` folder. It will also build gfxreconstruct binaries under `third_party/gfxreconstruct/android` and copy them to under `build_android`.
It will build the debug version of the libraries under `build_android` folder. To build release version, replace parameter with `Release`. To build both versions, do not pass a parameter.

It will also trigger gradle to rebuild gfxreconstruct binaries under `third_party/gfxreconstruct/android/...` and copy them to under `build_android`.

Troubleshooting tips:
- Open the gradle project at `third_party/gfxreconstruct/android` in Android Studio and try making recommended changes to the project and building from there.
- Delete build folders for a clean build
- `third_party/gfxreconstruct/android/layer/build`
- `third_party/gfxreconstruct/android/tools/replay/build`
- `build_android`
- If incremental builds are slow, try building only one version (Debug or Release) and not both

### CLI Tool for capture and cleanup
#### Capture with command line tool for Android applications
Expand Down
35 changes: 26 additions & 9 deletions scripts/build_android.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@
:: limitations under the License.

@echo off

setlocal enabledelayedexpansion
set PROJECT_ROOT=%~dp0\..
set BUILD_TYPE=Debug Release
set SRC_DIR=%PROJECT_ROOT%
set GFXR_ROOT_DIR=%PROJECT_ROOT%\\third_party\\gfxreconstruct\\android
set startTime=%time%

(for %%b in (%BUILD_TYPE%) do (
if "%~1"=="" goto parsingdone
if "%1"=="Debug" set BUILD_TYPE=%1
if "%1"=="Release" set BUILD_TYPE=%1
if not !BUILD_TYPE!==%1 (
echo Invalid parameter passed for BUILD_TYPE: %1
echo Valid options: 'Debug', 'Release'
echo To build all types, do not pass a parameter.
exit /b 1
)
:parsingdone
echo Building all the following types: !BUILD_TYPE!

(for %%b in (!BUILD_TYPE!) do (
setlocal enabledelayedexpansion
echo.
echo %%b : Building dive android layer
Expand Down Expand Up @@ -51,19 +63,18 @@ set startTime=%time%
))

pushd !GFXR_ROOT_DIR!
(for %%b in (%BUILD_TYPE%) do (
(for %%b in (!BUILD_TYPE!) do (
setlocal enabledelayedexpansion
echo.
echo %%b : Building gfxr android layer
set build=%%b

echo GFXR_ROOT_DIR: !GFXR_ROOT_DIR!
call gradlew assemble!build!
call gradlew assemble!build! --console=verbose
))
popd


(for %%b in (%BUILD_TYPE%) do (
(for %%b in (!BUILD_TYPE!) do (
setlocal enabledelayedexpansion
if "%%b" == "Release" set build_lowercase=release
if "%%b" == "Debug" set build_lowercase=debug
Expand All @@ -78,14 +89,20 @@ popd
echo Extracting gfxr android layer into build_android
set GFXR_LAYER_SRC=!GFXR_ROOT_DIR!\\layer\\build\\outputs\\aar\\layer-!build_lowercase!.aar
set GFXR_LAYER_DST=!GFXR_BUILD_DIR!\\layer
if not exist !GFXR_LAYER_DST! md !GFXR_LAYER_DST!
if exist !GFXR_LAYER_DST! rm -rf !GFXR_LAYER_DST!
if not !ERRORLEVEL!==0 exit /b 1
md !GFXR_LAYER_DST!
if not !ERRORLEVEL!==0 exit /b 1
tar -xf !GFXR_LAYER_SRC! -C !GFXR_LAYER_DST!
if not !ERRORLEVEL!==0 exit /b 1

echo Copying gfxr android replay into build_android
set GFXR_REPLAY_SRC=!GFXR_ROOT_DIR!\\tools\\replay\\build\\outputs\\apk\\!build_lowercase!
set GFXR_REPLAY_DST=!GFXR_BUILD_DIR!\\tools\\replay
if not exist !GFXR_REPLAY_DST! md !GFXR_REPLAY_DST!
copy !GFXR_REPLAY_SRC! !GFXR_REPLAY_DST!
if exist !GFXR_REPLAY_DST! rm -rf !GFXR_REPLAY_DST!
if not !ERRORLEVEL!==0 exit /b 1
xcopy /i !GFXR_REPLAY_SRC! !GFXR_REPLAY_DST!
if not !ERRORLEVEL!==0 exit /b 1
))

echo Start Time: %startTime%
Expand Down
22 changes: 19 additions & 3 deletions scripts/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ PROJECT_ROOT="${PROJECT_ROOT%/*}/.."
readonly PROJECT_ROOT="$(readlink -f ${PROJECT_ROOT})"
readonly BUILD_DIR_ROOT=${PROJECT_ROOT}/build_android
readonly SRC_DIR=${PROJECT_ROOT}
readonly BUILD_TYPE=(Debug Release)
BUILD_TYPE=(Debug Release)
readonly START_TIME=`date +%r`

for build in "${BUILD_TYPE[@]}"
if [ $# -ne 0 ]; then
if [ "$1" = "Debug" ] || [ "$1" = "Release" ]; then
BUILD_TYPE=$1
else
echo "Invalid parameter passed for BUILD_TYPE: $1"
echo "Valid options: 'Debug', 'Release'"
echo "To build all types, do not pass a parameter."
exit 1
fi
fi
echo "Building all the following types: $BUILD_TYPE"

for build in "${BUILD_TYPE}"
do
BUILD_DIR=${BUILD_DIR_ROOT}/${build}
mkdir -p ${BUILD_DIR}
Expand Down Expand Up @@ -50,4 +63,7 @@ do
cmake --install . || exit 1
fi
popd
done
done

echo "Start Time:" ${START_TIME}
echo "Finish Time:" `date +%r`

0 comments on commit 79e7368

Please sign in to comment.