From 078df4825c16f8f5bf6a517e440ef5b9f67b2535 Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Thu, 17 Jun 2021 09:21:00 -0700 Subject: [PATCH] Windows build (#29) * Added build instruction updates for Windows to README * Added composer to requirements --- .gitignore | 2 ++ Makefile.frag | 24 ++++++++++-------------- Makefile.frag.w32 | 35 +++++++++++++++++++++++++++++++++++ README.md | 42 +++++++++++++++++++++++++++++++++++++++--- composer.json | 7 ++++--- config.w32 | 13 +++++++++++++ crt/aws-crt-ffi | 2 +- gen_api.php | 24 ++++++++++++++++++++++++ php-win.ini | 2 ++ php.ini | 1 + run_tests | 5 +++++ run_tests.bat | 4 ++++ src/php.ini | 2 -- 13 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 Makefile.frag.w32 create mode 100644 config.w32 create mode 100644 gen_api.php create mode 100644 php-win.ini create mode 100644 php.ini create mode 100755 run_tests create mode 100644 run_tests.bat delete mode 100644 src/php.ini diff --git a/.gitignore b/.gitignore index d719482..531374f 100644 --- a/.gitignore +++ b/.gitignore @@ -194,6 +194,8 @@ config.nice *.la Makefile* !Makefile.am +!Makefile.frag +!Makefile.frag.w32 /vendor/ .idea/ .DS_Store diff --git a/Makefile.frag b/Makefile.frag index 1df88a3..afb6113 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -1,8 +1,5 @@ -BUILD_DIR=$(shell pwd)/build -DEPS_DIR=$(BUILD_DIR)/deps -INT_DIR=$(BUILD_DIR)/install -INSTALL_DIR=$(shell pwd) +INT_DIR=build/install GENERATE_STUBS=$(shell expr `php --version | head -1 | cut -f 2 -d' '` \>= 7.1) HAS_FFI=$(shell php -m | grep FFI | wc -l | xargs) @@ -11,7 +8,7 @@ ifeq (, $(shell which cmake3)) CMAKE = cmake endif -CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(INT_DIR) -DCMAKE_PREFIX_PATH=$(INT_DIR) -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) +CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(INT_DIR) -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) CMAKE_BUILD = $(CMAKE) --build CMAKE_BUILD_TYPE ?= RelWithDebInfo CMAKE_TARGET = --config $(CMAKE_BUILD_TYPE) --target install @@ -20,11 +17,11 @@ all: extension ffi .PHONY: all extension ffi # configure for static aws-crt-ffi.a -$(BUILD_DIR)/aws-crt-ffi-static/CMakeCache.txt: +build/aws-crt-ffi-static/CMakeCache.txt: $(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi-static -DBUILD_SHARED_LIBS=OFF # build static libaws-crt-ffi.a -$(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a: $(BUILD_DIR)/aws-crt-ffi-static/CMakeCache.txt +build/aws-crt-ffi-static/libaws-crt-ffi.a: build/aws-crt-ffi-static/CMakeCache.txt $(CMAKE_BUILD) build/aws-crt-ffi-static $(CMAKE_TARGET) # PHP extension target @@ -33,7 +30,7 @@ extension: ext/awscrt.lo # Force the crt object target to depend on the CRT static library ext/awscrt.lo: ext/awscrt.c -ext/awscrt.c: $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h ext/awscrt_arginfo.h +ext/awscrt.c: build/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h ext/awscrt_arginfo.h ext/awscrt_arginfo.h: ext/awscrt.stub.php gen_stub.php ifeq ($(GENERATE_STUBS),1) @@ -43,7 +40,7 @@ endif # transform/install api.h from FFI lib 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 '^#' > src/api.h + php gen_api.php crt/aws-crt-ffi/src/api.h > src/api.h # install api.h to ext/ as well ext/api.h : src/api.h @@ -55,21 +52,21 @@ ext/php_aws_crt.h: ext/awscrt_arginfo.h ext/api.h ffi: src/api.h src/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) # configure for shared aws-crt-ffi.so -$(BUILD_DIR)/aws-crt-ffi-shared/CMakeCache.txt: +build/aws-crt-ffi-shared/CMakeCache.txt: ifeq ($(HAS_FFI),1) $(CMAKE_CONFIGURE) -Hcrt/aws-crt-ffi -Bbuild/aws-crt-ffi-shared -DBUILD_SHARED_LIBS=ON endif # build shared libaws-crt-ffi.so -$(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME): $(BUILD_DIR)/aws-crt-ffi-shared/CMakeCache.txt +build/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME): build/aws-crt-ffi-shared/CMakeCache.txt ifeq ($(HAS_FFI),1) $(CMAKE_BUILD) build/aws-crt-ffi-shared $(CMAKE_TARGET) endif # copy the lib into the src folder -src/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME): $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) src/api.h +src/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME): build/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) src/api.h ifeq ($(HAS_FFI),1) - cp -v $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) src/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) + cp -v build/aws-crt-ffi-shared/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) src/libaws-crt-ffi.$(SHLIB_SUFFIX_NAME) endif vendor/bin/phpunit: @@ -85,4 +82,3 @@ test-extension: vendor/bin/phpunit extension # Use PHPUnit to run tests test: test-ffi test-extension - diff --git a/Makefile.frag.w32 b/Makefile.frag.w32 new file mode 100644 index 0000000..548ea4d --- /dev/null +++ b/Makefile.frag.w32 @@ -0,0 +1,35 @@ + +CMAKE=cmake.exe +COMPOSER_PHAR=C:\ProgramData\ComposerSetup\bin\composer.phar +PHP_BINARY=$(PHP_PREFIX)\php.exe + +CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(AWSCRT_DIR)\build\install -DCMAKE_PREFIX_PATH=$(AWSCRT_DIR)\build\install -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) +CMAKE_BUILD = $(CMAKE) --build +CMAKE_BUILD_TYPE = Release +CMAKE_TARGET = --config $(CMAKE_BUILD_TYPE) --target install + +# configure for static aws-crt-ffi.lib +$(AWSCRT_DIR)\build\CMakeCache.txt: + $(CMAKE_CONFIGURE) -H$(AWSCRT_DIR)\crt\aws-crt-ffi -B$(AWSCRT_DIR)\build -DBUILD_SHARED_LIBS=OFF + +# build static libaws-crt-ffi.lib +$(AWSCRT_DIR)\build\libaws-crt-ffi.lib: $(AWSCRT_DIR)\build\CMakeCache.txt + $(CMAKE_BUILD) $(AWSCRT_DIR)\build $(CMAKE_TARGET) + +# Force the awscrt extension DLL target to depend on the extension src +$(BUILD_DIR)\php_awscrt.dll: $(AWSCRT_DIR)\ext\awscrt.c + +$(AWSCRT_DIR)\ext\awscrt.c: $(AWSCRT_DIR)\build\libaws-crt-ffi.lib $(AWSCRT_DIR)\ext\api.h $(AWSCRT_DIR)\ext\awscrt_arginfo.h + +# transform\install api.h from FFI lib +$(AWSCRT_DIR)\src\api.h: $(AWSCRT_DIR)\crt\aws-crt-ffi\src\api.h + php $(AWSCRT_DIR)\gen_api.php $(AWSCRT_DIR)\crt\aws-crt-ffi\src\api.h > $(AWSCRT_DIR)\src\api.h + +# install api.h to ext/ as well +$(AWSCRT_DIR)\ext\api.h : $(AWSCRT_DIR)\src\api.h + copy $(AWSCRT_DIR)\src\api.h $(AWSCRT_DIR)\ext\api.h + +# Use PHPUnit to run tests +test-awscrt: install $(AWSCRT_DIR)\src\api.h $(BUILD_DIR)\php_awscrt.dll + $(PHP_BINARY) -c $(AWSCRT_DIR)\php-win.ini $(COMPOSER_PHAR) --working-dir=$(AWSCRT_DIR) update + $(PHP_BINARY) -c $(AWSCRT_DIR)\php-win.ini $(COMPOSER_PHAR) --working-dir=$(AWSCRT_DIR) run test-win diff --git a/README.md b/README.md index 9a0e7d7..9c691aa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # AWS Common Runtime PHP bindings ## Requirements -* PHP 5.6+ +* PHP 5.5+ on UNIX platforms, 7.2+ on Windows * CMake 3.x -* GCC 4.4+, clang 3.8+ +* GCC 4.4+, clang 3.8+ on UNIX, Visual Studio 2017 build tools on Windows +* Tests require [Composer](https://getcomposer.org) ## Building on UNIX ```sh @@ -14,6 +15,42 @@ $ ./configure $ make && make test ``` +## Building on Windows +* First, ensure that you are able to build PHP on windows via the PHP SDK (this example assumes installation of the SDK to C:\php-sdk and that you've checked out the PHP source to php-src within the build directory). The following resources are helpful to get PHP building on windows: + * https://github.com/microsoft/php-sdk-binary-tools + * https://medium.com/@erinus/how-to-build-php-on-windows-a7ad0a87862a + * https://medium.com/@erinus/how-to-build-php-extension-on-windows-d1667290f809 + +```bat +""" From VS2017 Command Prompt +> C:\php-sdk\phpsdk-vc15-x64.bat + +C:\php-sdk\ +$ phpsdk_buildtree php- + +C:\php-sdk\php-\vc15\x64\ +$ git clone https://github.com/php/php-src.git && cd php-src + +""" This only has to be done once, the first time you set this all up +C:\php-sdk\php-\vc15\x64\php-src +$ phpsdk_deps --update --branch + +C:\php-sdk\php-\vc15\x64\php-src +$ git clone --recursive https://github.com/awslabs/aws-crt-php.git ..\pecl\awscrt + +C:\php-sdk\php-\vc15\x64\php-src +$ buildconf + +C:\php-sdk\php-\vc15\x64\php-src +$ configure --enable-cli --with-openssl --enable-awscrt=shared + +C:\php-sdk\php-\vc15\x64\php-src +$ nmake + +C:\php-sdk\php-\vc15\x64\php-src +$ nmake test-awscrt +``` + ## Security See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. @@ -21,4 +58,3 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform ## License This project is licensed under the Apache-2.0 License. - diff --git a/composer.json b/composer.json index 5a082e8..f201d6a 100644 --- a/composer.json +++ b/composer.json @@ -29,9 +29,10 @@ ] }, "scripts": { - "test": "@php -d extension=modules/awscrt.so vendor/bin/phpunit tests", - "test-extension": "@php -d extension=modules/awscrt.so vendor/bin/phpunit tests", - "test-ffi": "@php vendor/bin/phpunit tests" + "test": "./run_tests", + "test-extension": "@test", + "test-ffi": "@php vendor/bin/phpunit tests", + "test-win": "run_tests" }, "license": "Apache-2.0" } diff --git a/config.w32 b/config.w32 new file mode 100644 index 0000000..ed08402 --- /dev/null +++ b/config.w32 @@ -0,0 +1,13 @@ +// vim:ft=javascript + +ARG_ENABLE("awscrt", "Include AWS Common Runtime support", "yes"); + +if (PHP_AWSCRT != "no") { + ADD_MAKEFILE_FRAGMENT(); + DEFINE('CFLAGS_AWSCRT', '/I ' + configure_module_dirname + '\\build\\install\\include'); + DEFINE('LIBS_AWSCRT', '/LIBPATH:' + configure_module_dirname + '\\build\\install\\lib ' + + 'aws-crt-ffi.lib aws-c-auth.lib aws-c-http.lib aws-c-io.lib aws-c-cal.lib aws-c-compression.lib aws-c-common.lib ' + + 'ncrypt.lib Secur32.lib Crypt32.lib Shlwapi.lib'); + DEFINE('AWSCRT_DIR', configure_module_dirname); + EXTENSION("awscrt", "ext\\awscrt.c", PHP_AWSCRT_SHARED); +} diff --git a/crt/aws-crt-ffi b/crt/aws-crt-ffi index 61f7a7a..14b72a2 160000 --- a/crt/aws-crt-ffi +++ b/crt/aws-crt-ffi @@ -1 +1 @@ -Subproject commit 61f7a7adcc5ffc143f515dc6030150acb7ce3632 +Subproject commit 14b72a2fda3d81f1397057869fba8cc25530d741 diff --git a/gen_api.php b/gen_api.php new file mode 100644 index 0000000..d534434 --- /dev/null +++ b/gen_api.php @@ -0,0 +1,24 @@ +