Skip to content

Commit

Permalink
CGI build tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorris committed Jun 24, 2024
1 parent 452f079 commit 2e6c954
Show file tree
Hide file tree
Showing 78 changed files with 269 additions and 1,376 deletions.
60 changes: 34 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,29 @@ ifeq ($(filter ${WITH_TOKENIZER},0 1),)
$(error WITH_TOKENIZER MUST BE 0 or 1. PLEASE CHECK YOUR SETTINGS FILE: $(abspath ${ENV_FILE}))
endif

## More libraries
WITH_ICONV ?=1
WITH_LIBXML ?=1
WITH_LIBZIP ?=1
WITH_SQLITE ?=1
WITH_VRZNO ?=1
WITH_ZLIB ?=1

## Even more libraries...
WITH_PHAR ?=0
WITH_OPENSSL ?=0
WITH_GD ?=0
WITH_LIBPNG ?=0
WITH_LIBJPEG ?=0
WITH_FREETYPE?=0

## Extra libraries...
WITH_ONIGURUMA?=0
WITH_INTL ?=0
WITH_TIDY ?=0
WITH_EXIF ?=0
WITH_YAML ?=0
WITH_LIBXML?=shared

# ## More libraries
# WITH_ICONV ?=1
# WITH_LIBZIP ?=1
# WITH_SQLITE ?=1
# WITH_VRZNO ?=1
# WITH_ZLIB ?=1

# ## Even more libraries...
# WITH_PHAR ?=0
# WITH_OPENSSL ?=0
# WITH_GD ?=0
# WITH_LIBPNG ?=0
# WITH_LIBJPEG ?=0
# WITH_FREETYPE?=0

# ## Extra libraries...
# WITH_ONIGURUMA?=0
# WITH_INTL ?=0
# WITH_TIDY ?=0
# WITH_EXIF ?=0
# WITH_YAML ?=0

## Emscripten features...
NODE_RAW_FS ?=0
Expand Down Expand Up @@ -230,9 +231,6 @@ endif

PRELOAD_NAME=php

-include packages/php-cgi-wasm/static.mak
-include $(addsuffix /static.mak,$(shell npm ls -p))

ifdef PRELOAD_ASSETS
# DEPENDENCIES+=
PHP_ASSET_LIST+= ${PRELOAD_NAME}.data
Expand All @@ -243,6 +241,9 @@ ${PHP_ASSET_PATH}/${PRELOAD_NAME}.data: .cache/preload-collected
cp -Lprf packages/php-wasm/${PRELOAD_NAME}.data ${PHP_ASSET_PATH}/
endif

-include packages/php-cgi-wasm/static.mak
-include $(addsuffix /static.mak,$(shell npm ls -p))

########### Collect & patch the source code. ###########

third_party/php${PHP_VERSION}-src/patched: third_party/php${PHP_VERSION}-src/.gitignore
Expand All @@ -254,7 +255,11 @@ third_party/php${PHP_VERSION}-src/patched: third_party/php${PHP_VERSION}-src/.gi
${DOCKER_RUN} rm -rf /src/third_party/preload
ifdef PRELOAD_ASSETS
@ mkdir -p third_party/preload
ifdef PHP_BUILDER_DIR
@ cp -prfL $(addprefix ${PHP_BUILDER_DIR},${PRELOAD_ASSETS}) third_party/preload/
else
@ cp -prfL ${PRELOAD_ASSETS} third_party/preload/
endif
@ ${DOCKER_RUN} touch .cache/preload-collected
endif

