Skip to content

Commit

Permalink
Merge branch 'main' into user/ashdhin/IssueTemplateRegressionCheckbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jmklix authored Oct 25, 2024
2 parents 247328d + f41b772 commit b5c4b8b
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 64 deletions.
2 changes: 1 addition & 1 deletion AWSCRTAndroidTestRunner/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.9)

# AWS lib
set(path_to_common "${CMAKE_CURRENT_LIST_DIR}/../../../../..")
Expand Down
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

cmake_minimum_required(VERSION 3.0)
# As of October 2024, we picked 3.9 as our version because internally we still support RHEL5 and AL2012, and CMake 3.9
# was the latest version available on those platforms.
cmake_minimum_required(VERSION 3.9)
option(ALLOW_CROSS_COMPILED_TESTS "Allow tests to be compiled via cross compile, for use with qemu" OFF)

project(aws-c-common LANGUAGES C VERSION 0.1.0)

message(STATUS "CMake ${CMAKE_VERSION}")

if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) # Enable LTO/IPO if available in the compiler, see AwsCFlags
endif()

if (POLICY CMP0077)
cmake_policy(SET CMP0077 OLD) # Enable options to get their values from normal variables
endif()
Expand Down Expand Up @@ -189,7 +187,6 @@ file(GLOB COMMON_SRC
${AWS_COMMON_EXTERNAL_SRC}
)


add_library(${PROJECT_NAME} ${COMMON_SRC})
aws_set_common_properties(${PROJECT_NAME} NO_WEXTRA)
aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_COMMON")
Expand Down
35 changes: 15 additions & 20 deletions cmake/AwsCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CMakeParseArguments) # needed for CMake v3.4 and lower

option(AWS_ENABLE_LTO "Enables LTO on libraries. Ensure this is set on all consumed targets, or linking will fail" OFF)
option(LEGACY_COMPILER_SUPPORT "This enables builds with compiler versions such as gcc 4.1.2. This is not a 'supported' feature; it's just a best effort." OFF)
Expand Down Expand Up @@ -173,6 +172,7 @@ function(aws_set_common_properties target)
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--exclude-libs,libcrypto.a")
endif()


endif()

check_include_file(stdint.h HAS_STDINT)
Expand Down Expand Up @@ -230,30 +230,18 @@ function(aws_set_common_properties target)
set(_ENABLE_LTO_EXPR $<NOT:$<CONFIG:Debug>>)

# try to check whether compiler supports LTO/IPO
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported OPTIONAL RESULT_VARIABLE ipo_check_exists)
if (ipo_check_exists)
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
message(STATUS "Enabling IPO/LTO for Release builds")
else()
message(STATUS "AWS_ENABLE_LTO is enabled, but cmake/compiler does not support it, disabling")
set(_ENABLE_LTO_EXPR OFF)
endif()
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
message(STATUS "Enabling IPO/LTO for Release builds")
else()
message(STATUS "AWS_ENABLE_LTO is enabled, but cmake/compiler does not support it, disabling")
set(_ENABLE_LTO_EXPR OFF)
endif()
else()
set(_ENABLE_LTO_EXPR OFF)
endif()

if(BUILD_SHARED_LIBS)
if (NOT MSVC)
# this should only be set when building shared libs.
list(APPEND AWS_C_FLAGS "-fvisibility=hidden")
endif()
endif()

if(AWS_ENABLE_TRACING)
target_link_libraries(${target} PRIVATE ittnotify)
else()
Expand All @@ -264,4 +252,11 @@ function(aws_set_common_properties target)
target_compile_definitions(${target} PRIVATE ${AWS_C_DEFINES_PRIVATE} PUBLIC ${AWS_C_DEFINES_PUBLIC})
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99 C_STANDARD_REQUIRED ON)
set_target_properties(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${_ENABLE_LTO_EXPR}>)

# Don't hide symbols in Debug builds.
# We do this so that backtraces are more likely to show function names.
# We mostly use backtraces to diagnose memory leaks.
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
endif ()
endfunction()
18 changes: 11 additions & 7 deletions cmake/AwsPrebuildDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ function(aws_prebuild_dependency)
set(depInstallDir ${depBinaryDir}/install)
file(MAKE_DIRECTORY ${depBinaryDir})

# Convert prefix path from list to escaped string, to be passed on command line
string(REPLACE ";" "\\\\;" ESCAPED_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
# For execute_process to accept a dynamically constructed command, it should be passed in a list format.
set(cmakeCommand "COMMAND" "${CMAKE_COMMAND}")
list(APPEND cmakeCommand -S ${AWS_PREBUILD_SOURCE_DIR})
set(cmakeCommand "${CMAKE_COMMAND}")
list(APPEND cmakeCommand ${AWS_PREBUILD_SOURCE_DIR})
list(APPEND cmakeCommand -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
list(APPEND cmakeCommand -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH})
list(APPEND cmakeCommand -DCMAKE_PREFIX_PATH=${ESCAPED_PREFIX_PATH})
list(APPEND cmakeCommand -DCMAKE_INSTALL_PREFIX=${depInstallDir})
list(APPEND cmakeCommand -DCMAKE_INSTALL_RPATH=${CMAKE_INSTALL_RPATH})
list(APPEND cmakeCommand -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS})
Expand All @@ -39,11 +41,13 @@ function(aws_prebuild_dependency)
list(APPEND cmakeCommand ${AWS_PREBUILD_CMAKE_ARGUMENTS})
endif()

