diff --git a/config/pkg/ext/ext-luasandbox.yml b/config/pkg/ext/ext-luasandbox.yml new file mode 100644 index 000000000..908cce1ae --- /dev/null +++ b/config/pkg/ext/ext-luasandbox.yml @@ -0,0 +1,17 @@ +ext-luasandbox: + type: php-extension + artifact: + source: + type: git + url: 'https://github.com/wikimedia/mediawiki-php-luasandbox' + rev: master + metadata: + license-files: [COPYING] + license: MIT + depends: + - lua51 + php-extension: + os: + - Linux + - Darwin + arg-type: with diff --git a/config/pkg/lib/lua51.yml b/config/pkg/lib/lua51.yml new file mode 100644 index 000000000..92ac0e98e --- /dev/null +++ b/config/pkg/lib/lua51.yml @@ -0,0 +1,16 @@ +lua51: + type: library + artifact: + source: + type: filelist + url: 'https://www.lua.org/ftp/' + regex: '/href="(?lua-(?5\.1\.\d+)\.tar\.gz)"/i' + metadata: + license-files: [COPYRIGHT] + license: MIT + headers: + - lua5.1/lua.h + pkg-configs: + - lua5.1 + static-libs@unix: + - liblua5.1.a diff --git a/src/Package/Extension/luasandbox.php b/src/Package/Extension/luasandbox.php new file mode 100644 index 000000000..5fdd47c17 --- /dev/null +++ b/src/Package/Extension/luasandbox.php @@ -0,0 +1,29 @@ +getTargetPackage('php')->getSourceDir() . '/ext/luasandbox'; + $m4 = "{$ext_dir}/config.m4"; + if (file_exists($m4)) { + FileSystem::replaceFileStr($m4, 'm4_include([m4/pkg.m4])', 'm4_sinclude([ext/luasandbox/m4/pkg.m4])'); + FileSystem::replaceFileStr($m4, 'PHP_ADD_MAKEFILE_FRAGMENT', ''); + } + } +} diff --git a/src/Package/Library/lua51.php b/src/Package/Library/lua51.php new file mode 100644 index 000000000..f1317d07b --- /dev/null +++ b/src/Package/Library/lua51.php @@ -0,0 +1,68 @@ +getSourceDir() . '/src'; + $cc = getenv('SPC_DEFAULT_CC') ?: (getenv('CC') ?: 'cc'); + $ar = getenv('SPC_DEFAULT_AR') ?: (getenv('AR') ?: 'ar'); + $ranlib = getenv('SPC_DEFAULT_RANLIB') ?: (getenv('RANLIB') ?: 'ranlib'); + $cflags = trim((string) getenv('SPC_DEFAULT_CFLAGS') . ' -fPIC -DLUA_USE_POSIX'); + + shell()->cd($src) + ->initializeEnv($lib) + ->exec('make clean') + ->exec("make -j{$builder->concurrency} CC=" . escapeshellarg($cc) + . ' AR=' . escapeshellarg("{$ar} rcu") + . ' RANLIB=' . escapeshellarg($ranlib) + . ' MYCFLAGS=' . escapeshellarg($cflags) + . ' liblua.a'); + + $inc = $lib->getIncludeDir() . '/lua5.1'; + FileSystem::createDir($inc); + foreach (['lua.h', 'luaconf.h', 'lualib.h', 'lauxlib.h'] as $h) { + FileSystem::copy("{$src}/{$h}", "{$inc}/{$h}"); + } + if (file_exists("{$lib->getSourceDir()}/etc/lua.hpp")) { + FileSystem::copy("{$lib->getSourceDir()}/etc/lua.hpp", "{$inc}/lua.hpp"); + } + FileSystem::copy("{$src}/liblua.a", $lib->getLibDir() . '/liblua5.1.a'); + + $version = '5.1.5'; + $lua_h = file_get_contents("{$src}/lua.h"); + if (is_string($lua_h) && preg_match('/#define\s+LUA_RELEASE\s+"Lua\s+([^"]+)"/', $lua_h, $m) === 1) { + $version = $m[1]; + } + + $pc_dir = $lib->getLibDir() . '/pkgconfig'; + FileSystem::createDir($pc_dir); + $prefix = $lib->getBuildRootPath(); + $pc = <<setMemoryLimit(10 * 1024 * 1024); +$fn = $sandbox->loadString('return 1 + 2, "ok"'); +assert($fn->call() === [3, 'ok']);