Expand Down Expand Up @@ -728,7 +733,10 @@ clean:
packages/php-wasm/*.mjs* \
packages/php-cgi-wasm/*.data \
packages/php-cgi-wasm/*.mjs* \
third_party/php${PHP_VERSION}-src/configured
third_party/php${PHP_VERSION}-src/configured \
third_party/preload \
.cache/pre.js \
.cache/preload-collected
${MAKE} php-clean

deep-clean: clean
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ const php = new PhpWeb({ini: `
The following extensions may be loaded at runtime. This allows the shared extension & their dependencies to be cached, re-used, and selected a-la-carte for each application.
* gd (https://www.npmjs.com/package/php-wasm-gd, https://www.npmjs.com/package/php-wasm-libjpeg, https://www.npmjs.com/package/php-wasm-libpng, https://www.npmjs.com/package/php-wasm-freetype)
* gd (https://www.npmjs.com/package/php-wasm-gd)
* iconv (https://www.npmjs.com/package/php-wasm-iconv)
* intl (https://www.npmjs.com/package/php-wasm-intl)
* xml (https://www.npmjs.com/package/php-wasm-libxml)
Expand Down
99 changes: 55 additions & 44 deletions bin/php-wasm-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const commands = {};
});
};

build.info = `Build php-wasm.`;
build.info = `Build php-wasm, optionally using a .php-wasm-rc file in the current directory.`;
build.help = `Usage: php-wasm-builder build [ENV_NAME] [MODULE_TYPE] [BINARY_TYPE]
ENV_NAME: [web, node]
Expand Down Expand Up @@ -111,53 +111,11 @@ const commands = {};
};

image.info = 'Create the build environment docker image';
image.help = `Usage: php-wasm-builder image`
image.help = `Usage: php-wasm-builder image.`

commands.image = image;
}

{ // clean
const clean = () => {
const subprocess = child_process.spawn(`make`, ['deep-clean'], {
stdio: [ 'inherit', 'inherit', 'inherit' ],
cwd: __dirname + '/..',
});
};

clean.info = `Clear cached build resources`;
clean.help = `Usage: php-wasm-builder clean`;

commands.clean = clean;
}

{ // assets
const assets = () => {
const options = [
`PHP_BUILDER_DIR=${cwd}`,
`IS_TTY=${tty.isatty(process.stdout.fd) ? 1 : 0}`,
];

options.push(`ENV_DIR=${cwd}/`);

if(fs.existsSync(cwd + '/.php-wasm-rc'))
{
options.push(`ENV_FILE=${rcFile}`);
}

options.push('assets');

const subprocess = child_process.spawn(`make`, options, {
stdio: [ 'inherit', 'inherit', 'inherit' ],
cwd: __dirname + '/..',
});
};

assets.info = `Build shared libs & file packages to asset directory.`;
assets.help = `Usage: php-wasm-builder assets`;

commands.assets = assets;
}

{ // copy-assets
const copy_assets = () => {
const ls = child_process.spawnSync('npm', ['ls', '-p'], { encoding : 'utf8' });
Expand Down Expand Up @@ -224,6 +182,59 @@ const commands = {};
commands['copy-assets'] = copy_assets;
}

{ // build-assets
const build_assets = () => {
const options = [
`PHP_BUILDER_DIR=${cwd}`,
`IS_TTY=${tty.isatty(process.stdout.fd) ? 1 : 0}`,
];

options.push(`ENV_DIR=${cwd}/`);

if(fs.existsSync(cwd + '/.php-wasm-rc'))
{
options.push(`ENV_FILE=${rcFile}`);
}

options.push('assets');

const subprocess = child_process.spawn(`make`, options, {
stdio: [ 'inherit', 'inherit', 'inherit' ],
cwd: __dirname + '/..',
});
};

build_assets.info = `Build shared libs & file packages to asset directory.`;
build_assets.help = `Usage: php-wasm-builder assets`;

commands['build-assets'] = build_assets;
}

{ // clean
const clean = () => {
const subprocess = child_process.spawn(`make`, ['deep-clean'], {
stdio: [ 'inherit', 'inherit', 'inherit' ],
cwd: __dirname + '/..',
});
};

clean.info = `Clear cached build resources.`;
clean.help = `Usage: php-wasm-builder clean`;

commands.clean = clean;
}

{ // deep-clean
const deep_clean = () => {

};

deep_clean.info = 'Clear out all downloaded dependencies and start from scratch.';
deep_clean.help = `Usage: php-wasm-builder deep-clean`

commands['deep-clean'] = deep_clean;
}

{ // help
const help = (flags, command = null) => {
if(command)
Expand Down
Binary file not shown.
Loading

0 comments on commit 2e6c954

Please sign in to comment.