list(APPEND cmakeCommand WORKING_DIRECTORY ${depBinaryDir})
list(APPEND cmakeCommand RESULT_VARIABLE result)

# Configure dependency project.
execute_process(${cmakeCommand})
execute_process(
COMMAND ${cmakeCommand}
WORKING_DIRECTORY ${depBinaryDir}
RESULT_VARIABLE result
)

if (NOT ${result} EQUAL 0)
message(FATAL_ERROR "Configuration failed for dependency project ${AWS_PREBUILD_DEPENDENCY_NAME}")
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/AwsSIMD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ else()
set(AWS_CLMUL_FLAG "-mpclmul")
set(AWS_SSE4_2_FLAG "-msse4.2")

# AWS Graviton3 processors use neoverse-v1
check_c_compiler_flag("-mtune=neoverse-v1" HAVE_MTUNE_NEOVERSE_V1)
if (HAVE_MTUNE_NEOVERSE_V1)
set(AWS_ARMv8_1_FLAG "-march=armv8-a+crc+crypto -mtune=neoverse-v1")
Expand Down Expand Up @@ -58,7 +59,7 @@ if (USE_CPU_EXTENSIONS)
_mm256_permutevar8x32_epi32(vec, vec);
return 0;
}" AWS_HAVE_AVX2_INTRINSICS)
}" AWS_HAVE_AVX2_INTRINSICS)

check_c_source_compiles("
#include <immintrin.h>
Expand Down
9 changes: 6 additions & 3 deletions cmake/AwsTestHarness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function(generate_test_driver driver_exe_name)
add_executable(${driver_exe_name} ${CMAKE_CURRENT_BINARY_DIR}/test_runner.c ${TESTS})
aws_set_common_properties(${driver_exe_name} NO_WEXTRA NO_PEDANTIC)

# Some versions of CMake (3.9-3.11) generate a test_runner.c file with
# a strncpy() call that triggers the "stringop-overflow" warning in GCC 8.1+
# This warning doesn't exist until GCC 7 though, so test for it before disabling.
# Some versions of CMake (3.9-3.11) generate a test_runner.c file with
# a strncpy() call that triggers the "stringop-overflow" warning in GCC 8.1+
# This warning doesn't exist until GCC 7 though, so test for it before disabling.
if (NOT MSVC)
check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW)
if (HAS_WNO_STRINGOP_OVERFLOW)
Expand All @@ -57,6 +57,9 @@ function(generate_test_driver driver_exe_name)
target_compile_definitions(${driver_exe_name} PRIVATE AWS_UNSTABLE_TESTING_API=1)
target_include_directories(${driver_exe_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR})

# Export symbols so that backtraces are more likely to show function names.
set_target_properties(${driver_exe_name} PROPERTIES ENABLE_EXPORTS ON)

foreach(name IN LISTS TEST_CASES)
add_test(${name} ${driver_exe_name} "${name}")
set_tests_properties("${name}" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE_VALUE})
Expand Down
2 changes: 1 addition & 1 deletion include/aws/common/array_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, siz
AWS_COMMON_API
void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn);

AWS_EXTERN_C_END
#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/array_list.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_ARRAY_LIST_H */
3 changes: 2 additions & 1 deletion include/aws/common/atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,12 @@ size_t aws_atomic_fetch_xor(volatile struct aws_atomic_var *var, size_t n);
AWS_STATIC_IMPL
void aws_atomic_thread_fence(enum aws_memory_order order);

AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/atomics.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif
3 changes: 1 addition & 2 deletions include/aws/common/atomics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ AWS_STATIC_IMPL
size_t aws_atomic_fetch_xor(volatile struct aws_atomic_var *var, size_t n) {
return aws_atomic_fetch_xor_explicit(var, n, aws_memory_order_seq_cst);
}
AWS_EXTERN_C_END

/* Include the backend implementation now, because we'll use its typedefs and #defines below */
#if defined(__GNUC__) || defined(__clang__)
Expand All @@ -143,6 +144,4 @@ size_t aws_atomic_fetch_xor(volatile struct aws_atomic_var *var, size_t n) {

#include <aws/common/atomics_fallback.inl>

AWS_EXTERN_C_END

#endif /* AWS_COMMON_ATOMICS_INL */
2 changes: 1 addition & 1 deletion include/aws/common/byte_order.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ AWS_STATIC_IMPL uint16_t aws_hton16(uint16_t x);
*/
AWS_STATIC_IMPL uint16_t aws_ntoh16(uint16_t x);

AWS_EXTERN_C_END
#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/byte_order.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_BYTE_ORDER_H */
3 changes: 2 additions & 1 deletion include/aws/common/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ int aws_high_res_clock_get_ticks(uint64_t *timestamp);
AWS_COMMON_API
int aws_sys_clock_get_ticks(uint64_t *timestamp);

AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/clock.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_CLOCK_H */
13 changes: 9 additions & 4 deletions include/aws/common/condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ AWS_COMMON_API
int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable);

