Skip to content

Commit

Permalink
Fixes for Watcom compiler and new CI test
Browse files Browse the repository at this point in the history
* Correct cmake script to support Open Watcom toolchain (#8167)
* Fix thread start callback prototype for Open Watcom toolchain (#8175)
* Added GitHub CI action for Windows/Linux/OS2
* Improvements for C89 compliance.
Thank you @jmalak for your contributions.
  • Loading branch information
dgarske committed Feb 4, 2025
1 parent f0b3c29 commit 4e03549
Show file tree
Hide file tree
Showing 22 changed files with 711 additions and 137 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/watcomc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build Watcom C

# START OF COMMON SECTION
on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# END OF COMMON SECTION

jobs:
wolfssl_watcomc_windows:
if: github.repository_owner == 'wolfssl'
strategy:
fail-fast: false
matrix:
common:
- cmake: '-G "Watcom WMake" -DCMAKE_VERBOSE_MAKEFILE=TRUE -DWOLFSSL_ASM=no -DWOLFSSL_EXAMPLES=no -DWOLFSSL_CRYPT_TESTS=no'
platform:
- title: 'Windows OW 2.0'
system: 'Windows'
image: 'windows-latest'
owimage: '2.0'
id: 'win32ow20'
cmake: '-DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86'
- title: 'Linux OW 2.0'
system: 'Linux'
image: 'ubuntu-latest'
owimage: '2.0'
id: 'linuxow20'
cmake: '-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86'
- title: 'OS/2 OW 2.0'
system: 'OS2'
image: 'windows-latest'
owimage: '2.0'
id: 'os2ow20'
cmake: '-DCMAKE_SYSTEM_NAME=OS2 -DCMAKE_SYSTEM_PROCESSOR=x86'
thread:
- id: 'multi'
cmake: ''
owcmake: '-DCMAKE_POLICY_DEFAULT_CMP0136=NEW -DCMAKE_WATCOM_RUNTIME_LIBRARY=MultiThreaded'
- id: 'single'
cmake: '-DWOLFSSL_SINGLE_THREADED=yes'
owcmake: '-DCMAKE_POLICY_DEFAULT_CMP0136=NEW -DCMAKE_WATCOM_RUNTIME_LIBRARY=SingleThreaded'
library:
- id: 'dll'
cmake: ''
owcmake: 'DLL'
- id: 'static'
cmake: '-DBUILD_SHARED_LIBS=no'
owcmake: ''
exclude:
- { platform: { system: 'Linux' }, library: { id: 'dll' } }
runs-on: ${{ matrix.platform.image }}
name: ${{ matrix.platform.title }} (${{ matrix.thread.id }} ${{ matrix.library.id }})
steps:
- name: Setup Open Watcom ${{ matrix.platform.owimage }}
uses: open-watcom/setup-watcom@v0
with:
version: ${{ matrix.platform.owimage }}

- name: Checkout wolfSSL
uses: actions/checkout@v4
with:
path: wolfssl

- name: Build wolfSSL
working-directory: wolfssl
shell: bash
run: |
cmake -B build ${{matrix.common.cmake}} ${{ matrix.platform.cmake }} ${{ matrix.thread.cmake }} ${{ matrix.library.cmake }} ${{ matrix.thread.owcmake }}${{ matrix.library.owcmake }}
cmake --build build
- name: Upload build errors
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.id }}-${{ matrix.thread.id }}-${{ matrix.library.id }}
path: |
build/**
3 changes: 3 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ __INTEGRITY
__INTEL_COMPILER
__KEIL__
__KEY_DATA_H__
__LINUX__
__LP64
__LP64__
__MACH__
Expand All @@ -908,7 +909,9 @@ __MINGW32__
__MINGW64_VERSION_MAJOR
__MINGW64__
__MWERKS__
__NT__
__OpenBSD__
__OS2__
__PIE__
__POWERPC__
__PPC__
Expand Down
93 changes: 56 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ endif()
# Thread local storage
include(CheckCSourceCompiles)

set(TLS_KEYWORDS "__thread" "__declspec(thread)")
foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
set(TLS_CODE "#include <stdlib.h>
if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
endif()
else()
set(TLS_KEYWORDS "__thread" "__declspec(thread)")
foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
set(TLS_CODE "#include <stdlib.h>
static void foo(void) {
static ${TLS_KEYWORD} int bar\;
exit(1)\;
Expand All @@ -164,21 +169,22 @@ foreach(TLS_KEYWORD IN LISTS TLS_KEYWORDS)
int main() {
return 0\;
}"
)
check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)
)
check_c_source_compiles(${TLS_CODE} THREAD_LS_ON)

if(THREAD_LS_ON)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
break()
else()
# THREAD_LS_ON is cached after each call to
# check_c_source_compiles, and the function
# won't run subsequent times if the variable
# is in the cache. To make it run again, we
# need to remove the variable from the cache.
unset(THREAD_LS_ON CACHE)
endif()
endforeach()
if(THREAD_LS_ON)
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_THREAD_LS")
break()
else()
# THREAD_LS_ON is cached after each call to
# check_c_source_compiles, and the function
# won't run subsequent times if the variable
# is in the cache. To make it run again, we
# need to remove the variable from the cache.
unset(THREAD_LS_ON CACHE)
endif()
endforeach()
endif()

# TODO: AX_PTHREAD does a lot. Need to implement the
# rest of its logic.
Expand All @@ -198,13 +204,20 @@ find_package(Threads)
# Example for map file and custom linker script
#set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")

message(STATUS "C Compiler ID: ${CMAKE_C_COMPILER_ID}")

if(DEFINED WARNING_C_FLAGS)
set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}")
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wx -wcd=202")
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_HAVE_MIN -DWOLFSSL_HAVE_MAX -DNO_WRITEV")
elseif(WIN32)
# Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags.
set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
# Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags.
set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}")
endif()

####################################################
Expand Down Expand Up @@ -281,9 +294,7 @@ if(NOT WOLFSSL_SINGLE_THREADED)
if(CMAKE_USE_PTHREADS_INIT)
list(APPEND WOLFSSL_LINK_LIBS Threads::Threads)
set(HAVE_PTHREAD 1)
list(APPEND WOLFSSL_DEFINITIONS
"-DHAVE_PTHREAD"
"-D_POSIX_THREADS")
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PTHREAD")
endif()
else()
list(APPEND WOLFSSL_DEFINITIONS "-DSINGLE_THREADED")
Expand Down Expand Up @@ -2414,6 +2425,7 @@ if (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_SYSTEM_NAME} MATCHE
message("Building on Windows/MSYS/MINGW")
target_link_libraries(wolfssl PUBLIC
ws2_32 crypt32 advapi32)
elseif(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
elseif(APPLE)
message("Building on Apple")
if(WOLFSSL_SYS_CA_CERTS)
Expand Down Expand Up @@ -2479,7 +2491,9 @@ if(WOLFSSL_EXAMPLES)
add_executable(tls_bench
${CMAKE_CURRENT_SOURCE_DIR}/examples/benchmark/tls_bench.c)
target_link_libraries(tls_bench wolfssl)
target_link_libraries(tls_bench Threads::Threads)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
target_link_libraries(tls_bench Threads::Threads)
endif()
set_property(TARGET tls_bench
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
Expand All @@ -2501,7 +2515,9 @@ if(WOLFSSL_EXAMPLES)
${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER")
target_link_libraries(unit_test wolfssl)
target_link_libraries(unit_test Threads::Threads)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
target_link_libraries(unit_test Threads::Threads)
endif()
set_property(TARGET unit_test
PROPERTY RUNTIME_OUTPUT_DIRECTORY
${WOLFSSL_OUTPUT_BASE}/tests/)
Expand Down Expand Up @@ -2751,19 +2767,22 @@ if(WOLFSSL_INSTALL)
set(includedir "\${prefix}/include")
set(VERSION ${PROJECT_VERSION})

# Setting libm in Libs.private of wolfssl.pc.
# See "Link Libraries" in above about `m` insertion to LINK_LIBRARIES
get_target_property(_wolfssl_dep_libs wolfssl LINK_LIBRARIES)
list(FIND _wolfssl_dep_libs m _dep_libm)
if ("${_dep_libm}" GREATER -1)
set(LIBM -lm)
if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
else()
set(LIBM)
endif()
# Setting libm in Libs.private of wolfssl.pc.
# See "Link Libraries" in above about `m` insertion to LINK_LIBRARIES
get_target_property(_wolfssl_dep_libs wolfssl LINK_LIBRARIES)
list(FIND _wolfssl_dep_libs m _dep_libm)
if ("${_dep_libm}" GREATER -1)
set(LIBM -lm)
else()
set(LIBM)
endif()

configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
configure_file(support/wolfssl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/support/wolfssl.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
Expand Down
8 changes: 4 additions & 4 deletions examples/benchmark/tls_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ static int bench_tls_client(info_t* info)
}

#if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN)
static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
{
int ret;
info_t* info = (info_t*)args;
Expand All @@ -1243,7 +1243,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_server.cond));

WOLFSSL_RETURN_FROM_THREAD(0);
RETURN_FROM_THREAD_NOJOIN(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_CLIENT */
Expand Down Expand Up @@ -1675,7 +1675,7 @@ static int bench_tls_server(info_t* info)
}

