Skip to content

Commit 2e7baae

Browse files
committed
Improving sample-app build examples and removing internal deps from it
1 parent af7d416 commit 2e7baae

File tree

5 files changed

+97
-17
lines changed

5 files changed

+97
-17
lines changed

tools/CI/install-test/CMakeLists.txt

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
1-
cmake_minimum_required(VERSION 3.3)
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.13)
5+
# -- Preamble --
6+
project("sample_app"
7+
LANGUAGES CXX
8+
VERSION 1.0
9+
DESCRIPTION "A testing app using AWS SDK for C++"
10+
)
11+
12+
# -- Project wide setup --
13+
# Setting C++ minimum requirements
214
set(CMAKE_CXX_STANDARD 11)
3-
project(app LANGUAGES CXX)
15+
set(CMAKE_CXX_EXTENSIONS OFF)
16+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
17+
18+
# Setting build to hide symbols in targets by default
19+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
20+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
21+
22+
# Preventing writes to package registry by default
23+
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY YES)
24+
25+
# Validating config type and setting default if needed
26+
get_property(is_multi_conf_build GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
27+
if (NOT is_multi_conf_build)
28+
set(allowed_build_types Debug Release RelWithDebInfo MinSizeRel)
29+
# cmake-gui helper
30+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowed_build_types}")
31+
if (NOT CMAKE_BUILD_TYPE)
32+
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
33+
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
34+
elseif (NOT CMAKE_BUILD_TYPE IN_LIST allowed_build_types)
35+
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
36+
endif ()
37+
endif ()
38+
39+
# -- Dependencies --
440
find_package(AWSSDK REQUIRED COMPONENTS s3-crt)
5-
add_executable(${PROJECT_NAME} "main.cpp")
6-
if(MSVC AND BUILD_SHARED_LIBS)
7-
target_compile_definitions(${PROJECT_NAME} PUBLIC "USE_IMPORT_EXPORT")
8-
add_definitions(-DUSE_IMPORT_EXPORT)
9-
# Copy relevant AWS SDK for C++ libraries into the current binary directory for running and debugging.
10-
list(APPEND SERVICE_LIST s3-crt)
11-
AWSSDK_CPY_DYN_LIBS(SERVICE_LIST "" ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
12-
endif()
13-
set_compiler_flags(${PROJECT_NAME})
14-
set_compiler_warnings(${PROJECT_NAME})
15-
target_link_libraries(${PROJECT_NAME} ${AWSSDK_LINK_LIBRARIES})
41+
42+
# -- main build target --
43+
add_executable(app "main.cpp")
44+
target_link_libraries(app ${AWSSDK_LINK_LIBRARIES})
45+
target_include_directories(app PRIVATE ${AWSSDK_INCLUDE_DIRS})
46+
47+
# -- install target --
48+
include(GNUInstallDirs)
49+
set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME})
50+
51+
install(TARGETS app
52+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
53+
)

tools/scripts/build-tests/build-al2-sample-app.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ PREFIX_DIR="$1"
2525
echo "Building the Sample App"
2626

2727
mkdir "${PREFIX_DIR}/sample-build"
28+
mkdir "${PREFIX_DIR}/sample-install"
2829
cd "${PREFIX_DIR}/sample-build"
29-
cmake ../aws-sdk-cpp/tools/CI/install-test -G Ninja -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="${PREFIX_DIR}/al2-install"
30-
ninja-build
30+
cmake ../aws-sdk-cpp/tools/CI/install-test -G Ninja -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="${PREFIX_DIR}/al2-install" -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}/sample_install"
31+
cmake --build .
32+
cmake --build . --target install
3133

3234
if [ "${AUTORUN}" -eq 0 ]; then
3335
# Only continue if there is a scheduled autorun
@@ -43,5 +45,7 @@ aws configure set aws_secret_access_key $(echo "$sts" | jq -r '.[1]') --profile
4345
aws configure set aws_session_token $(echo "$sts" | jq -r '.[2]') --profile "$profile"
4446
aws configure list --profile "$profile"
4547
export AWS_PROFILE=$profile
48+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${PREFIX_DIR}/al2-install/lib64/"
4649
echo "Running the app"
50+
cd "${PREFIX_DIR}/sample_install/bin"
4751
./app

tools/scripts/build-tests/build-mac-sample-app.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ echo "Building the Sample App"
2626

