From 3fed54755168046c70762db55543cc8efe2100ff Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Fri, 29 Jan 2021 13:44:55 -0800 Subject: [PATCH] Imported CRT FFI lib (#7) * Added php7 library skeleton * Re-worked Makefile.frag to use paths correctly * Added gitignore for lib * clang-format * Remove symlinked api.h * Copy api.h into lib/ as part of build --- Makefile.frag | 40 +++++++++++++++++++++++++++++----------- lib/.gitignore | 3 +++ lib/crt.php | 35 +++++++++++++++++++++++++++++++++++ lib/php.ini | 2 ++ lib/preload.php | 7 +++++++ lib/test.php | 7 +++++++ 6 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 lib/.gitignore create mode 100644 lib/crt.php create mode 100644 lib/php.ini create mode 100644 lib/preload.php create mode 100644 lib/test.php diff --git a/Makefile.frag b/Makefile.frag index 7668383..a1629e8 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -1,34 +1,52 @@ -INSTALL_DIR=$(shell pwd)/build/install +BUILD_DIR=$(shell pwd)/build +DEPS_DIR=$(BUILD_DIR)/deps +INT_DIR=$(BUILD_DIR)/install +INSTALL_DIR=$(shell pwd) + +CMAKE = cmake3 +ifeq (, $(shell which cmake3)) + CMAKE = cmake +endif # download and build libcrypto.a for the CRT with -fPIC -build/deps/openssl: +$(DEPS_DIR)/openssl: @echo Fetching libcrypto source - git clone --depth=1 --single-branch --branch OpenSSL_1_1_1-stable https://github.com/openssl/openssl.git build/deps/openssl + git clone --depth=1 --single-branch --branch OpenSSL_1_1_1-stable https://github.com/openssl/openssl.git $(DEPS_DIR)/openssl -$(INSTALL_DIR)/lib/libcrypto.a: build/deps/openssl +$(INT_DIR)/lib/libcrypto.a: $(DEPS_DIR)/openssl @echo Building libcrypto - cd build/deps/openssl && \ + cd $(DEPS_DIR)/openssl && \ ./config -fPIC no-md2 no-rc5 no-rfc3779 no-sctp no-ssl-trace no-zlib no-hw no-mdc2 no-seed no-idea \ no-camellia no-bf no-dsa no-ssl3 no-capieng \ -DSSL_FORBID_ENULL -DOPENSSL_NO_DTLS1 -DOPENSSL_NO_HEARTBEATS \ - --prefix=$(INSTALL_DIR) --openssldir=$(INSTALL_DIR) && \ + --prefix=$(INT_DIR) --openssldir=$(INT_DIR) && \ make -j && \ make install_sw + mkdir -p $(INT_DIR)/lib + ln -s $(INT_DIR)/lib64/libcrypto.a $(INT_DIR)/lib/libcrypto.a || true -CMAKE_CONFIGURE = cmake -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) -DCMAKE_PREFIX_PATH=$(INSTALL_DIR) -DBUILD_TESTING=OFF -CMAKE_BUILD = cmake --build +CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(INT_DIR) -DCMAKE_PREFIX_PATH=$(INT_DIR) -DBUILD_TESTING=OFF +CMAKE_BUILD = $(CMAKE) --build CMAKE_BUILD_TYPE ?= RelWithDebInfo -CMAKE_TARGET = --config $CMAKE_BUILD_TYPE --target install +CMAKE_TARGET = --config $(CMAKE_BUILD_TYPE) --target install # cmake configure depends on libcrypto above -build/aws-crt-ffi/CMakeCache.txt: $(INSTALL_DIR)/lib/libcrypto.a +$(BUILD_DIR)/aws-crt-ffi/CMakeCache.txt: $(INT_DIR)/lib/libcrypto.a $(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi # build the FFI library -$(INSTALL_DIR)/lib/libaws-crt-ffi.so: build/aws-crt-ffi/CMakeCache.txt +$(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi/CMakeCache.txt $(CMAKE_BUILD) build/aws-crt-ffi $(CMAKE_TARGET) +# copy the lib into the lib folder +$(INSTALL_DIR)/lib/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so $(INSTALL_DIR)/lib/api.h + cp -v $(BUILD_DIR)/aws-crt-ffi/libaws-crt-ffi.so $(INSTALL_DIR)/lib/libaws-crt-ffi.so + +# install api.h from FFI lib +$(INSTALL_DIR)/lib/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)/lib/api.h + # Force the crt object target to depend on the FFI library src/crt.lo: $(INSTALL_DIR)/lib/libaws-crt-ffi.so diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..0445360 --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1,3 @@ +api.h +pkgconfig/ +*.so* diff --git a/lib/crt.php b/lib/crt.php new file mode 100644 index 0000000..fc09f58 --- /dev/null +++ b/lib/crt.php @@ -0,0 +1,35 @@ +getMessage(), "\n"; + } + } + } + + function init() { + return self::$ffi->aws_crt_init(); + } + + function clean_up() { + return self::$ffi->aws_crt_clean_up(); + } + + function last_error() { + return self::$ffi->aws_crt_last_error(); + } + + function error_str($error) { + return self::$ffi->aws_crt_error_str((int) $error); + } + + function error_name($error) { + return self::$ffi->aws_crt_error_name((int) $error); + } +} diff --git a/lib/php.ini b/lib/php.ini new file mode 100644 index 0000000..5386e02 --- /dev/null +++ b/lib/php.ini @@ -0,0 +1,2 @@ +ffi.enable=preload +opcache.preload=preload.php diff --git a/lib/preload.php b/lib/preload.php new file mode 100644 index 0000000..379a2dd --- /dev/null +++ b/lib/preload.php @@ -0,0 +1,7 @@ +init(); +var_dump($crt->error_name(0)); +$crt->clean_up();