Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
type EmscriptenOptions,
type PHPRuntime,
type SupportedPHPVersion,
installPHPExtensionFilesSync,
PHP_EXTENSIONS_DIR,
} from '@php-wasm/universal';
import fs from 'fs';

export interface WpMysqlParserOptions {
/**
* Absolute path on the host filesystem to a `wp_mysql_parser.so` side
* module compiled for the target PHP version and async mode.
*
* The extension itself lives at
* https://github.com/WordPress/sqlite-database-integration/pull/381
* and is not yet packaged with Playground; users build it themselves
* (or fetch it from a release artifact) and pass the path via
* `--wp-mysql-parser-so=<path>` on the CLI.
*/
soPath: string;
}

/*
* The PR #381 build hasn't been validated against earlier PHP versions
* yet, so this run only wires it up for PHP 8.4. Widening to other
* versions is a one-line change once we have artifacts to test against.
*/
const SUPPORTED_VERSIONS: ReadonlyArray<SupportedPHPVersion> = ['8.4'];

export async function withWpMysqlParser(
version: SupportedPHPVersion,
options: EmscriptenOptions,
wpMysqlParserOptions: WpMysqlParserOptions
): Promise<EmscriptenOptions> {
if (!SUPPORTED_VERSIONS.includes(version)) {
throw new Error(
`withWpMysqlParser: only PHP ${SUPPORTED_VERSIONS.join(
', '
)} are supported in this build; got ${version}.`
);
}

const soBytes = new Uint8Array(
fs.readFileSync(wpMysqlParserOptions.soPath)
);

return {
...options,
ENV: {
...options.ENV,
PHP_INI_SCAN_DIR: PHP_EXTENSIONS_DIR,
},
onRuntimeInitialized: (phpRuntime: PHPRuntime) => {
if (options.onRuntimeInitialized) {
options.onRuntimeInitialized(phpRuntime);
}

installPHPExtensionFilesSync(phpRuntime.FS, {
name: 'wp_mysql_parser',
soBytes,
});
},
};
}
12 changes: 12 additions & 0 deletions packages/php-wasm/node/src/lib/load-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {
import { withIntl } from './extensions/intl/with-intl';
import { withRedis } from './extensions/redis/with-redis';
import { withMemcached } from './extensions/memcached/with-memcached';
import {
withWpMysqlParser,
type WpMysqlParserOptions,
} from './extensions/wp-mysql-parser/with-wp-mysql-parser';
import { dirname, joinPaths, toPosixPath } from '@php-wasm/util';
import { platform } from 'os';

Expand All @@ -34,6 +38,7 @@ export interface PHPLoaderOptions {
withIntl?: boolean;
withRedis?: boolean;
withMemcached?: boolean;
withWpMysqlParser?: WpMysqlParserOptions;
}

export type PHPLoaderOptionsForNode = PHPLoaderOptions & {
Expand Down Expand Up @@ -344,6 +349,13 @@ export async function loadNodeRuntime(
emscriptenOptions
);
}
if (options?.withWpMysqlParser) {
emscriptenOptions = await withWpMysqlParser(
modernVersion,
emscriptenOptions,
options.withWpMysqlParser
);
}
}

emscriptenOptions = await withNetworking(emscriptenOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export class BlueprintsV1Handler {
withRedis: this.args.redis,
withMemcached: this.args.memcached,
withXdebug: !!this.args.xdebug,
withWpMysqlParserSo: this.args['wp-mysql-parser-so'],
nativeInternalDirPath,
pathAliases: this.args.pathAliases,
});
Expand Down
4 changes: 4 additions & 0 deletions packages/playground/cli/src/blueprints-v1/worker-thread-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface WorkerBootRequestHandlerOptions {
withRedis?: boolean;
withMemcached?: boolean;
withXdebug?: boolean;
withWpMysqlParserSo?: string;
pathAliases?: PathAlias[];
}

Expand Down Expand Up @@ -251,6 +252,9 @@ function createPhpRuntimeFactory(
withRedis: options.withRedis,
withMemcached: options.withMemcached,
withXdebug: options.withXdebug,
withWpMysqlParser: options.withWpMysqlParserSo
? { soPath: options.withWpMysqlParserSo }
: undefined,
}
);
};
Expand Down
9 changes: 9 additions & 0 deletions packages/playground/cli/src/run-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
type: 'boolean',
default: false,
},
'wp-mysql-parser-so': {
describe:
'Path to a wp_mysql_parser.so side module compiled for the ' +
'target PHP version. Only PHP 8.4 is supported in this build. ' +
'See https://github.com/WordPress/sqlite-database-integration/pull/381',
type: 'string',
normalize: true,
},
'experimental-unsafe-ide-integration': {
describe:
'Enable experimental IDE development tools. This option edits IDE config files ' +
Expand Down Expand Up @@ -890,6 +898,7 @@ export interface RunCLIArgs {
redis?: boolean;
memcached?: boolean;
xdebug?: boolean | XdebugOptions;
'wp-mysql-parser-so'?: string;
experimentalUnsafeIdeIntegration?: string[];
experimentalDevtools?: boolean;
'experimental-blueprints-v2-runner'?: boolean;
Expand Down
Loading