Skip to content

Commit ec490c0

Browse files
authored
stand-alone sample (#148)
#### *Issue #, if available:* #147 #### *Description of changes:* - Added stand-alone sample - CI will build the stand-alone samples for testing as well
1 parent dec3644 commit ec490c0

File tree

7 files changed

+1179
-74
lines changed

7 files changed

+1179
-74
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: CI
33
on:
44
push:
55
branches:
6-
- '*'
7-
- '!master'
6+
- "*"
7+
- "!master"
88

99
env:
1010
BUILDER_VERSION: v0.6.5
@@ -25,87 +25,87 @@ jobs:
2525
- manylinux2014-x64
2626
- manylinux2014-x86
2727
steps:
28-
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
29-
- name: Build ${{ env.PACKAGE_NAME }}
30-
run: |
31-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
32-
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ matrix.image }}:${{ env.BUILDER_VERSION }}
33-
docker pull $DOCKER_IMAGE
34-
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }}
28+
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
29+
- name: Build ${{ env.PACKAGE_NAME }}
30+
run: |
31+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
32+
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ matrix.image }}:${{ env.BUILDER_VERSION }}
33+
docker pull $DOCKER_IMAGE
34+
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }}
3535
3636
al2:
3737
runs-on: ubuntu-latest
3838
steps:
39-
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
40-
- name: Build ${{ env.PACKAGE_NAME }} + consumers
41-
run: |
42-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
43-
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }}
44-
docker pull $DOCKER_IMAGE
45-
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --spec=downstream
39+
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
40+
- name: Build ${{ env.PACKAGE_NAME }} + consumers
41+
run: |
42+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
43+
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }}
44+
docker pull $DOCKER_IMAGE
45+
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --spec=downstream
4646
4747
clang-compat:
4848
runs-on: ubuntu-latest
4949
strategy:
5050
matrix:
5151
version: [3, 6, 8, 9]
5252
steps:
53-
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
54-
- name: Build ${{ env.PACKAGE_NAME }}
55-
run: |
56-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
57-
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
58-
docker pull $DOCKER_IMAGE
59-
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=clang-${{ matrix.version }} --config Debug
53+
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
54+
- name: Build ${{ env.PACKAGE_NAME }}
55+
run: |
56+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
57+
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
58+
docker pull $DOCKER_IMAGE
59+
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=clang-${{ matrix.version }} --config Debug
6060
6161
gcc-compat:
6262
runs-on: ubuntu-latest
6363
strategy:
6464
matrix:
6565
version: [4.8, 5, 6, 7, 8]
6666
steps:
67-
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
68-
- name: Build ${{ env.PACKAGE_NAME }}
69-
run: |
70-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
71-
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
72-
docker pull $DOCKER_IMAGE
73-
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=gcc-${{ matrix.version }}
67+
# We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages
68+
- name: Build ${{ env.PACKAGE_NAME }}
69+
run: |
70+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
71+
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
72+
docker pull $DOCKER_IMAGE
73+
docker run --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --compiler=gcc-${{ matrix.version }}
7474
7575
windows-vs16:
7676
runs-on: windows-latest
7777
steps:
78-
- name: Build ${{ env.PACKAGE_NAME }} + consumers
79-
run: |
80-
md D:\a\work
81-
cd D:\a\work
82-
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder.pyz')"
83-
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
78+
- name: Build ${{ env.PACKAGE_NAME }} + consumers
79+
run: |
80+
md D:\a\work
81+
cd D:\a\work
82+
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder.pyz')"
83+
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
8484
8585
windows-vs14:
8686
runs-on: windows-latest
8787
strategy:
8888
matrix:
8989
arch: [x86, x64]
9090
steps:
91-
- uses: ilammy/msvc-dev-cmd@v1
92-
with:
93-
toolset: 14.0
94-
arch: ${{ matrix.arch }}
95-
uwp: false
96-
spectre: true
97-
- name: Build ${{ env.PACKAGE_NAME }} + consumers
98-
run: |
99-
md D:\a\work
100-
cd D:\a\work
101-
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
102-
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
91+
- uses: ilammy/msvc-dev-cmd@v1
92+
with:
93+
toolset: 14.0
94+
arch: ${{ matrix.arch }}
95+
uwp: false
96+
spectre: true
97+
- name: Build ${{ env.PACKAGE_NAME }} + consumers
98+
run: |
99+
md D:\a\work
100+
cd D:\a\work
101+
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
102+
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
103103
104104
osx:
105105
runs-on: macos-latest
106106
steps:
107-
- name: Build ${{ env.PACKAGE_NAME }} + consumers
108-
run: |
109-
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder')"
110-
chmod a+x builder
111-
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream
107+
- name: Build ${{ env.PACKAGE_NAME }} + consumers
108+
run: |
109+
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz', 'builder')"
110+
chmod a+x builder
111+
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream

builder.json

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
11
{
2-
"name": "aws-iot-device-sdk-cpp-v2",
3-
"!cmake_args": [
4-
"-DBUILD_DEPS=ON",
5-
"-DPERFORM_HEADER_CHECK=OFF",
6-
"-DS2N_NO_PQ_ASM=ON"
7-
],
8-
"targets": {
9-
"linux" : {
10-
"imports": [
11-
"s2n"
12-
]
13-
}
14-
},
15-
"search_dirs": ["crt"],
16-
"hosts": {
17-
"manylinux": {
18-
"architectures": {
19-
"x86": {
20-
"!yum_compiler_packages": []
21-
}
22-
}
2+
"name": "aws-iot-device-sdk-cpp-v2",
3+
"!cmake_args": [
4+
"-DBUILD_DEPS=ON",
5+
"-DPERFORM_HEADER_CHECK=OFF",
6+
"-DS2N_NO_PQ_ASM=ON"
7+
],
8+
"targets": {
9+
"linux": {
10+
"imports": ["s2n"]
11+
}
12+
},
13+
"search_dirs": ["crt"],
14+
"hosts": {
15+
"manylinux": {
16+
"architectures": {
17+
"x86": {
18+
"!yum_compiler_packages": []
2319
}
20+
}
2421
}
22+
},
23+
"test_steps": [
24+
[
25+
"mkdir",
26+
"build_shadow"
27+
],
28+
[
29+
"cmake",
30+
"--version"
31+
],
32+
[
33+
"cmake",
34+
"-Bbuild_shadow",
35+
"-Hsamples/stand-alone-samples/shadow/shadow_sync/",
36+
"-DCMAKE_INSTALL_PREFIX={install_dir}",
37+
"-DCMAKE_PREFIX_PATH={install_dir}",
38+
"-DCMAKE_BUILD_TYPE=Release",
39+
"-DLibCrypto_INCLUDE_DIR={deps_dir}/libcrypto/include",
40+
"-DLibCrypto_SHARED_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.so",
41+
"-DLibCrypto_STATIC_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.a"
42+
],
43+
[ "cmake", "--build", "build_shadow", "--config", "Release" ],
44+
[
45+
"mkdir",
46+
"build_pubsub"
47+
],
48+
[
49+
"cmake",
50+
"-Bbuild_pubsub",
51+
"-Hsamples/stand-alone-samples/basic_pub_sub/",
52+
"-DCMAKE_INSTALL_PREFIX={install_dir}",
53+
"-DCMAKE_PREFIX_PATH={install_dir}",
54+
"-DCMAKE_BUILD_TYPE=Release",
55+
"-DLibCrypto_INCLUDE_DIR={deps_dir}/libcrypto/include",
56+
"-DLibCrypto_SHARED_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.so",
57+
"-DLibCrypto_STATIC_LIBRARY={deps_dir}/libcrypto/lib/libcrypto.a"
58+
],
59+
[ "cmake", "--build", "build_pubsub", "--config", "Release" ]
60+
]
2561
}

samples/stand-alone-samples/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Stand-alone Samples
2+
3+
## building instruction
4+
5+
Firstly, build the project with the following instruction.
6+
7+
``` sh
8+
mkdir sdk-cpp-workspace
9+
cd sdk-cpp-workspace
10+
git clone --recursive https://github.com/aws/aws-iot-device-sdk-cpp-v2.git
11+
mkdir aws-iot-device-sdk-cpp-v2-build
12+
cd aws-iot-device-sdk-cpp-v2-build
13+
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=ON -DCMAKE_BUILD_TYPE=Release ../aws-iot-device-sdk-cpp-v2
14+
cmake --build . --config Release --target install
15+
```
16+
17+
Then, change directory into stand-alone-samples.
18+
19+
In stand-alone-samples/shadow/shadow_sync/ or stand-alone-samples/basic_pub_sub/:
20+
21+
``` sh
22+
mkdir build
23+
cd build
24+
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE=Release ..
25+
cmake --build . --config Release
26+
```
27+
28+
Note: for linux machine, you may need to indicate the path to libcrypto, because of the dependency of S2N. Following commands as below:
29+
30+
``` sh
31+
mkdir build
32+
cd build
33+
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 ..
34+
cmake --build . --config Release
35+
```
36+
37+
To debug, just change every mentioned `Release` to `Debug`.
38+
The binary executable file will be under build/. for Linux/Mac, and under build/release for Windows.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(basic-pub-sub CXX)
3+
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")
5+
6+
file(GLOB PUB_SUB_SRC
7+
"*.cpp"
8+
)
9+
10+
add_executable(${PROJECT_NAME} ${PUB_SUB_SRC})
11+
12+
set_target_properties(${PROJECT_NAME} PROPERTIES
13+
LINKER_LANGUAGE CXX
14+
CXX_STANDARD 11)
15+
16+
if(COMMAND cmake_policy)
17+
cmake_policy(SET CMP0003 NEW)
18+
endif(COMMAND cmake_policy)
19+
20+
#set warnings
21+
if (MSVC)
22+
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
23+
else ()
24+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
25+
endif ()
26+
27+
find_package(aws-crt-cpp REQUIRED)
28+
29+
target_link_libraries(${PROJECT_NAME} AWS::aws-crt-cpp)

0 commit comments

Comments
 (0)