/**
* Waits the calling thread on a notification from another thread.
* Waits the calling thread on a notification from another thread. This function must be called with the mutex locked
* by the calling thread otherwise the behavior is undefined. Spurious wakeups can occur and to avoid this causing
* any problems use the _pred version of this function.
*/
AWS_COMMON_API
int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex);

/**
* Waits the calling thread on a notification from another thread. If predicate returns false, the wait is reentered,
* otherwise control returns to the caller.
* otherwise control returns to the caller. This function must be called with the mutex locked by the calling thread
* otherwise the behavior is undefined.
*/
AWS_COMMON_API
int aws_condition_variable_wait_pred(
Expand All @@ -87,7 +90,8 @@ int aws_condition_variable_wait_pred(

/**
* Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in
* nanoseconds.
* nanoseconds. This function must be called with the mutex locked by the calling thread otherwise the behavior is
* undefined. Spurious wakeups can occur and to avoid this causing any problems use the _pred version of this function.
*/
AWS_COMMON_API
int aws_condition_variable_wait_for(
Expand All @@ -97,7 +101,8 @@ int aws_condition_variable_wait_for(

/**
* Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in
* nanoseconds. If predicate returns false, the wait is reentered, otherwise control returns to the caller.
* nanoseconds. If predicate returns false, the wait is reentered, otherwise control returns to the caller. This
* function must be called with the mutex locked by the calling thread otherwise the behavior is undefined.
*/
AWS_COMMON_API
int aws_condition_variable_wait_for_pred(
Expand Down
3 changes: 2 additions & 1 deletion include/aws/common/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ AWS_COMMON_API int aws_utf8_decoder_update(struct aws_utf8_decoder *decoder, str
*/
AWS_COMMON_API int aws_utf8_decoder_finalize(struct aws_utf8_decoder *decoder);

AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/encoding.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_ENCODING_H */
3 changes: 1 addition & 2 deletions include/aws/common/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ int aws_translate_and_raise_io_error_or(int error_no, int fallback_aws_error_cod
AWS_COMMON_API
int aws_translate_and_raise_io_error(int error_no);

AWS_EXTERN_C_END
#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/error.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END

enum aws_common_error {
AWS_ERROR_SUCCESS = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_COMMON_PACKAGE_ID),
AWS_ERROR_OOM,
Expand Down
2 changes: 1 addition & 1 deletion include/aws/common/linked_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ AWS_STATIC_IMPL void aws_linked_list_move_all_front(
* Returns true if the node is currently in a list, false otherwise.
*/
AWS_STATIC_IMPL bool aws_linked_list_node_is_in_list(struct aws_linked_list_node *node);
AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/linked_list.inl>
#endif /* AWS_NO_STATIC_IMPL */
AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_LINKED_LIST_H */
2 changes: 1 addition & 1 deletion include/aws/common/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ AWS_STATIC_IMPL float aws_max_float(float a, float b);
AWS_STATIC_IMPL double aws_min_double(double a, double b);
AWS_STATIC_IMPL double aws_max_double(double a, double b);

AWS_EXTERN_C_END
#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/math.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_MATH_H */
4 changes: 2 additions & 2 deletions include/aws/common/math.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <limits.h>
#include <stdlib.h>

AWS_EXTERN_C_BEGIN

#if defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus))
/*
* GCC and clang have these super convenient overflow checking builtins...
Expand Down Expand Up @@ -48,6 +46,8 @@ AWS_EXTERN_C_BEGIN
# include <aws/common/math.gcc_builtin.inl>
#endif

AWS_EXTERN_C_BEGIN

#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4127) /*Disable "conditional expression is constant" */
Expand Down
3 changes: 2 additions & 1 deletion include/aws/common/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ AWS_COMMON_API bool aws_ring_buffer_buf_belongs_to_pool(
const struct aws_ring_buffer *ring_buffer,
const struct aws_byte_buf *buf);

AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/ring_buffer.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_RING_BUFFER_H */
3 changes: 2 additions & 1 deletion include/aws/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,12 @@ bool aws_c_string_is_valid(const char *str);
AWS_STATIC_IMPL
bool aws_char_is_space(uint8_t c);

AWS_EXTERN_C_END

#ifndef AWS_NO_STATIC_IMPL
# include <aws/common/string.inl>
#endif /* AWS_NO_STATIC_IMPL */

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_STRING_H */
Loading

0 comments on commit b5c4b8b

Please sign in to comment.