Skip to content

Commit

Permalink
stand-alone sample (#148)
Browse files Browse the repository at this point in the history
#### *Issue #, if available:*

#147

#### *Description of changes:*

- Added stand-alone sample
- CI will build the stand-alone samples for testing as well
  • Loading branch information
TingDaoK committed Oct 14, 2020
1 parent dec3644 commit ec490c0
Show file tree
Hide file tree
Showing 7 changed files with 1,179 additions and 74 deletions.
106 changes: 53 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI
on:
push:
branches:
- '*'
- '!master'
- "*"
- "!master"

env:
BUILDER_VERSION: v0.6.5
Expand All @@ -25,87 +25,87 @@ jobs:
- manylinux2014-x64
- manylinux2014-x86
steps:
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ matrix.image }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }}
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ matrix.image }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }}
al2:
runs-on: ubuntu-latest
steps:
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --spec=downstream
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --spec=downstream
clang-compat:
runs-on: ubuntu-latest
strategy:
matrix:
version: [3, 6, 8, 9]
steps:
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=clang-${{ matrix.version }} --config Debug
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=clang-${{ matrix.version }} --config Debug
gcc-compat:
runs-on: ubuntu-latest
strategy:
matrix:
version: [4.8, 5, 6, 7, 8]
steps:
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=gcc-${{ matrix.version }}
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
- name: Build ${{ env.PACKAGE_NAME }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=gcc-${{ matrix.version }}
windows-vs16:
runs-on: windows-latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
md D:\a\work
cd D:\a\work
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
md D:\a\work
cd D:\a\work
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
windows-vs14:
runs-on: windows-latest
strategy:
matrix:
arch: [x86, x64]
steps:
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.0
arch: ${{ matrix.arch }}
uwp: false
spectre: true
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
md D:\a\work
cd D:\a\work
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.0
arch: ${{ matrix.arch }}
uwp: false
spectre: true
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
md D:\a\work
cd D:\a\work
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
osx:
runs-on: macos-latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream
78 changes: 57 additions & 21 deletions builder.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
{
"name": "aws-iot-device-sdk-cpp-v2",
"!cmake_args": [
"-DBUILD_DEPS=ON",
"-DPERFORM_HEADER_CHECK=OFF",
"-DS2N_NO_PQ_ASM=ON"
],
"targets": {
"linux" : {
"imports": [
"s2n"
]
}
},
"search_dirs": ["crt"],
"hosts": {
"manylinux": {
"architectures": {
"x86": {
"!yum_compiler_packages": []
}
}
"name": "aws-iot-device-sdk-cpp-v2",
"!cmake_args": [
"-DBUILD_DEPS=ON",
"-DPERFORM_HEADER_CHECK=OFF",
"-DS2N_NO_PQ_ASM=ON"
],
"targets": {
"linux": {
"imports": ["s2n"]
}
},
"search_dirs": ["crt"],
"hosts": {
"manylinux": {
"architectures": {
"x86": {
"!yum_compiler_packages": []
}
}
}
},
"test_steps": [
[
"mkdir",
"build_shadow"
],
[
"cmake",
"--version"
],
[
"cmake",
"-Bbuild_shadow",
"-Hsamples/stand-alone-samples/shadow/shadow_sync/",
"-DCMAKE_INSTALL_PREFIX={install_dir}",
"-DCMAKE_PREFIX_PATH={install_dir}",
"-DCMAKE_BUILD_TYPE=Release",
"-DLibCrypto_INCLUDE_DIR={deps_dir}/libcrypto/include",
"-DLibCrypto_SHARED_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.so",
"-DLibCrypto_STATIC_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.a"
],
[ "cmake", "--build", "build_shadow", "--config", "Release" ],
[
"mkdir",
"build_pubsub"
],
[
"cmake",
"-Bbuild_pubsub",
"-Hsamples/stand-alone-samples/basic_pub_sub/",
"-DCMAKE_INSTALL_PREFIX={install_dir}",
"-DCMAKE_PREFIX_PATH={install_dir}",
"-DCMAKE_BUILD_TYPE=Release",
"-DLibCrypto_INCLUDE_DIR={deps_dir}/libcrypto/include",
"-DLibCrypto_SHARED_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.so",
"-DLibCrypto_STATIC_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.a"
],
[ "cmake", "--build", "build_pubsub", "--config", "Release" ]
]
}
38 changes: 38 additions & 0 deletions samples/stand-alone-samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Stand-alone Samples

## building instruction

Firstly, build the project with the following instruction.

``` sh
mkdir sdk-cpp-workspace
cd sdk-cpp-workspace
git clone --recursive https://github.com/aws/aws-iot-device-sdk-cpp-v2.git
mkdir aws-iot-device-sdk-cpp-v2-build
cd aws-iot-device-sdk-cpp-v2-build
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=ON -DCMAKE_BUILD_TYPE=Release ../aws-iot-device-sdk-cpp-v2
cmake --build . --config Release --target install
```

Then, change directory into stand-alone-samples.

In stand-alone-samples/shadow/shadow_sync/ or stand-alone-samples/basic_pub_sub/:

``` sh
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
```

Note: for linux machine, you may need to indicate the path to libcrypto, because of the dependency of S2N. Following commands as below:

``` sh
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DLibCrypto_INCLUDE_DIR="<path to include dir>" -DLibCrypto_STATIC_LIBRARY="<path to libcrypto.a file>" -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
```

To debug, just change every mentioned `Release` to `Debug`.
The binary executable file will be under build/. for Linux/Mac, and under build/release for Windows.
29 changes: 29 additions & 0 deletions samples/stand-alone-samples/basic_pub_sub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.1)
project(basic-pub-sub CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB PUB_SUB_SRC
"*.cpp"
)

add_executable(${PROJECT_NAME} ${PUB_SUB_SRC})

set_target_properties(${PROJECT_NAME} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 11)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

#set warnings
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else ()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()

find_package(aws-crt-cpp REQUIRED)

target_link_libraries(${PROJECT_NAME} AWS::aws-crt-cpp)
Loading

0 comments on commit ec490c0

Please sign in to comment.