From 2f8d2ee756ee11ea3543dc1ebde20fe68b8050ab Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Mon, 30 Aug 2021 13:36:54 -0700 Subject: [PATCH] Made PHP extension compile with openssl by default (#41) * Made PHP extension compile with openssl * Use catchsegv to dump a callstack * Updated to use aws_crt_crypto_share() * Much faster builds by making cmake parallel if supported * Make sure all CRT threads shutdown prior to cleanup * USE_OPENSSL should be the path to openssldir * Updated to aws-crt-ffi v0.2.4 --- .github/workflows/ci.yml | 34 ++++++++++++++----- .../workflows/{clang-format.yml => lint.yml} | 11 ++++++ Makefile.frag | 19 +++++++++-- config.m4 | 2 +- crt/aws-crt-ffi | 2 +- ext/crt.c | 3 ++ run_tests | 8 +++-- 7 files changed, 65 insertions(+), 14 deletions(-) rename .github/workflows/{clang-format.yml => lint.yml} (51%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6a92d..6a011db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,14 +37,14 @@ jobs: - name: Install depedencies run: composer update --no-interaction - - name: Run tests + - name: Build for PHP 5.5 env: CC: clang CXX: clang++ run: | phpize ./configure - make test + make php-linux-x64: runs-on: ubuntu-latest @@ -60,12 +60,30 @@ jobs: - "7.4" - "8.0" steps: - - name: PHP ${{ matrix.version}} Extension - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin - export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-php${{ matrix.version }}-linux-x64:${{ env.BUILDER_VERSION }} - docker pull $DOCKER_IMAGE - docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream --skip-install + - name: Setup PHP with Xdebug + uses: shivammathur/setup-php@v2 + with: + coverage: xdebug + php-version: ${{matrix.version}} + ini-values: xdebug.overload_var_dump=0, memory_limit=4G, phar.readonly=false + + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Install depedencies + run: composer update --no-interaction + + - name: Run tests + env: + CC: clang + CXX: clang++ + run: | + phpize + ./configure + make + make test # linux-arm: diff --git a/.github/workflows/clang-format.yml b/.github/workflows/lint.yml similarity index 51% rename from .github/workflows/clang-format.yml rename to .github/workflows/lint.yml index c3b8c20..5aa3ebd 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/lint.yml @@ -16,3 +16,14 @@ jobs: with: # List of extensions to check extensions: c + + check-submodules: + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + - name: Check Submodules + uses: awslabs/aws-crt-builder/.github/actions/check-submodules@main diff --git a/Makefile.frag b/Makefile.frag index 0b97206..3eda4bc 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -7,8 +7,23 @@ ifeq (, $(shell which cmake3)) CMAKE = cmake endif -CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(INT_DIR) -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) -CMAKE_BUILD = $(CMAKE) --build +# default to using system OpenSSL, if disabled aws-lc will be used +USE_OPENSSL ?= ON +ifneq (OFF,$(USE_OPENSSL)) + CMAKE_USE_OPENSSL=-DUSE_OPENSSL=ON + # if a path was provided, add it to CMAKE_PREFIX_PATH + ifneq (ON,$(USE_OPENSSL)) + CMAKE_PREFIX_PATH=-DCMAKE_PREFIX_PATH=$(USE_OPENSSL) + endif +endif + +CMAKE_CONFIGURE = $(CMAKE) \ + -DCMAKE_INSTALL_PREFIX=$(INT_DIR) \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \ + $(CMAKE_USE_OPENSSL) \ + $(CMAKE_PREFIX_PATH) +CMAKE_BUILD = CMAKE_BUILD_PARALLEL_LEVEL='' $(CMAKE) --build CMAKE_BUILD_TYPE ?= RelWithDebInfo CMAKE_TARGET = --config $(CMAKE_BUILD_TYPE) --target install diff --git a/config.m4 b/config.m4 index 395f4e5..c65e3a8 100644 --- a/config.m4 +++ b/config.m4 @@ -13,7 +13,7 @@ if test "$PHP_AWSCRT" != "no"; then if uname -a | grep -i darwin > /dev/null 2>&1; then platform_tls_libs="" else - platform_tls_libs="-ls2n -l:libcrypto.a" + platform_tls_libs="-ls2n -lcrypto" fi CRT_LIBPATHS="-L${cwd}/build/install/lib -L${cwd}/build/install/lib64" CRT_LIBS="-laws-crt-ffi -laws-c-auth -laws-c-http -laws-c-io -laws-c-cal -laws-c-compression -laws-checksums -laws-c-common ${platform_tls_libs}" diff --git a/crt/aws-crt-ffi b/crt/aws-crt-ffi index 94e82ef..aecdb91 160000 --- a/crt/aws-crt-ffi +++ b/crt/aws-crt-ffi @@ -1 +1 @@ -Subproject commit 94e82ef7b42fd23241f68692c2b3dfc9d596d685 +Subproject commit aecdb91b85079de6883bc3643428be0f1e61c153 diff --git a/ext/crt.c b/ext/crt.c index 766aa82..b71dd79 100644 --- a/ext/crt.c +++ b/ext/crt.c @@ -241,6 +241,8 @@ PHP_INI_END() static PHP_MINIT_FUNCTION(awscrt) { REGISTER_INI_ENTRIES(); + /* prevent s2n from initializing/de-initializing OpenSSL/libcrypto */ + aws_crt_crypto_share(); aws_crt_init(); aws_php_thread_queue_init(&s_aws_php_main_thread_queue); return SUCCESS; @@ -249,6 +251,7 @@ static PHP_MINIT_FUNCTION(awscrt) { static PHP_MSHUTDOWN_FUNCTION(awscrt) { UNREGISTER_INI_ENTRIES(); aws_php_thread_queue_clean_up(&s_aws_php_main_thread_queue); + aws_crt_thread_join_all(0); aws_crt_clean_up(); return SUCCESS; } diff --git a/run_tests b/run_tests index 3d13c04..18b449a 100755 --- a/run_tests +++ b/run_tests @@ -2,6 +2,11 @@ set -ex +launcher= +if command -v catchsegv; then + launcher=catchsegv +fi + if [ -z $PHP_BINARY ]; then PHP_BINARY=$(which php) fi @@ -10,5 +15,4 @@ if [ ! -d vendor ]; then composer update fi -$PHP_BINARY -c php.ini vendor/bin/phpunit tests --debug - +$launcher $PHP_BINARY -c php.ini vendor/bin/phpunit tests --debug