Skip to content

Commit 1bee4d6

Browse files
authored
JNI Builds Enhancements & CMake Dependency Enhancements (#1237)
* Build optimizations * Build PIC in JNI only path * Make parallel optional
1 parent ebd504d commit 1bee4d6

File tree

10 files changed

+262
-92
lines changed

10 files changed

+262
-92
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ jobs:
4545
4646
mac-os-build-gcc:
4747
runs-on: macos-13
48+
strategy:
49+
matrix:
50+
parallel-build:
51+
- ON
52+
- OFF
53+
54+
fail-fast: false
55+
4856
permissions:
4957
id-token: write
5058
contents: read
@@ -62,17 +70,25 @@ jobs:
6270
- name: Build repository
6371
run: |
6472
mkdir build && cd build
65-
cmake .. -DBUILD_TEST=TRUE -DCMAKE_INSTALL_PREFIX=.
66-
make
67-
make install
73+
cmake .. -DBUILD_TEST=TRUE -DCMAKE_INSTALL_PREFIX=. -DPARALLEL_BUILD=${{ matrix.parallel-build }}
74+
75+
if [[ "${{ matrix.parallel-build }}" == 'ON' ]]; then
76+
make
77+
make -j install
78+
else
79+
make
80+
make install
81+
fi
6882
- name: Configure AWS Credentials
83+
if: ${{ matrix.parallel-build == 'ON' }} # Only need to run the tests once
6984
uses: aws-actions/configure-aws-credentials@v1-node16
7085
with:
7186
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
7287
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
7388
aws-region: ${{ secrets.AWS_REGION }}
7489
role-duration-seconds: 10800
7590
- name: Run tests
91+
if: ${{ matrix.parallel-build == 'ON' }}
7692
run: |
7793
cd build
7894
./tst/producerTest
@@ -242,6 +258,15 @@ jobs:
242258

243259
ubuntu-gcc:
244260
runs-on: ubuntu-20.04
261+
262+
strategy:
263+
matrix:
264+
parallel-build:
265+
- ON
266+
- OFF
267+
268+
fail-fast: false
269+
245270
env:
246271
AWS_KVS_LOG_LEVEL: 2
247272
CC: gcc
@@ -260,17 +285,24 @@ jobs:
260285
- name: Build repository
261286
run: |
262287
mkdir build && cd build
263-
cmake .. -DBUILD_TEST=TRUE -DBUILD_GSTREAMER_PLUGIN=TRUE -DBUILD_JNI=TRUE -DCMAKE_INSTALL_PREFIX=.
264-
make
265-
make install
288+
cmake .. -DBUILD_TEST=TRUE -DBUILD_GSTREAMER_PLUGIN=TRUE -DBUILD_JNI=TRUE -DCMAKE_INSTALL_PREFIX=. -DPARALLEL_BUILD=${{ matrix.parallel-build }}
289+
290+
if [[ "${{ matrix.parallel-build }}" == 'ON' ]]; then
291+
make -j install
292+
else
293+
make install
294+
fi
295+
266296
- name: Configure AWS Credentials
297+
if: ${{ matrix.parallel-build == 'ON' }} # Only need to run the tests once
267298
uses: aws-actions/configure-aws-credentials@v1-node16
268299
with:
269300
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
270301
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
271302
aws-region: ${{ secrets.AWS_REGION }}
272303
role-duration-seconds: 10800
273304
- name: Run tests
305+
if: ${{ matrix.parallel-build == 'ON' }}
274306
run: |
275307
cd build
276308
ulimit -c unlimited -S

.github/workflows/jni.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Producer CPP JNI Builds
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
9+
branches:
10+
- develop
11+
- master
12+
13+
jobs:
14+
mac-os:
15+
strategy:
16+
matrix:
17+
config:
18+
- name: Intel x86_64
19+
runner: macos-13
20+
- name: Apple Silicon
21+
runner: macos-15
22+
- name: Ubuntu 22.04
23+
runner: ubuntu-latest
24+
container: public.ecr.aws/ubuntu/ubuntu:22.04_stable
25+
- name: Ubuntu 20.04
26+
runner: ubuntu-latest
27+
container: public.ecr.aws/ubuntu/ubuntu:20.04_stable
28+
29+
java:
30+
- 11
31+
- 17
32+
- 21
33+
34+
fail-fast: false
35+
36+
name: JNI ${{ matrix.config.name }} (Java ${{ matrix.java }})
37+
runs-on: ${{ matrix.config.runner }}
38+
container: ${{ matrix.config.container || '' }}
39+
40+
env:
41+
DEBIAN_FRONTEND: noninteractive
42+
43+
steps:
44+
- name: Setup XCode
45+
if: ${{ runner.os == 'macOS' }}
46+
uses: maxim-lobanov/setup-xcode@v1
47+
with:
48+
xcode-version: latest-stable
49+
50+
- name: Install Dependencies (Linux only)
51+
if: runner.os == 'Linux'
52+
run: |
53+
apt-get update
54+
apt-get install -y git cmake build-essential
55+
56+
- name: Set up Java (JDK ${{ matrix.java }})
57+
uses: actions/setup-java@v4
58+
with:
59+
distribution: 'corretto'
60+
java-version: ${{ matrix.java }}
61+
62+
- name: Clone repository
63+
uses: actions/checkout@v4
64+
65+
- name: Build JNI (CMake)
66+
run: |
67+
mkdir build && cd build
68+
cmake .. -DBUILD_JNI_ONLY=ON
69+
70+
# Note: Dependencies on/off shouldn't make any difference since
71+
# the only dependency for the JNI is PIC
72+
73+
- name: Build JNI (make)
74+
working-directory: ./build
75+
run: |
76+
make -j

CMake/Dependencies/libautoconf-CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ find_program(MAKE_EXE NAMES make)
77
include(ExternalProject)
88
ExternalProject_Add(project_libautoconf
99
URL http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
10+
GIT_SHALLOW TRUE
11+
GIT_PROGRESS TRUE
1012
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
1113
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libautoconf/configure --prefix=${OPEN_SRC_INSTALL_PREFIX}
1214
BUILD_COMMAND ${MAKE_EXE} -j 4

CMake/Dependencies/libautomake-CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ find_program(MAKE_EXE NAMES make)
77
include(ExternalProject)
88
ExternalProject_Add(project_libautomake
99
URL http://ftp.gnu.org/gnu/automake/automake-1.16.1.tar.gz
10+
GIT_SHALLOW TRUE
11+
GIT_PROGRESS TRUE
1012
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
1113
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/build/src/project_libautomake/configure --prefix=${OPEN_SRC_INSTALL_PREFIX}
1214
BUILD_COMMAND ${MAKE_EXE} -j 4

CMake/Dependencies/libkvscproducer-CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ include(ExternalProject)
88
ExternalProject_Add(libkvscproducer-download
99
GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git
1010
GIT_TAG v1.5.3
11+
GIT_SHALLOW TRUE
12+
GIT_PROGRESS TRUE
1113
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvscproducer-src"
1214
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvscproducer-build"
1315
CONFIGURE_COMMAND ""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.6.3)
2+
3+
project(libkvspic-download LANGUAGES C)
4+
5+
include(ExternalProject)
6+
7+
# Normally, PIC is built through Producer-C
8+
# When building the JNI only, Producer-C is not used at all, meaning
9+
# that we need to download PIC directly.
10+
ExternalProject_Add(libkvspic-download
11+
GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-pic.git
12+
GIT_TAG v1.2.0
13+
GIT_SHALLOW TRUE
14+
GIT_PROGRESS TRUE
15+
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvspic-src"
16+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/kvspic-build"
17+
CMAKE_ARGS
18+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
19+
CONFIGURE_COMMAND ""
20+
BUILD_COMMAND ""
21+
INSTALL_COMMAND ""
22+
TEST_COMMAND ""
23+
)

CMake/Dependencies/liblog4cplus-CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ if (WIN32)
2626
ExternalProject_Add(project_log4cplus
2727
GIT_REPOSITORY https://github.com/log4cplus/log4cplus
2828
GIT_TAG REL_2_0_1
29+
GIT_SHALLOW TRUE
30+
GIT_PROGRESS TRUE
2931
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
3032
TEST_COMMAND ""
3133
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${OPEN_SRC_INSTALL_PREFIX} -DLOG4CPLUS_BUILD_TESTING=0 -DLOG4CPLUS_BUILD_LOGGINGSERVER=0 -DUNICODE=0 -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
@@ -34,6 +36,8 @@ else()
3436
ExternalProject_Add(project_log4cplus
3537
GIT_REPOSITORY https://github.com/log4cplus/log4cplus
3638
GIT_TAG REL_2_0_1
39+
GIT_SHALLOW TRUE
40+
GIT_PROGRESS TRUE
3741
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
3842
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
3943
BUILD_COMMAND ${MAKE_EXE}

CMake/Utilities.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# only fetch target repo for add_subdirectory later
22
function(fetch_repo lib_name)
33
set(supported_libs
4+
kvspic
45
kvscproducer)
56
list(FIND supported_libs ${lib_name} index)
67
if(${index} EQUAL -1)
78
message(WARNING "${lib_name} is not supported for fetch_repo")
89
return()
910
endif()
1011

12+
if (WIN32 OR NOT PARALLEL_BUILD)
13+
set(PARALLEL_BUILD "") # No parallel build for Windows
14+
else()
15+
set(PARALLEL_BUILD "--parallel") # Enable parallel builds for Unix-like systems
16+
endif()
17+
1118
# build library
1219
configure_file(
1320
./CMake/Dependencies/lib${lib_name}-CMakeLists.txt
@@ -21,7 +28,7 @@ function(fetch_repo lib_name)
2128
message(FATAL_ERROR "CMake step for lib${lib_name} failed: ${result}")
2229
endif()
2330
execute_process(
24-
COMMAND ${CMAKE_COMMAND} --build .
31+
COMMAND ${CMAKE_COMMAND} --build . ${PARALLEL_BUILD}
2532
RESULT_VARIABLE result
2633
WORKING_DIRECTORY ${DEPENDENCY_DOWNLOAD_PATH}/lib${lib_name})
2734
if(result)
@@ -34,6 +41,7 @@ function(build_dependency lib_name)
3441
set(supported_libs
3542
autoconf
3643
automake
44+
kvspic
3745
log4cplus)
3846
list(FIND supported_libs ${lib_name} index)
3947
if(${index} EQUAL -1)
@@ -73,6 +81,12 @@ function(build_dependency lib_name)
7381

7482
file(REMOVE_RECURSE ${KINESIS_VIDEO_OPEN_SOURCE_SRC}/lib${lib_name})
7583

84+
if (WIN32 OR NOT PARALLEL_BUILD)
85+
set(PARALLEL_BUILD "") # No parallel build for Windows
86+
else()
87+
set(PARALLEL_BUILD "--parallel") # Enable parallel builds for Unix-like systems
88+
endif()
89+
7690
# build library
7791
configure_file(
7892
${CMAKE_CURRENT_SOURCE_DIR}/CMake/Dependencies/lib${lib_name}-CMakeLists.txt
@@ -87,7 +101,7 @@ function(build_dependency lib_name)
87101
message(FATAL_ERROR "CMake step for lib${lib_name} failed: ${result}")
88102
endif()
89103
execute_process(
90-
COMMAND ${CMAKE_COMMAND} --build .
104+
COMMAND ${CMAKE_COMMAND} --build . ${PARALLEL_BUILD}
91105
RESULT_VARIABLE result
92106
WORKING_DIRECTORY ${KINESIS_VIDEO_OPEN_SOURCE_SRC}/lib${lib_name})
93107
if(result)

0 commit comments

Comments
 (0)