Skip to content

Commit 05f67e2

Browse files
authored
Fixing build errors for Windows build (#192)
* Fixing build errors for Windows build * Updated the github workflow file to fix PR check errors.
1 parent feb59e2 commit 05f67e2

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
cd protobuf-3.17.3
4646
mkdir build_make
4747
cd build_make
48-
cmake ../cmake
48+
cmake ../cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5
4949
make
5050
sudo make install
5151
- name: Building localproxy
@@ -118,13 +118,12 @@ jobs:
118118
name: localproxy-ubuntu
119119
path: ${{ github.workspace }}/build/bin/localproxy
120120
windows:
121-
runs-on: windows-2019
121+
runs-on: windows-2022
122122
if: (github.event_name == 'push') || ((github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name != github.repository))
123123
steps:
124124
- name: Setup developer command prompt
125125
uses: ilammy/msvc-dev-cmd@v1
126126
with:
127-
toolset: 14.2
128127
arch: x64
129128
- name: Install OpenSSL
130129
run: |
@@ -163,7 +162,7 @@ jobs:
163162
Expand-Archive "boost_1_87_0.zip" -Force
164163
cd .\boost_1_87_0\boost_1_87_0\
165164
.\bootstrap.bat
166-
.\b2 toolset=msvc-14.2 address-model=64 install define=_WIN32_WINNT=0x0601 define=BOOST_WINAPI_VERSION_WIN7 link=static
165+
.\b2 toolset=msvc address-model=64 install define=_WIN32_WINNT=0x0A00 define=BOOST_WINAPI_VERSION_WIN10 link=static
167166
- name: Install protobuf
168167
run: |
169168
cd \
@@ -172,7 +171,7 @@ jobs:
172171
cd .\protobuf-all-3.17.3\protobuf-3.17.3\cmake\
173172
mkdir build
174173
cd build
175-
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../
174+
cmake -G "NMake Makefiles" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -Dprotobuf_MSVC_STATIC_RUNTIME=OFF ../
176175
nmake
177176
nmake install
178177
$env:Path += ";C:\Program Files (x86)\protobuf\bin"
@@ -188,7 +187,7 @@ jobs:
188187
run: |
189188
mkdir build
190189
cd build
191-
cmake -DBUILD_TESTS=OFF -DLINK_STATIC_OPENSSL=OFF -DBOOST_PKG_VERSION=1.84.0 -DWIN32_WINNT=0x0601 -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 16 2019" -A x64 ..\
190+
cmake -DBUILD_TESTS=OFF -DLINK_STATIC_OPENSSL=OFF -DBOOST_PKG_VERSION=1.87.0 -DWIN32_WINNT=0x0A00 -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 17 2022" -A x64 ..\
192191
msbuild localproxy.vcxproj -p:Configuration=Release
193192
- name: Upload Artifact
194193
uses: actions/upload-artifact@v4

CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
22

33
set(AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME localproxy)
44
set(AWS_TUNNEL_LOCAL_PROXY_LIB_NAME lproxy)
@@ -74,8 +74,27 @@ find_package(OpenSSL REQUIRED)
7474

7575
if(LINK_STATIC_OPENSSL)
7676
include_directories(${OPENSSL_INCLUDE_DIR})
77-
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
78-
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY})
77+
78+
# Check SSL library location
79+
get_target_property(SSL_LOCATION OpenSSL::SSL IMPORTED_LOCATION)
80+
if(SSL_LOCATION STREQUAL "SSL_LOCATION-NOTFOUND")
81+
get_target_property(SSL_LOCATION OpenSSL::SSL IMPORTED_LOCATION_RELEASE)
82+
if(SSL_LOCATION STREQUAL "SSL_LOCATION-NOTFOUND")
83+
message(FATAL_ERROR "Could not find OpenSSL SSL library location")
84+
endif()
85+
endif()
86+
87+
# Check Crypto library location
88+
get_target_property(CRYPTO_LOCATION OpenSSL::Crypto IMPORTED_LOCATION)
89+
if(CRYPTO_LOCATION STREQUAL "CRYPTO_LOCATION-NOTFOUND")
90+
get_target_property(CRYPTO_LOCATION OpenSSL::Crypto IMPORTED_LOCATION_RELEASE)
91+
if(CRYPTO_LOCATION STREQUAL "CRYPTO_LOCATION-NOTFOUND")
92+
message(FATAL_ERROR "Could not find OpenSSL Crypto library location")
93+
endif()
94+
endif()
95+
96+
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${SSL_LOCATION})
97+
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${CRYPTO_LOCATION})
7998
endif()
8099

