From 08002c5400d799a959f3b06dd36d4c2765fce44b Mon Sep 17 00:00:00 2001 From: Marco Magdy Date: Wed, 19 Oct 2022 08:48:20 -0700 Subject: [PATCH 01/10] Add GitHub code scanner workflow (#172) * Add support for Github code scanner 'lgtm.com' is shutting down in December 2022. It has been replaced by 'GitHub code scanning'. * Install libcurl as part of the build steps * Replace lgtm badge with GitHub code analyzer * fixup! Replace lgtm badge with GitHub code analyzer --- .github/workflows/code-quality.yml | 58 ++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-quality.yml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 00000000..9ccfc820 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,58 @@ +name: "Code Quality" + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '32 14 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install libcurl dependency + - name: Install dependencies + run: sudo apt install -y libcurl4-openssl-dev + + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + - run: | + echo "Run, CMake build script" + cmake -B ${{github.workspace}}/build -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" + diff --git a/README.md b/README.md index f86004a9..74e60af6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![GitHub](https://img.shields.io/github/license/awslabs/aws-lambda-cpp.svg)](https://github.com/awslabs/aws-lambda-cpp/blob/master/LICENSE) -[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/awslabs/aws-lambda-cpp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-lambda-cpp/context:cpp) +![Code Quality badge](https://github.com/awslabs/aws-lambda-cpp/actions/workflows/code-quality.yml/badge.svg) | OS | Arch | Status | |----|------|--------| From 8e98808f346964a85ede585e0fdd5874d43b325f Mon Sep 17 00:00:00 2001 From: Marco Magdy Date: Wed, 19 Oct 2022 13:20:43 -0700 Subject: [PATCH 02/10] Pass payload by value to enable moving arguments (#173) * Pass payload by value to enable moving arguments * Update the tests to use std::move * empty commit Co-authored-by: Bryan Moffatt Co-authored-by: Bryan Moffatt --- examples/dynamodb/main.cpp | 8 ++++---- examples/s3/main.cpp | 2 +- include/aws/lambda-runtime/runtime.h | 2 +- src/runtime.cpp | 6 +++--- tests/resources/lambda_function.cpp | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/dynamodb/main.cpp b/examples/dynamodb/main.cpp index a8b86621..6089fa32 100644 --- a/examples/dynamodb/main.cpp +++ b/examples/dynamodb/main.cpp @@ -173,9 +173,9 @@ aws::lambda_runtime::invocation_response my_handler( if (cr.error_msg) { JsonValue response; response.WithString("body", cr.error_msg).WithInteger("statusCode", 400); - auto const apig_response = response.View().WriteCompact(); + auto apig_response = response.View().WriteCompact(); AWS_LOGSTREAM_ERROR(TAG, "Validation failed. " << apig_response); - return aws::lambda_runtime::invocation_response::success(apig_response, "application/json"); + return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json"); } auto result = query(cr, client); @@ -190,10 +190,10 @@ aws::lambda_runtime::invocation_response my_handler( response.WithString("body", "No data found for this product.").WithInteger("statusCode", 400); } - auto const apig_response = response.View().WriteCompact(); + auto apig_response = response.View().WriteCompact(); AWS_LOGSTREAM_DEBUG(TAG, "api gateway response: " << apig_response); - return aws::lambda_runtime::invocation_response::success(apig_response, "application/json"); + return aws::lambda_runtime::invocation_response::success(std::move(apig_response), "application/json"); } std::function()> GetConsoleLoggerFactory() diff --git a/examples/s3/main.cpp b/examples/s3/main.cpp index 45b935bf..a389121c 100644 --- a/examples/s3/main.cpp +++ b/examples/s3/main.cpp @@ -50,7 +50,7 @@ static invocation_response my_handler(invocation_request const& req, Aws::S3::S3 return invocation_response::failure(err, "DownloadFailure"); } - return invocation_response::success(base64_encoded_file, "application/base64"); + return invocation_response::success(std::move(base64_encoded_file), "application/base64"); } std::function()> GetConsoleLoggerFactory() diff --git a/include/aws/lambda-runtime/runtime.h b/include/aws/lambda-runtime/runtime.h index 96023697..d19dbc27 100644 --- a/include/aws/lambda-runtime/runtime.h +++ b/include/aws/lambda-runtime/runtime.h @@ -105,7 +105,7 @@ class invocation_response { /** * Create a successful invocation response with the given payload and content-type. */ - static invocation_response success(std::string const& payload, std::string const& content_type); + static invocation_response success(std::string payload, std::string content_type); /** * Create a failure response with the given error message and error type. diff --git a/src/runtime.cpp b/src/runtime.cpp index 47ead0e7..3968adb8 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -506,12 +506,12 @@ static std::string json_escape(std::string const& in) } AWS_LAMBDA_RUNTIME_API -invocation_response invocation_response::success(std::string const& payload, std::string const& content_type) +invocation_response invocation_response::success(std::string payload, std::string content_type) { invocation_response r; r.m_success = true; - r.m_content_type = content_type; - r.m_payload = payload; + r.m_content_type = std::move(content_type); + r.m_payload = std::move(payload); return r; } diff --git a/tests/resources/lambda_function.cpp b/tests/resources/lambda_function.cpp index 7cd62e55..b0228d3c 100644 --- a/tests/resources/lambda_function.cpp +++ b/tests/resources/lambda_function.cpp @@ -23,8 +23,8 @@ invocation_response echo_failure(invocation_request const& /*request*/) invocation_response binary_response(invocation_request const& /*request*/) { - const std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN); - return invocation_response::success(png, "image/png"); + std::string png((char*)awslogo_png, AWSLOGO_PNG_LEN); + return invocation_response::success(std::move(png), "image/png"); } invocation_response crash_backtrace(invocation_request const& /*request*/) From 2601aeaa686086a20d1d87eb1bb68d5bcdfe8f1f Mon Sep 17 00:00:00 2001 From: Marco Magdy Date: Wed, 19 Oct 2022 13:36:14 -0700 Subject: [PATCH 03/10] Build with ASan and UBSan (#174) Co-authored-by: Bryan Moffatt --- CMakeLists.txt | 6 ++++++ ci/codebuild/arch-linux.yml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76702cb5..14ee99f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project(aws-lambda-runtime option(ENABLE_LTO "Enables link-time optimization, requires compiler support." OFF) option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF) +option(ENABLE_SANITIZERS "Enables ASan and UBSan." OFF) add_library(${PROJECT_NAME} "src/logging.cpp" @@ -22,6 +23,11 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $) +if (ENABLE_SANITIZERS) + target_compile_options(${PROJECT_NAME} PUBLIC "-fsanitize=address,undefined") + target_link_libraries(${PROJECT_NAME} PUBLIC "-fsanitize=address,undefined") +endif() + if (ENABLE_LTO) include(CheckIPOSupported) check_ipo_supported(RESULT has_lto OUTPUT lto_check_output) diff --git a/ci/codebuild/arch-linux.yml b/ci/codebuild/arch-linux.yml index 4262f502..0a12a5d1 100644 --- a/ci/codebuild/arch-linux.yml +++ b/ci/codebuild/arch-linux.yml @@ -4,6 +4,6 @@ phases: build: commands: - echo Build started on `date` - - ./ci/codebuild/build.sh -DTEST_RESOURCE_PREFIX=lambda-cpp-archbtw + - ./ci/codebuild/build.sh -DTEST_RESOURCE_PREFIX=lambda-cpp-archbtw -DENABLE_SANITIZERS=ON - ./ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun - echo Build completed on `date` From 78ffe176de2ae98e1a9ae513abaad9d74b1bfb14 Mon Sep 17 00:00:00 2001 From: Marco Magdy Date: Fri, 4 Nov 2022 12:03:51 -0700 Subject: [PATCH 04/10] Update code-quality.yml (#176) --- .github/workflows/code-quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 9ccfc820..495f6a6a 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -31,7 +31,7 @@ jobs: # Install libcurl dependency - name: Install dependencies - run: sudo apt install -y libcurl4-openssl-dev + run: sudo apt-get update && sudo apt install -y libcurl4-openssl-dev # Initializes the CodeQL tools for scanning. From e3e9e096a0fa4537e35f32c4ea10ea62fe7c9f5a Mon Sep 17 00:00:00 2001 From: Maxi Mittelhammer Date: Thu, 2 Feb 2023 17:58:46 +0100 Subject: [PATCH 05/10] Changed sprintf to snprintf (#180) --- src/runtime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index 3968adb8..4ca70dc2 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -496,7 +496,7 @@ static std::string json_escape(std::string const& in) // escape and print as unicode codepoint constexpr int printed_unicode_length = 6; // 4 hex + letter 'u' + \0 std::array buf; - sprintf(buf.data(), "u%04x", ch); + snprintf(buf.data(), buf.size(), "u%04x", ch); out.append(buf.data(), buf.size() - 1); // add only five, discarding the null terminator. break; } From fbfdaec9777adac9f6b50d9acd23edc24ca2b3e2 Mon Sep 17 00:00:00 2001 From: Marco Magdy Date: Tue, 14 Feb 2023 13:01:15 -0800 Subject: [PATCH 06/10] Fix clang-tidy benign warnings (#185) --- .clang-tidy | 3 ++- ci/codebuild/format-check.sh | 5 +++++ include/aws/lambda-runtime/runtime.h | 3 +-- src/runtime.cpp | 9 +++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7d343ead..d42139e3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,7 @@ --- Checks: -'clang-diagnostic-*,clang-analyzer-*,performance-*,readability-*,modernize-*,bugprone-*,misc-*,-modernize-use-trailing-return-type' +'clang-diagnostic-*,clang-analyzer-*,performance-*,readability-*,modernize-*,bugprone-*,misc-*, +-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-readability-identifier-length' WarningsAsErrors: '*' HeaderFilterRegex: 'include/aws/.*\.h$' FormatStyle: 'none' diff --git a/ci/codebuild/format-check.sh b/ci/codebuild/format-check.sh index 222b784f..035bd54f 100755 --- a/ci/codebuild/format-check.sh +++ b/ci/codebuild/format-check.sh @@ -13,6 +13,11 @@ FAIL=0 SOURCE_FILES=$(find src include tests -type f -name "*.h" -o -name "*.cpp") for i in $SOURCE_FILES do + if [[ "$i" == *"gtest.h" || "$i" == *"backward.h" ]]; then + continue + fi + + echo "$i\n" if [ $($CLANG_FORMAT -output-replacements-xml $i | grep -c " #include #include +#include #include // for strtoul #include @@ -133,12 +134,16 @@ static size_t read_data(char* buffer, size_t size, size_t nitems, void* userdata } if (unread <= limit) { - std::copy_n(ctx->first.begin() + ctx->second, unread, buffer); + auto from = ctx->first.begin(); + std::advance(from, ctx->second); + std::copy_n(from, unread, buffer); ctx->second += unread; return unread; } - std::copy_n(ctx->first.begin() + ctx->second, limit, buffer); + auto from = ctx->first.begin(); + std::advance(from, ctx->second); + std::copy_n(from, limit, buffer); ctx->second += limit; return limit; } From fa438eba19f3c536cfcce74737f336146767fde8 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Wed, 15 Feb 2023 09:16:17 +0100 Subject: [PATCH 07/10] Update actions/checkout to v3 (#181) --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 14bb1dac..5cadaf02 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install Dependencies run: sudo apt-get update && sudo apt-get install -y clang-tidy libcurl4-openssl-dev @@ -36,7 +36,7 @@ jobs: build-on-arm-too: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: uraimo/run-on-arch-action@v2 with: arch: aarch64 @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Check Formatting run: ./ci/codebuild/format-check.sh From c09c86e0268ab8965ebd0ebee142c69c655a3207 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Mon, 27 Feb 2023 05:45:06 +0100 Subject: [PATCH 08/10] Add building and packaging a demo project to CI and revert #136 (#183) * Add demo project * Add build-demo CI job * Revert "Simplified method for picking out shared libraries from system package query result (#136)" This reverts commit 5fb60b9d93c685e15d036889eb992dabe296d0bc. --------- Co-authored-by: Bryan Moffatt Co-authored-by: Bryan Moffatt --- .github/workflows/workflow.yml | 22 ++++++++++++++++++++++ examples/demo/CMakeLists.txt | 11 +++++++++++ examples/demo/main.cpp | 20 ++++++++++++++++++++ packaging/packager | 17 ++++++++++++----- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 examples/demo/CMakeLists.txt create mode 100644 examples/demo/main.cpp diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 5cadaf02..526b38a9 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -46,6 +46,28 @@ jobs: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + build-demo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y clang-tidy libcurl4-openssl-dev + + - name: Build and install lambda runtime + run: | + mkdir build && cd build + cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/lambda-install + make + make install + + - name: Build and package demo project + run: | + cd examples/demo + mkdir build && cd build + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=~/lambda-install + make + make aws-lambda-package-demo format: diff --git a/examples/demo/CMakeLists.txt b/examples/demo/CMakeLists.txt new file mode 100644 index 00000000..06aad51b --- /dev/null +++ b/examples/demo/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.9) +set(CMAKE_CXX_STANDARD 11) +project(demo LANGUAGES CXX) +find_package(aws-lambda-runtime) +add_executable(${PROJECT_NAME} "main.cpp") +target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-lambda-runtime) +target_compile_features(${PROJECT_NAME} PRIVATE "cxx_std_11") +target_compile_options(${PROJECT_NAME} PRIVATE "-Wall" "-Wextra") + +# this line creates a target that packages your binary and zips it up +aws_lambda_package_target(${PROJECT_NAME}) diff --git a/examples/demo/main.cpp b/examples/demo/main.cpp new file mode 100644 index 00000000..358efe03 --- /dev/null +++ b/examples/demo/main.cpp @@ -0,0 +1,20 @@ +#include + +using namespace aws::lambda_runtime; + +static invocation_response my_handler(invocation_request const& req) +{ + if (req.payload.length() > 42) { + return invocation_response::failure("error message here"/*error_message*/, + "error type here" /*error_type*/); + } + + return invocation_response::success("json payload here" /*payload*/, + "application/json" /*MIME type*/); +} + +int main() +{ + run_handler(my_handler); + return 0; +} diff --git a/packaging/packager b/packaging/packager index 4e8759ef..0c4e7493 100755 --- a/packaging/packager +++ b/packaging/packager @@ -56,7 +56,7 @@ if ! type zip > /dev/null 2>&1; then exit 1 fi -function find_so_files() { +function pluck_so_files() { sed -E '/\.so$|\.so\.[0-9]+$/!d' } @@ -64,7 +64,7 @@ function package_libc_alpine() { # -F matches a fixed string rather than a regex (grep that comes with busybox doesn't know --fixed-strings) if grep -F "Alpine Linux" < /etc/os-release > /dev/null; then if type apk > /dev/null 2>&1; then - apk info --contents musl 2>/dev/null | find_so_files | sed 's/^/\//' + apk info --contents musl 2>/dev/null | pluck_so_files | sed 's/^/\//' fi fi } @@ -72,20 +72,27 @@ function package_libc_alpine() { function package_libc_pacman() { if grep --extended-regexp "Arch Linux|Manjaro Linux" < /etc/os-release > /dev/null 2>&1; then if type pacman > /dev/null 2>&1; then - pacman --query --list --quiet glibc | find_so_files + pacman --query --list --quiet glibc | pluck_so_files fi fi } function package_libc_dpkg() { if type dpkg-query > /dev/null 2>&1; then - dpkg-query --listfiles libc6:$(dpkg --print-architecture) | find_so_files + architecture=$(dpkg --print-architecture) + if [[ $(dpkg-query --listfiles libc6:$architecture | wc -l) -gt 0 ]]; then + dpkg-query --listfiles libc6:$architecture | pluck_so_files + fi fi } function package_libc_rpm() { + arch=$(uname -m) + if type rpm > /dev/null 2>&1; then - rpm --query --list glibc.$(uname -m) | find_so_files + if [[ $(rpm --query --list glibc.$arch | wc -l) -gt 1 ]]; then + rpm --query --list glibc.$arch | pluck_so_files + fi fi } From f0ad0623682cd9bf9bc9ae2e362cb5a00b28e59a Mon Sep 17 00:00:00 2001 From: Mart Haarman Date: Fri, 24 Mar 2023 22:29:03 +0100 Subject: [PATCH 09/10] Update main.cpp (#178) Co-authored-by: Bryan Moffatt --- examples/s3/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/s3/main.cpp b/examples/s3/main.cpp index a389121c..892560cb 100644 --- a/examples/s3/main.cpp +++ b/examples/s3/main.cpp @@ -73,8 +73,7 @@ int main() config.region = Aws::Environment::GetEnv("AWS_REGION"); config.caFile = "/etc/pki/tls/certs/ca-bundle.crt"; - auto credentialsProvider = Aws::MakeShared(TAG); - S3::S3Client client(credentialsProvider, config); + S3::S3Client client(config); auto handler_fn = [&client](aws::lambda_runtime::invocation_request const& req) { return my_handler(req, client); }; From e08ca6e065877b0ab4eb0e1e43e21c3a3c5f274a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Toma?= <34220105+Stefan9283@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:46:26 +0300 Subject: [PATCH 10/10] Making libbacktrace optional (#189) * Making libbacktrace optional --------- Co-authored-by: Stefan Toma --- CMakeLists.txt | 39 +++++++++++++++++++++++---------------- src/backward.cpp | 6 +++++- src/backward.h | 6 ++++++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ee99f0..09e226fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,8 +47,29 @@ endif() target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS}) -find_package(Backtrace REQUIRED) -target_link_libraries(${PROJECT_NAME} PRIVATE ${Backtrace_LIBRARIES}) +find_package(Backtrace QUIET) +if (${Backtrace_FOUND}) + target_link_libraries(${PROJECT_NAME} PRIVATE ${Backtrace_LIBRARIES}) + + find_library(DW_LIB NAMES dw) + if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND) + message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}") + target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1") + target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}") + else() + find_library(BFD_LIB NAMES bfd) + if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND) + message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}") + target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1") + target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}") + endif() + endif() + +else() + message("-- libbacktrace was not installed. Stacktracing will be disabled") + add_definitions(-Dno_backtrace) +endif() + target_compile_options(${PROJECT_NAME} PRIVATE "-fno-exceptions" @@ -61,20 +82,6 @@ target_compile_options(${PROJECT_NAME} PRIVATE "-Wconversion" "-Wno-sign-conversion") -find_library(DW_LIB NAMES dw) -if (NOT DW_LIB STREQUAL DW_LIB-NOTFOUND) - message("-- Enhanced stack-traces are enabled via libdw: ${DW_LIB}") - target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_DW=1") - target_link_libraries(${PROJECT_NAME} PUBLIC "${DW_LIB}") -else() - find_library(BFD_LIB NAMES bfd) - if (NOT BFD_LIB STREQUAL BFD_LIB-NOTFOUND) - message("-- Enhanced stack-traces are enabled via libbfd: ${BFD_LIB}") - target_compile_definitions(${PROJECT_NAME} PRIVATE "BACKWARD_HAS_BFD=1") - target_link_libraries(${PROJECT_NAME} PRIVATE "${BFD_LIB}") - endif() -endif() - if (LOG_VERBOSITY) target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=${LOG_VERBOSITY}") elseif(CMAKE_BUILD_TYPE STREQUAL Debug) diff --git a/src/backward.cpp b/src/backward.cpp index cc64abdb..8649fd51 100644 --- a/src/backward.cpp +++ b/src/backward.cpp @@ -23,10 +23,14 @@ // - g++/clang++ -lbfd ... // #define BACKWARD_HAS_BFD 1 -#include "backward.h" +#ifndef no_backtrace + +# include "backward.h" namespace backward { backward::SignalHandling sh; } // namespace backward + +#endif diff --git a/src/backward.h b/src/backward.h index c4213789..832c4528 100644 --- a/src/backward.h +++ b/src/backward.h @@ -28,6 +28,10 @@ # error "It's not going to compile without a C++ compiler..." #endif +#ifdef no_backtrace +# pragma message "Disabling stacktracing" +#else + #if defined(BACKWARD_CXX11) #elif defined(BACKWARD_CXX98) #else @@ -4539,4 +4543,6 @@ class SignalHandling { } // namespace backward +#endif /* no_backtrace */ + #endif /* H_GUARD */