[Replicate] compatibility with PHP 5.x (#97)

original: https://github.com/awslabs/aws-crt-php/pull/96

- Make sure run the test... Run the test for php5.5
- Add readme section about the mismatch of libcrypto from php and awscrt. 

---------

Co-authored-by: Remi Collet <[email protected]>
This commit is contained in:
Dengke Tang
2023-03-24 13:22:19 -07:00
committed by GitHub
co-authored by Remi Collet
parent ed3f8ca16d
commit 1926277fc7
4 changed files with 31 additions and 10 deletions
+6 -7
View File
@@ -37,13 +37,12 @@ jobs:
run: | run: |
phpize phpize
./configure ./configure
make # Normally, CRT uses the system's default libcrypto.so.
# But in this CI run, PHP 5.5 is using a different older libcrypto.so, as PHP 5.5 cannot build with openssl >=1.1.1.
- name: Install dependencies # When an applications uses two different libcrypto.so at the same time, things tend to explode.
# get path to composer.phar so we can run it with custom php.ini # Therefore, in this CI run we build AWS-LC statically, and use its libcrypto.a instead.
run: | USE_OPENSSL=OFF make
COMPOSER_PHAR=$(realpath $(which composer)) ./dev-scripts/run_tests.sh
php -c php.ini $COMPOSER_PHAR update --no-interaction
php-linux-x64: php-linux-x64:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+11
View File
@@ -16,8 +16,19 @@ ifneq (OFF,$(USE_OPENSSL))
ifneq (ON,$(USE_OPENSSL)) ifneq (ON,$(USE_OPENSSL))
CMAKE_PREFIX_PATH=-DCMAKE_PREFIX_PATH=$(USE_OPENSSL) CMAKE_PREFIX_PATH=-DCMAKE_PREFIX_PATH=$(USE_OPENSSL)
endif endif
else
# Hide symbols from libcrypto.a
# This avoids problems when an application ends up using both libcrypto.a and libcrypto.so.
#
# An example of this happening is the aws-c-io tests.
# All the C libs are compiled statically, but then a PKCS#11 library is
# loaded at runtime which happens to use libcrypto.so from OpenSSL.
# If the symbols from libcrypto.a aren't hidden, then SOME function calls use the libcrypto.a implementation
# and SOME function calls use the libcrypto.so implementation, and this mismatch leads to weird crashes.
EXTRA_LDFLAGS="-Wl,--exclude-libs,libcrypto.a"
endif endif
CMAKE_CONFIGURE = $(CMAKE) \ CMAKE_CONFIGURE = $(CMAKE) \
-DCMAKE_SOURCE_DIR=$(srcdir) \ -DCMAKE_SOURCE_DIR=$(srcdir) \
-DCMAKE_BINARY_DIR=$(CMAKE_BUILD_DIR) \ -DCMAKE_BINARY_DIR=$(CMAKE_BUILD_DIR) \
+12 -3
View File
@@ -1,6 +1,7 @@
# AWS Common Runtime PHP bindings # AWS Common Runtime PHP bindings
## Requirements ## Requirements
* PHP 5.5+ on UNIX platforms, 7.2+ on Windows * PHP 5.5+ on UNIX platforms, 7.2+ on Windows
* CMake 3.x * CMake 3.x
* GCC 4.4+, clang 3.8+ on UNIX, Visual Studio build tools on Windows * GCC 4.4+, clang 3.8+ on UNIX, Visual Studio build tools on Windows
@@ -17,7 +18,7 @@ pecl install awscrt
composer require aws/aws-crt-php composer require aws/aws-crt-php
``` ```
On Windows, you need to build from source as instruction written below for the native extension `php_awscrt.dll`. And, follow https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading to load extension. After that: On Windows, you need to build from source as instruction written below for the native extension `php_awscrt.dll` . And, follow https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading to load extension. After that:
``` ```
composer require aws/aws-crt-php composer require aws/aws-crt-php
@@ -46,7 +47,7 @@ $ ./dev-scripts/run_tests.sh
From Command Prompt (not powershell). The instruction is based on Visual Studio 2019 on 64bit Windows. From Command Prompt (not powershell). The instruction is based on Visual Studio 2019 on 64bit Windows.
``` bat ```bat
> git clone --recursive https://github.com/awslabs/aws-crt-php.git > git clone --recursive https://github.com/awslabs/aws-crt-php.git
> git clone https://github.com/microsoft/php-sdk-binary-tools.git C:\php-sdk > git clone https://github.com/microsoft/php-sdk-binary-tools.git C:\php-sdk
> C:\php-sdk\phpsdk-vs16-x64.bat > C:\php-sdk\phpsdk-vs16-x64.bat
@@ -80,6 +81,7 @@ set CMAKE_GENERATOR_PLATFORM=x64
``` ```
## Debugging ## Debugging
Using [PHPBrew](https://github.com/phpbrew/phpbrew) to build/manage multiple versions of PHP is helpful. Using [PHPBrew](https://github.com/phpbrew/phpbrew) to build/manage multiple versions of PHP is helpful.
Note: You must use a debug build of PHP to debug native extensions. Note: You must use a debug build of PHP to debug native extensions.
@@ -96,13 +98,20 @@ $ ./configure
$ make CMAKE_BUILD_TYPE=Debug $ make CMAKE_BUILD_TYPE=Debug
``` ```
Ensure that the php you launch from your debugger is the result of `which php`, not just Ensure that the php you launch from your debugger is the result of `which php` , not just
the system default php. the system default php.
## Security ## Security
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
## Known OpenSSL related issue (Unix only)
* When your php loads a different version of openssl than your system openssl version, awscrt may fail to load or weirdly crash. You can find the openssl version php linked via: `php -i | grep 'OpenSSL'`, and awscrt linked from the build log, which will be `Found OpenSSL: * (found version *)`
The easiest workaround to those issue is to build from source and get aws-lc for awscrt to depend on instead.
TO do that, same instructions as [here](#building-from-github-source), but use `USE_OPENSSL=OFF make` instead of `make`
## License ## License
This project is licensed under the Apache-2.0 License. This project is licensed under the Apache-2.0 License.
+2
View File
@@ -60,6 +60,8 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
# define XRETURN_STRING(s) RETURN_STRING(s, 1) # define XRETURN_STRING(s) RETURN_STRING(s, 1)
# define XRETVAL_STRINGL(s, l) RETVAL_STRINGL(s, l, 1) # define XRETVAL_STRINGL(s, l) RETVAL_STRINGL(s, l, 1)
# define XRETVAL_STRING(s) RETVAL_STRING(s, 1) # define XRETVAL_STRING(s) RETVAL_STRING(s, 1)
/* zend_error_noreturn is not public until PHP7, but may still be visible with some PHP 5.X distributions */
# define zend_error_noreturn zend_error
#endif /* PHP 5.x */ #endif /* PHP 5.x */
#include "api.h" #include "api.h"