Skip to content

Commit 8a9da3d

Browse files
committed
Use prebuilt protoc
1 parent df54728 commit 8a9da3d

File tree

6 files changed

+42
-61
lines changed

6 files changed

+42
-61
lines changed

.github/workflows/build_pull_request.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@ jobs:
2727
ndk-version: r27c
2828
add-to-path: false
2929

30+
- name: Get protoc
31+
run: |
32+
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip
33+
sudo unzip -p protoc-*.zip bin/protoc -d /usr/local/bin/
34+
3035
- name: Patch
3136
run: bash ./patch.sh
3237

33-
- name: Compile protoc
34-
run: |
35-
mkdir -p src/protobuf/build
36-
pushd src/protobuf/build
37-
cmake -GNinja -Dprotobuf_BUILD_TESTS=OFF ..
38-
ninja -j$(nproc --all)
39-
popd
40-
4138
- name: Compile aapt2
4239
env:
4340
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
44-
PROTOC_PATH: "/${{ github.workspace }}/src/protobuf/build/protoc"
4541
run: bash ./build.sh ${{ matrix.target_arch }}
4642

4743
- name: Upload artifacts

.github/workflows/release.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,17 @@ jobs:
2828
ndk-version: r27c
2929
add-to-path: false
3030

31+
- name: Get protoc
32+
run: |
33+
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip
34+
sudo unzip -p protoc-*.zip bin/protoc -d /usr/local/bin/
35+
3136
- name: Patch
3237
run: bash ./patch.sh
3338

34-
- name: Compile protoc
35-
run: |
36-
mkdir -p src/protobuf/build
37-
pushd src/protobuf/build
38-
cmake -GNinja -Dprotobuf_BUILD_TESTS=OFF ..
39-
ninja -j$(nproc --all)
40-
popd
41-
4239
- name: Compile aapt2
4340
env:
4441
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
45-
PROTOC_PATH: "${{ github.workspace }}/src/protobuf/build/protoc"
4642
run: bash ./build.sh ${{ matrix.target_arch }}
4743

4844
- name: Upload artifacts
@@ -51,7 +47,7 @@ jobs:
5147
name: aapt2-${{ matrix.target_arch }}
5248
path: ${{ github.workspace }}/build/bin/aapt2-*
5349
if-no-files-found: error
54-
50+
5551
release:
5652
needs: build
5753
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ set(SRC ${PROJECT_SOURCE_DIR}/src)
2626
# 64-bit off_t for lseek.
2727
add_definitions(-D_FILE_OFFSET_BITS=64)
2828

29-
if(NOT DEFINED PROTOC_PATH)
30-
message(FATAL_ERROR "PROTOC_PATH undefined, please make sure to build and install protoc from the cloned submodule." )
31-
endif()
32-
33-
set(PROTOC_COMPILER ${PROTOC_PATH})
34-
35-
if(NOT EXISTS ${PROTOC_COMPILER})
36-
unset(PROTOC_PATH CACHE)
37-
message(FATAL_ERROR "Invalid protoc: ${PROTOC_COMPILER}, please check if the path is correct")
38-
endif()
29+
# protoc options
30+
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
31+
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
32+
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "" FORCE)
33+
set(protobuf_BUILD_LIBPROTOC ON CACHE BOOL "" FORCE)
3934

4035
# thrid-party libraries
4136
add_subdirectory(src/boringssl EXCLUDE_FROM_ALL)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
This repository contains a workflow to build the aapt2 binaries for Android.
66

7+
Currently, the submodules are pinned to platform-tools 35.0.2 of AOSP source code. `src/base` example:
8+
https://android.googlesource.com/platform/frameworks/base/+/refs/tags/platform-tools-35.0.2
9+
710
# Build
811

912
## Fetch submodules

build-tools/aapt2.cmake

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@ set(AAPT2_PROTO_DIR ${SRC}/base/tools/aapt2)
55

