bcgen icon indicating copy to clipboard operation
bcgen copied to clipboard

Windows dll

Open vjardin opened this issue 5 years ago • 16 comments

Please, can you provide builds with bcgen dll for Windows?

vjardin avatar Aug 02 '18 15:08 vjardin

Windows is not my target. If you want to support the Windows platform, please feel free to support this platform. Maybe you can create Travis-CI file to compile this PECL extension for Windows in the MINGW environment. I have not checked if this is possible though.

nanosonde avatar Aug 03 '18 06:08 nanosonde

Understood. First let's get the other fix before tackling Windows.

vjardin avatar Aug 03 '18 07:08 vjardin

Windows compilation fails, I'll check the root cause. See below some notes to compile it:

# Follow README.md - https://github.com/Microsoft/php-sdk-binary-tools/blob/master/README.md
$ cd C:\
$ git clone https://github.com/Microsoft/php-sdk-binary-tools.git c:\php-sdk
$ cd c:\php-sdk
$ phpsdk-vc15-x64.bat # assuming Visual Studio 2017 / Window 64 bits
$ phpsdk_buildtree phpmaster
$ git clone https://github.com/php/php-src.git
$ cd C:\php-sdk\phpmaster\vc15\x64\php-src
$ phpsdk_deps --update --branch master
$ buildconf
$ configure --enable-json --enable-sockets --enable-hash --enable-cli --enable-cgi --enable-session --enable-calendar --enable-ipv6 --enable-mbstring --enable-fileinfo --enable-zlib
$ nmake
$ nmake install

# build pecl - bcgen
$ mkdir C:\php-sdk\phpmaster\vc15\x64\pecl
$ cd C:\php-sdk\phpmaster\vc15\x64\pecl
$ git clone https://github.com/nanosonde/bcgen.git
$ cd C:\php-sdk\phpmaster\vc15\x64\php-src
$ buildconf --force
$ configure --disable-all --enable-cli --enable-cgi --enable-bcgen
$ nmake

zend_persist_calc.c
zend_shared_alloc.c ..\pecl\bcgen\zend_accelerator_util_funcs.c(50): error C2105: '--' necessite une l-value
..\pecl\bcgen\zend_persist.c(73): warning C4146: operateur moins unaire applique a un type non signe, le resultat sera non signe

vjardin avatar Aug 05 '18 12:08 vjardin

@nanosonde Many files from bcgen are extracted from opcache. Upstream opcache is able to compile on Windows so I was hoping to get a quick solution thanks to opcache. However, when I try to analyze the modifications that you have applied on bcgen out of opcache, I cannot get it from your git logs.

For instance:

commit aadfa2c6e65f7be872efe6c1de445e2006602eeb
Author: Cille <[email protected]>
Date:   Mon May 14 17:42:23 2018 +0200

    Initial commit of BCgen for PHP-7.2

This initial commit seems to already have some modifications. I cannot find the same vanilla codes from any tag from https://github.com/php/php-src

Please, can you describe a bit more? Or do you have some records somewhere so we can rebase bcgen with https://github.com/php/php-src/tree/master/ext/opcache ?

vjardin avatar Aug 05 '18 15:08 vjardin

@vjardin Hi! First of all, I will be on vacation for three weeks now. After that I have project deadline at the 1.10.2018. So I won't be able to investigate further at the moment.

Unfortunately, there is no commit history for the modifications. :(

What I basically did is to assume the the opcache option "file_cache_only"is set to true. With this assumptions I have studied the opcache code and was supprised how much code could be removed. The most stuff in opcache is related to shared memory caching (SHM) and maintaining interned strings in the SHM. However, the file_cache_only option forces opcache to NOT use SHM, although the file content is loaded into memory for obvious reasons though. I have kept the function names of the most relevant files zend_persist.c, zend_persist_calc.c and zend_file_cache.c the same. With a DIFF tool it is still possible to compare opache and bcgen code.

nanosonde avatar Aug 07 '18 06:08 nanosonde

Thank you. Just in case, do you remember the git hash/tag that you started from?

Enjoy your holidays.

vjardin avatar Aug 07 '18 07:08 vjardin

I have started from this branch: https://github.com/php/php-src/tree/PHP-7.2.6

nanosonde avatar Aug 10 '18 05:08 nanosonde

The master branch is based on https://github.com/php/php-src/tree/master

Arround the date of the initial GitHub commit here.

nanosonde avatar Aug 10 '18 06:08 nanosonde

So do you mean around the date of : 57a916f
Initial checkin for PHP-7.3 on master branch ?

From may 14h ? https://github.com/nanosonde/bcgen/commit/57a916fce52b3cc90a4d89b33d7e20f28c58235d

vjardin avatar Aug 10 '18 08:08 vjardin

Please see this initial commit on the 7.2 branch. https://github.com/nanosonde/bcgen/commit/aadfa2c6e65f7be872efe6c1de445e2006602eeb

nanosonde avatar Aug 11 '18 13:08 nanosonde

BTW: if you want to compare BCgen with the original OPcache from 7.2.6:

  • the optimizer directory has just been copied over. You could even leave out the optimizer at all
  • the tests directory contains only the tests from the old bcompiler adapted to run with BCgen and PHP7
  • most important stuff for serialization/deserialization is in zend_file_cache.[ch], zend_persist.[ch] and zend_persist_calc.c
  • I have kept the function names the same as in OPcache code. However, I have removed function arguments like the famous "shm" bool where they were not needed anymore.
  • it was relatively easy to follow matching Opcache minor version changes 7.2.x with only minor changes
  • Just follow what changed in OPcache upsteam, understand what needs to be done in BCgen then. ;)

nanosonde avatar Aug 11 '18 13:08 nanosonde

Currently, I am using bcgen with PHP 7.2 (but not the head yet / PHP 7.3). It works fine. Could you register bcgen on PECL: https://pecl.php.net/account-request.php or would you be OK if I do it on your behalf?

thank you,

vjardin avatar Aug 11 '18 23:08 vjardin

If you could register it on PECL that would be fine.

One remark concerning platform compatibility: BCgen puts the sizes of char, int, long, together with the alignment and the architecture (32bit/64bit) in the header of each file. Currently, the code does not bail out if things do not match as I wanted to experiment with it. After some experiments with 64bit/32 bit and X86 and ARM, I can say that BCgen compiled for one architecture size work on either platform: so x86 64-bit works on ARM 64 bit. But you cannot use 32 bit BCgen compiled stuff on 64 bit version and vice versa. I have always used PHP-7.2.6 for my tests and compiled it myself.

So the check of the header signature need to be strict: if some values in the header of a provided BCgen compiled file does not match the current values, then BCgen must exit as it would crash otherwise as the datatype sizes do not match.

I think that the datatype size problem could be fixed by always putting smaller datatypes into bigger ones, but at the moment I do not care about this. If someone wants to provide BCgen compiled files, just two versions have to be provided: for 32-bit and for 64-bit I can live with this caveat, especially because 64-bit becomes more popular every day.

nanosonde avatar Aug 12 '18 08:08 nanosonde

thanks for these comments. I'll check them. Meanwhile, for the records, https://marc.info/?l=pecl-dev&m=153411407006547&w=2

vjardin avatar Aug 12 '18 22:08 vjardin

@vjardin Did the bcgen can build dll for windows now?

jin-pan avatar Mar 20 '20 07:03 jin-pan

Yes, it does compile: we use it.

vjardin avatar Mar 20 '20 09:03 vjardin