81100
#########################################

windows-localproxy-build.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* `nmake`
2525
* `nmake install` (installs OpenSSL inside C:\Program Files\)
2626
* Update PATH environment variable to add the dll for openssl which is inside C:\Program Files\OpenSSL\bin
27-
* Note: In some x86_64 windows configurations, compiling for a 64 bit target may fail. You may instead install openssl through Chocolatey.
27+
* Note: In some x86_64 windows configurations, compiling for a 64 bit target may fail. You may instead install openssl through Chocolatey. The installation folder name might be OpenSSL-Win64. The project build command below should be changed correspondingly.
2828
* https://community.chocolatey.org/packages/openssl
2929
* Download and install catch2
3030
* Use Visual Studio native tool command prompt in admin mode.
@@ -52,22 +52,27 @@
5252
* Use Visual Studio native tool command prompt
5353
* `cd path/to/boost_1_87_0`
5454
* `bootstrap.bat`
55-
* `.\b2 toolset=msvc address-model={32 | 64} install define=BOOST_WINAPI_VERSION_WIN10` ( installs boost inside C:\)
56-
* Replace `BOOST_WINAPI_VERSION_WIN10` with the appropriate macro from [here](https://www.boost.org/doc/libs/develop/libs/winapi/doc/html/winapi/config.html)
55+
* `.\b2 toolset=msvc address-model={32 | 64} install define=BOOST_USE_WINAPI_VERSION=\<hex value> . ( installs boost inside C:\)
56+
* Replace \<hex value> with the appropriate macro from [here](https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers?redirectedfrom=MSDN#macros-for-conditional-declarations)
57+
* Example: 0x0A00 is for Win10, 0x0602 is for Win8
5758
* Download and build aws-iot-securetunneling-localproxy
5859
* Use Visual Studio native tool command prompt in admin mode
5960
* `git clone https://github.com/aws-samples/aws-iot-securetunneling-localproxy.git`
6061
* `cd aws-iot-securetunneling-localproxy`
6162
* `mkdir build`
6263
* `cd build`
63-
* Build the cmake project. Replace <_WIN32_WINNT> with the appropriate value based on [your OS from here](https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=vs-2019)
64+
* Build the cmake project. Replace \<hex value> with the appropriate value based on [your OS from here](https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=vs-2019), (e.g. 0x0A00 for Win10, 0x00602 for Win8). This value should be the same value used to build the Boost libraries.
65+
* For visual studio 2022
66+
```
67+
cmake -DWIN32_WINNT=<hex value> -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 17 2022" -A x64 ..\
68+
```
6469
* For visual studio 2019
6570
```
66-
cmake -DWIN32_WINNT=<_WIN32_WINNT> -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 16 2019" -A x64 ..\
71+
cmake -DWIN32_WINNT=<hex value> -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 16 2019" -A x64 ..\
6772
```
6873
* for visual studio 2017
6974
```
70-
cmake -DWIN32_WINNT=<_WIN32_WINNT> -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 15 2017 <Win64/Win32>" ..\
75+
cmake -DWIN32_WINNT=<hex value> -DBoost_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH="C:\Boost;C:\Program Files (x86)\Catch2;C:\Program Files (x86)\protobuf;C:\Program Files\OpenSSL" -G "Visual Studio 15 2017 <Win64/Win32>" ..\
7176
```
7277
* `msbuild localproxy.vcxproj -p:Configuration=Release` ( builds localproxy.exe inside bin\Release folder )
7378
* Follow [instructions](https://github.com/aws-samples/aws-iot-securetunneling-localproxy) under heading `Security Considerations` to run local proxy on a window OS.

0 commit comments

Comments
 (0)