mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 01:57:13 +00:00
Initial skeleton to make extension support CRT FFI API (#11)
* Fixed build issues with static CRT, separated ffi target * Fixed makefile for test-ffi target
This commit is contained in:
+31
-16
@@ -32,28 +32,43 @@ CMAKE_BUILD = $(CMAKE) --build
|
||||
CMAKE_BUILD_TYPE ?= RelWithDebInfo
|
||||
CMAKE_TARGET = --config $(CMAKE_BUILD_TYPE) --target install
|
||||
|
||||
# cmake configure depends on libcrypto above
|
||||
$(BUILD_DIR)/aws-crt-ffi/CMakeCache.txt: $(INT_DIR)/lib/libcrypto.a
|
||||
$(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi
|
||||
# configure for shared aws-crt-ffi.so
|
||||
$(BUILD_DIR)/aws-crt-ffi-shared/CMakeCache.txt: $(INT_DIR)/lib/libcrypto.a
|
||||
$(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi-shared -DBUILD_SHARED_LIBS=ON
|
||||
|
||||
# build the FFI library
|
||||
$(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi/CMakeCache.txt
|
||||
$(CMAKE_BUILD) build/aws-crt-ffi $(CMAKE_TARGET)
|
||||
# build shared libaws-crt-ffi.so
|
||||
$(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi-shared/CMakeCache.txt
|
||||
$(CMAKE_BUILD) build/aws-crt-ffi-shared $(CMAKE_TARGET)
|
||||
|
||||
# copy the lib into the src folder
|
||||
$(INSTALL_DIR)/src/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so $(INSTALL_DIR)/src/api.h
|
||||
cp -v $(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so $(INSTALL_DIR)/src/libaws-crt-ffi.so
|
||||
# configure for static aws-crt-ffi.a
|
||||
$(BUILD_DIR)/aws-crt-ffi-static/CMakeCache.txt: $(INT_DIR)/lib/libcrypto.a
|
||||
$(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi-static -DBUILD_SHARED_LIBS=OFF
|
||||
|
||||
# install api.h from FFI lib
|
||||
# build static libaws-crt-ffi.a
|
||||
$(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a: $(BUILD_DIR)/aws-crt-ffi-static/CMakeCache.txt
|
||||
$(CMAKE_BUILD) build/aws-crt-ffi-static $(CMAKE_TARGET)
|
||||
|
||||
# PHP extension target
|
||||
extension: ext/crt.lo
|
||||
|
||||
# Force the crt object target to depend on the CRT static library
|
||||
ext/crt.lo: $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h
|
||||
|
||||
# transform/install api.h from FFI lib
|
||||
$(INSTALL_DIR)/src/api.h: crt/aws-crt-ffi/src/api.h
|
||||
cat crt/aws-crt-ffi/src/api.h | grep -v AWS_EXTERN_C | sed -e 's/AWS_CRT_API //' | grep -ve '^#' > $(INSTALL_DIR)/src/api.h
|
||||
|
||||
# copy the FFI lib from src to ext for the extension to use
|
||||
$(INSTALL_DIR)/ext/libaws-crt-ffi.so: $(INSTALL_DIR)/src/libaws-crt-ffi.so
|
||||
cp -v $(INSTALL_DIR)/src/libaws-crt-ffi.so $(INSTALL_DIR)/ext/libaws-crt-ffi.so
|
||||
# install api.h to ext/ as well
|
||||
ext/api.h : $(INSTALL_DIR)/src/api.h
|
||||
cp -v $(INSTALL_DIR)/src/api.h ext/api.h
|
||||
|
||||
# Force the crt object target to depend on the FFI library
|
||||
ext/crt.lo: $(INSTALL_DIR)/ext/libaws-crt-ffi.so
|
||||
# FFI target
|
||||
ffi: src/libaws-crt-ffi.so
|
||||
TEST_FFI = 1
|
||||
|
||||
# copy the lib into the src folder
|
||||
src/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so $(INSTALL_DIR)/src/api.h
|
||||
cp -v $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so $(INSTALL_DIR)/src/libaws-crt-ffi.so
|
||||
|
||||
ifeq ($(TEST_FFI),1)
|
||||
test-ci: test-ffi
|
||||
@@ -62,6 +77,6 @@ test-ci: test
|
||||
endif
|
||||
|
||||
# Test the FFI interface
|
||||
test-ffi: $(INSTALL_DIR)/src/libaws-crt-ffi.so
|
||||
test-ffi: src/libaws-crt-ffi.so
|
||||
composer update
|
||||
composer run test
|
||||
|
||||
@@ -8,8 +8,8 @@ PHP_ARG_WITH(awscrt)
|
||||
if test "$PHP_AWSCRT" != "no"; then
|
||||
# force lib paths to be absolute, or PHP will mangle them
|
||||
cwd=`pwd`
|
||||
CRT_LIBPATHS="-L${cwd}/build/install/lib64 -L${cwd}/build/install/lib"
|
||||
CRT_LIBS="-laws-c-auth -laws-c-http -laws-c-cal -laws-c-io -laws-c-compression -laws-c-common -ls2n -l:libcrypto.a"
|
||||
CRT_LIBPATHS="-L${cwd}/build/install/lib"
|
||||
CRT_LIBS="-laws-crt-ffi -laws-c-auth -laws-c-http -laws-c-cal -laws-c-io -laws-c-compression -laws-c-common -ls2n -l:libcrypto.a"
|
||||
PHP_ADD_INCLUDE(${cwd}/build/install/include)
|
||||
PHP_EVAL_LIBLINE([$CRT_LIBPATHS $CRT_LIBS], AWSCRT_SHARED_LIBADD)
|
||||
|
||||
|
||||
+1
-1
Submodule crt/aws-crt-ffi updated: f865650224...56b60e586b
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "php_aws_crt.h"
|
||||
|
||||
#include "api.h"
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(awscrt);
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
@@ -21,12 +23,14 @@ PHP_INI_END()
|
||||
|
||||
static PHP_MINIT_FUNCTION(awscrt) {
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
aws_crt_init();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static PHP_MSHUTDOWN_FUNCTION(awscrt) {
|
||||
UNREGISTER_INI_ENTRIES();
|
||||
|
||||
aws_crt_clean_up();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -37,6 +41,7 @@ static PHP_GINIT_FUNCTION(awscrt) {
|
||||
awscrt_globals->log_level = 0;
|
||||
}
|
||||
|
||||
/* awscrt_version */
|
||||
ZEND_BEGIN_ARG_INFO(awscrt_version_arginfo, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
@@ -44,9 +49,19 @@ PHP_FUNCTION(awscrt_version) {
|
||||
static const char *version = "1.0.0-dev";
|
||||
AWS_RETURN_STRING(version);
|
||||
}
|
||||
|
||||
/* aws_crt_last_error() */
|
||||
ZEND_BEGIN_ARG_INFO(aws_crt_last_error_arginfo, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
PHP_FUNCTION(aws_crt_last_error) {
|
||||
RETURN_LONG(aws_crt_last_error());
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
const zend_function_entry awscrt_functions[] = {
|
||||
PHP_FE(awscrt_version, awscrt_version_arginfo)
|
||||
PHP_FE(aws_crt_last_error, aws_crt_last_error_arginfo)
|
||||
PHP_FE_END
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
aws_crt_last_error
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/common.inc');
|
||||
|
||||
echo aws_crt_last_error();
|
||||
?>
|
||||
--EXPECT--
|
||||
0
|
||||
Reference in New Issue
Block a user