Drupal 8 & Twig C extension: tip on building the extension for Acquia Dev Desktop 2 context

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Trebor's picture

A note about the Twig C extension (offers enhanced theme performance) for use with Drupal 8 in the context of Acquia Dev Desktop 2

I discovered that if you follow the instructions to build the Twig C extension (OS X context) per:

http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension

$ cd ext/twig # my full path location was at: ~/.composer/vendor/twig/twig/ext/twig
$ phpize
$ ./configure
$ make
$ make install

You will get a 64-bit component as evidenced by using the file command on the resultant twig.so file:

$ file /Applications/DevDesktop/php5_6/ext/twig.so
/Applications/DevDesktop/php5_6/ext/twig.so: Mach-O 64-bit bundle x86_64

But the PHP component in Acquia Dev Desktop 2 is a 32-bit component:

$ file /Applications/DevDesktop/php5_6/bin/php
/Applications/DevDesktop/php5_6/bin/php: Mach-O executable i386

To build the twig.so as a 32-bit component, you need to rebuild it with the following modified configure line:

$ cd ext/twig # my full path location was at: ~/.composer/vendor/twig/twig/ext/twig
$ phpize
$ CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure
$ make
$ make install

Other local dev environments such as MAMP and XAMPP have a 64-bit PHP component, so this modification from the main Twig C extension instructions is not needed.

Additionally, if you try to interact with an environment that has the wrong build of the twig.so file installed, you get errors such as:

PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/DevDesktop/php5_6/ext/twig.so' - dlopen(/Applications/DevDesktop/php5_6/ext/twig.so, 9): no suitable image found. Did find:
/Applications/DevDesktop/php5_6/ext/twig.so: mach-o, but wrong architecture in Unknown on line 0