2727
cd aws-sdk-cpp/tools/CI/install-test
2828
mkdir "${PREFIX_DIR}/sample-build"
29+
mkdir "${PREFIX_DIR}/sample-install"
2930
cd "${PREFIX_DIR}/sample-build"
30-
cmake ../aws-sdk-cpp/tools/CI/install-test -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="${PREFIX_DIR}/mac-install"
31+
cmake ../aws-sdk-cpp/tools/CI/install-test -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="${PREFIX_DIR}/mac-install" -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}/sample_install"
3132
cmake --build .
33+
cmake --install .
3234

3335
if [ "${AUTORUN}" -eq 0 ]; then
3436
# Only continue if there is a scheduled autorun
@@ -45,5 +47,7 @@ aws configure set aws_secret_access_key $(echo "$sts" | jq -r '.[1]') --profile
4547
aws configure set aws_session_token $(echo "$sts" | jq -r '.[2]') --profile "$profile"
4648
aws configure list --profile "$profile"
4749
export AWS_PROFILE=$profile
50+
export DYLD_LIBRARY_PATH=$CATAPULT_WORKSPACE_DIR/mac-install/lib
4851
echo "Running the app"
52+
cd "${PREFIX_DIR}/sample_install/bin"
4953
./app

tools/scripts/build-tests/build-windows-default.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
param($PREFIX_DIR)
99

1010
mkdir "${PREFIX_DIR}/win-build"
11+
mkdir "${PREFIX_DIR}/win-install"
1112
cd "${PREFIX_DIR}/win-build"
12-
&'C:\\Program Files\\CMake\\bin\\cmake.exe' ../aws-sdk-cpp
13+
&'C:\\Program Files\\CMake\\bin\\cmake.exe' ../aws-sdk-cpp -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}/win-install"
1314
&'C:\\Program Files\\CMake\\bin\\cmake.exe' --build . -j 8
15+
&'C:\\Program Files\\CMake\\bin\\cmake.exe' --build . --target install
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0.
4+
5+
# This script builds a sample app
6+
# Directories created and files are prefixed with PREFIX_DIR argument
7+
# SDK installation is expected to be in ${PREFIX_DIR}/mac-install and a clone of aws-sdk-cpp is expected to be in ${PREFIX_DIR}/aws-sdk-cpp
8+
# A AWS_ACCOUNT with proper role setup is required to run the built app, if passed argument, app is tried to run after build
9+
# Platform: Windows
10+
11+
param($PREFIX_DIR)
12+
13+
cd "${PREFIX_DIR}/aws-sdk-cpp/tools/CI/install-test"
14+
mkdir "${PREFIX_DIR}/sample-build"
15+
mkdir "${PREFIX_DIR}/sample-install"
16+
cd "${PREFIX_DIR}/sample-build"
17+
&'C:\\Program Files\\CMake\\bin\\cmake.exe' ../aws-sdk-cpp/tools/CI/install-test -DCMAKE_CXX_FLAGS="-ggdb -fsanitize=address" -DCMAKE_PREFIX_PATH="${PREFIX_DIR}/win-install" -DCMAKE_INSTALL_PREFIX="${PREFIX_DIR}/sample_install"
18+
&'C:\\Program Files\\CMake\\bin\\cmake.exe' --build .
19+
&'C:\\Program Files\\CMake\\bin\\cmake.exe' --build . --target install
20+
21+
echo "Setting the run environment"
22+
$TEST_ASSUME_ROLE_ARN = "arn:aws:iam::${env:AWS_ACCOUNT}:role/IntegrationTest"
23+
${env:TEST_LAMBDA_CODE_PATH} = "${env:PREFIX_DIR}/aws-sdk-cpp/tests/aws-cpp-sdk-lambda-integration-tests/resources"
24+
$sts = aws sts assume-role --role-arn "${TEST_ASSUME_ROLE_ARN}" --role-session-name "${env:AWS_ROLE_SESSION_NAME}" --query "Credentials.[AccessKeyId, SecretAccessKey, SessionToken]"
25+
$sts
26+
aws configure set aws_access_key_id (${sts}[1] -replace " " -replace "`"" -replace ",")
27+
aws configure set aws_secret_access_key (${sts}[2] -replace " " -replace "`"" -replace ",")
28+
aws configure set aws_session_token (${sts}[3] -replace " " -replace "`"" -replace ",")
29+
aws configure list
30+
# Run tests
31+
cd "${PREFIX_DIR}/sample_install/bin"
32+
app

0 commit comments

Comments
 (0)