#if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN)
static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
{
int ret = 0;
info_t* info = (info_t*)args;
Expand Down Expand Up @@ -1703,7 +1703,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_client.cond));

WOLFSSL_RETURN_FROM_THREAD(0);
RETURN_FROM_THREAD_NOJOIN(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_SERVER */
Expand Down
2 changes: 1 addition & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -11916,7 +11916,7 @@ static int GetRecordHeader(WOLFSSL* ssl, word32* inOutIdx,
(!ssl->options.dtls &&
rh->pvMinor < ssl->version.minor))
#else
rh->pvMinor < ssl->version.minor
(rh->pvMinor < ssl->version.minor)
#endif
)) {
WOLFSSL_MSG("SSL version error");
Expand Down
1 change: 1 addition & 0 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifdef WOLFSSL_SYS_CA_CERTS

#ifdef _WIN32
#define _WINSOCKAPI_ /* Force winsock (workaround for WinCE) */
#include <windows.h>
#include <wincrypt.h>

Expand Down
11 changes: 4 additions & 7 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
#include <errno.h>
#endif

#ifdef _WIN32_WCE
/* On WinCE winsock2.h must be included before windows.h for socket stuff */
#include <winsock2.h>
#endif

#include <wolfssl/internal.h>
#include <wolfssl/error-ssl.h>
#include <wolfssl/wolfio.h>
Expand All @@ -56,7 +51,9 @@ int Nucleus_Net_Errno;
#endif

#if defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT)
#ifndef USE_WINDOWS_API
#ifdef USE_WINDOWS_API
#include <winsock2.h>
#else
#if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT)
#elif defined(ARDUINO)
#elif defined(FREESCALE_MQX)
Expand Down Expand Up @@ -248,7 +245,7 @@ static int TranslateIoReturnCode(int err, SOCKET_T sd, int direction)
return WOLFSSL_CBIO_ERR_CONN_CLOSE;
}

#if defined(_WIN32)
#if defined(_WIN32) && !defined(__WATCOMC__)
strcpy_s(errstr, sizeof(errstr), "\tGeneral error: ");
errstr_offset = strlen(errstr);
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
Expand Down
Loading

0 comments on commit 4e03549

Please sign in to comment.