66
file(GLOB_RECURSE PROTO_FILES ${AAPT2_PROTO_DIR}/*.proto)
77

8+
find_package(Protobuf)
9+
10+
if(NOT EXISTS ${Protobuf_PROTOC_EXECUTABLE})
11+
message(FATAL_ERROR "Invalid protoc: ${Protobuf_PROTOC_EXECUTABLE}")
12+
endif()
13+
14+
815
foreach(proto ${PROTO_FILES})
916
get_filename_component(FIL_WE ${proto} NAME_WE)
1017

11-
if(DEFINED PROTOC_PATH)
12-
# Execute the protoc command to generate the proto targets for host arch.
13-
execute_process(
14-
COMMAND ${PROTOC_COMPILER} ${proto}
15-
--proto_path=${AAPT2_PROTO_DIR}
16-
--cpp_out=${AAPT2_PROTO_DIR}
17-
COMMAND_ECHO STDOUT
18-
RESULT_VARIABLE RESULT
19-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
20-
)
21-
22-
if(RESULT EQUAL 0)
23-
message(STATUS "generate cpp file ${TARGET_CPP_FILE}")
24-
message(STATUS "generate head file ${TARGET_HEAD_FILE}")
25-
endif()
18+
# Execute the protoc command to generate the proto targets for host arch.
19+
execute_process(
20+
COMMAND ${Protobuf_PROTOC_EXECUTABLE} ${proto}
21+
--proto_path=${AAPT2_PROTO_DIR}
22+
--cpp_out=${AAPT2_PROTO_DIR}
23+
COMMAND_ECHO STDOUT
24+
RESULT_VARIABLE RESULT
25+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
26+
)
27+
28+
if(RESULT EQUAL 0)
29+
message(STATUS "generate cpp file ${TARGET_CPP_FILE}")
30+
message(STATUS "generate head file ${TARGET_HEAD_FILE}")
2631
endif()
2732

2833
set(TARGET_CPP_FILE "${AAPT2_PROTO_DIR}/${FIL_WE}.pb.cc")
@@ -34,10 +39,9 @@ foreach(proto ${PROTO_FILES})
3439
endif()
3540
endforeach()
3641

37-
if(DEFINED PROTOC_PATH)
38-
set_source_files_properties(${AAPT2_PROTO_SRC} PROPERTIES GENERATED TRUE)
39-
set_source_files_properties(${AAPT2_PROTO_HDRS} PROPERTIES GENERATED TRUE)
40-
endif()
42+
set_source_files_properties(${AAPT2_PROTO_SRC} PROPERTIES GENERATED TRUE)
43+
set_source_files_properties(${AAPT2_PROTO_HDRS} PROPERTIES GENERATED TRUE)
44+
4145
set_source_files_properties(${AAPT2_PROTO_SRC} ${AAPT2_PROTO_HDRS}
4246
PROPERTIES GENERATED TRUE)
4347
# ========================= aapt2 proto ============================

build.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ if [[ -z "${ANDROID_NDK}" ]]; then
2525
exit 1
2626
fi
2727

28-
# Check if PROTOC_PATH is missing or if the file doesn't exist
29-
if [[ -z "$PROTOC_PATH" || ! -f "$PROTOC_PATH" ]]; then
30-
echo "Error: PROTOC_PATH is missing in env or file does not exist."
31-
help
32-
exit 1
33-
fi
34-
3528
architecture="$1"
3629

3730
if [[ ! " ${ARCHITECTURES[@]} " =~ " $architecture " ]]; then
@@ -50,15 +43,9 @@ cmake -GNinja \
5043
-DANDROID_PLATFORM="android-$API" \
5144
-DCMAKE_ANDROID_ARCH_ABI="$architecture" \
5245
-DANDROID_ABI="$architecture" \
53-
-DPROTOC_PATH="$PROTOC_PATH" \
5446
-DCMAKE_SYSTEM_NAME=Android \
5547
-DANDROID_ARM_NEON=ON \
5648
-DCMAKE_BUILD_TYPE=Release \
57-
-Dprotobuf_BUILD_TESTS=OFF \
58-
-DABSL_PROPAGATE_CXX_STD=ON \
59-
-Dprotobuf_BUILD_SHARED_LIBS=OFF \
60-
-Dprotobuf_BUILD_PROTOC_BINARIES=OFF \
61-
-Dprotobuf_BUILD_LIBPROTOC=ON \
6249
-DPNG_SHARED=OFF \
6350
-DZLIB_USE_STATIC_LIBS=ON
6451

0 commit comments

Comments
 (0)