Skip to content

Try bundling xdiff #2174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
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
20 changes: 18 additions & 2 deletions packages/php-wasm/compile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,31 @@ libcurl/jspi/dist/root/lib/lib/libcurl.a: base-image libz libopenssl
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/lib/.libs ./libcurl/jspi/dist/root/lib/lib
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/include/ ./libcurl/jspi/dist/root/lib

libxdiff_asyncify: libxdiff/asyncify/dist/root/lib/lib/libxdiff.a
libxdiff/asyncify/dist/root/lib/lib/libxdiff.a: base-image
mkdir -p ./libxdiff/asyncify/dist/root/lib
docker build -f ./libxdiff/Dockerfile -t playground-php-wasm:libxdiff .
docker cp $$(docker create playground-php-wasm:libxdiff):/root/lib/lib ./libxdiff/asyncify/dist/root/lib
docker cp $$(docker create playground-php-wasm:libxdiff):/root/lib/include ./libxdiff/asyncify/dist/root/lib

libxdiff_jspi: libxdiff/jspi/dist/root/lib/lib/libxdiff.a
libxdiff/jspi/dist/root/lib/lib/libxdiff.a: base-image
mkdir -p ./libxdiff/jspi/dist/root/lib
docker build -f ./libxdiff/Dockerfile -t playground-php-wasm:libxdiff . --build-arg JSPI=1
docker cp $$(docker create playground-php-wasm:libxdiff):/root/lib/lib ./libxdiff/jspi/dist/root/lib
docker cp $$(docker create playground-php-wasm:libxdiff):/root/lib/include ./libxdiff/jspi/dist/root/lib

all: all_jspi all_asyncify
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi libxdiff_jspi
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify libxdiff_asyncify

clean:
rm -rf ./libz/jspi/dist
rm -rf ./libz/asyncify/dist
rm -rf ./libzip/jspi/dist
rm -rf ./libzip/asyncify/dist
rm -rf ./libxdiff/jspi/dist
rm -rf ./libxdiff/asyncify/dist
rm -rf ./libpng16/jspi/dist
rm -rf ./libpng16/asyncify/dist
rm -rf ./libjpeg/jspi/dist
Expand Down
10 changes: 5 additions & 5 deletions packages/php-wasm/compile/base-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Originally forked from https://github.com/seanmorris/php-wasm
# ubuntu:lunar supports amd64 and arm64 (Apple Silicon) while
# ubuntu:noble supports amd64 and arm64 (Apple Silicon) while
# emscripten/emsdk:3.1.24 supports amd64 only.
FROM ubuntu:lunar as emscripten
FROM ubuntu:noble as emscripten

SHELL ["/bin/bash", "-c"]

Expand Down Expand Up @@ -36,16 +36,16 @@ RUN set -euxo pipefail;\
# Install Emscripten from the repository. We'd use the official
# Docker image, but there is no arm64 image available which makes
# the build take forever on Apple Silicon.
#
#
# ---- IMPORTANT ----
# When upgrading the Emscripten version, you will need to rebuild all the WebAssembly libraries
# shipped in this repository before you can rebuild PHP itself. The entire build, including every
# linked lib, must be produced by the same Emscripten version – otherwise you'll run into undefined
# behaviors and indeterministic failures like we did in these two PRs:
#
#
# * https://github.com/WordPress/wordpress-playground/pull/1471
# * https://github.com/WordPress/wordpress-playground/pull/1339
#
#
# WASM libraries to rebuild live here:
# https://github.com/WordPress/wordpress-playground/tree/67d916b5eccfe78e26e9c953598cc1a81f316931/packages/php-wasm/compile
RUN ln -s /usr/bin/python3 /usr/bin/python
Expand Down
24 changes: 24 additions & 0 deletions packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const argParser = yargs(process.argv.slice(2))
choices: ['yes', 'no'],
description: 'Build with fileinfo support',
},
WITH_XDIFF: {
type: 'string',
choices: ['yes', 'no'],
description: 'Build with xdiff support',
},
WITH_LIBXML: {
type: 'string',
choices: ['yes', 'no'],
Expand Down Expand Up @@ -141,6 +146,7 @@ const platformDefaults = {
WITH_MBREGEX: 'yes',
WITH_OPENSSL: 'yes',
WITH_WS_NETWORKING_PROXY: 'yes',
WITH_XDIFF: 'no',
},
web: {},
node: {
Expand Down Expand Up @@ -179,6 +185,22 @@ const sourceDir = path.dirname(new URL(import.meta.url).pathname);
// Build the base image
await asyncSpawn('make', ['base-image'], { cwd: sourceDir, stdio: 'inherit' });

// Build libxdiff if needed
if (getArg('WITH_XDIFF') === 'WITH_XDIFF=yes') {
console.log('Building libxdiff...');
if (getArg('WITH_JSPI') === 'WITH_JSPI=yes') {
await asyncSpawn('make', ['libxdiff_jspi'], {
cwd: sourceDir,
stdio: 'inherit',
});
} else {
await asyncSpawn('make', ['libxdiff_asyncify'], {
cwd: sourceDir,
stdio: 'inherit',
});
}
}

await asyncSpawn(
'docker',
[
Expand Down Expand Up @@ -221,6 +243,8 @@ await asyncSpawn(
'--build-arg',
getArg('WITH_MYSQL'),
'--build-arg',
getArg('WITH_XDIFF'),
'--build-arg',
getArg('WITH_WS_NETWORKING_PROXY'),
'--build-arg',
`EMSCRIPTEN_ENVIRONMENT=${platform === 'node' ? 'node' : 'web'}`,
Expand Down
30 changes: 30 additions & 0 deletions packages/php-wasm/compile/libxdiff/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM playground-php-wasm:base

ARG JSPI="0"

# Download and extract libxdiff
RUN wget http://www.xmailserver.org/libxdiff-0.23.tar.gz && \
tar -xzf libxdiff-0.23.tar.gz

# Configure and build with Emscripten
RUN cd libxdiff-0.23 && \
source /root/emsdk/emsdk_env.sh && \
# Update config.guess and config.sub for better platform detection
wget -O config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' && \
wget -O config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' && \
chmod +x config.guess config.sub && \
if [ "$JSPI" = "1" ]; then \
emconfigure ./configure --prefix=/root/lib --build=$(./config.guess) --host=wasm32-unknown-emscripten CFLAGS="-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"; \
else \
emconfigure ./configure --prefix=/root/lib --build=$(./config.guess) --host=wasm32-unknown-emscripten; \
fi && \
emmake make && \
emmake make install && \
# Ensure the library is in the correct location
mkdir -p /root/lib/lib && \
# Verify the library was built and installed
test -f /root/lib/lib/libxdiff.a || { echo "ERROR: libxdiff.a not found in /root/lib/lib/"; exit 1; } && \
# Copy to final location and verify
cp -f /root/lib/lib/libxdiff.a /root/lib/lib/ && \
ls -la /root/lib/lib/libxdiff.a || { echo "ERROR: Failed to copy libxdiff.a"; exit 1; } && \
echo "Successfully built and installed libxdiff.a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* LibXDiff by Davide Libenzi ( File Differential Library )
* Copyright (C) 2003 Davide Libenzi
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Davide Libenzi <davidel@xmailserver.org>
*
*/

#if !defined(XDIFF_H)
#define XDIFF_H

#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */


#define XDF_NEED_MINIMAL (1 << 1)

#define XDL_PATCH_NORMAL '-'
#define XDL_PATCH_REVERSE '+'
#define XDL_PATCH_MODEMASK ((1 << 8) - 1)
#define XDL_PATCH_IGNOREBSPACE (1 << 8)

#define XDL_MMB_READONLY (1 << 0)

#define XDL_MMF_ATOMIC (1 << 0)

#define XDL_BDOP_INS 1
#define XDL_BDOP_CPY 2
#define XDL_BDOP_INSB 3



typedef struct s_memallocator {
void *priv;
void *(*malloc)(void *, unsigned int);
void (*free)(void *, void *);
void *(*realloc)(void *, void *, unsigned int);
} memallocator_t;

typedef struct s_mmblock {
struct s_mmblock *next;
unsigned long flags;
long size, bsize;
char *ptr;
} mmblock_t;

typedef struct s_mmfile {
unsigned long flags;
mmblock_t *head, *tail;
long bsize, fsize, rpos;
mmblock_t *rcur, *wcur;
} mmfile_t;

typedef struct s_mmbuffer {
char *ptr;
long size;
} mmbuffer_t;

typedef struct s_xpparam {
unsigned long flags;
} xpparam_t;

typedef struct s_xdemitcb {
void *priv;
int (*outf)(void *, mmbuffer_t *, int);
} xdemitcb_t;

typedef struct s_xdemitconf {
long ctxlen;
} xdemitconf_t;

typedef struct s_bdiffparam {
long bsize;
} bdiffparam_t;


int xdl_set_allocator(memallocator_t const *malt);
void *xdl_malloc(unsigned int size);
void xdl_free(void *ptr);
void *xdl_realloc(void *ptr, unsigned int size);

int xdl_init_mmfile(mmfile_t *mmf, long bsize, unsigned long flags);
void xdl_free_mmfile(mmfile_t *mmf);
int xdl_mmfile_iscompact(mmfile_t *mmf);
int xdl_seek_mmfile(mmfile_t *mmf, long off);
long xdl_read_mmfile(mmfile_t *mmf, void *data, long size);
long xdl_write_mmfile(mmfile_t *mmf, void const *data, long size);
long xdl_writem_mmfile(mmfile_t *mmf, mmbuffer_t *mb, int nbuf);
void *xdl_mmfile_writeallocate(mmfile_t *mmf, long size);
long xdl_mmfile_ptradd(mmfile_t *mmf, char *ptr, long size, unsigned long flags);
long xdl_copy_mmfile(mmfile_t *mmf, long size, xdemitcb_t *ecb);
void *xdl_mmfile_first(mmfile_t *mmf, long *size);
void *xdl_mmfile_next(mmfile_t *mmf, long *size);
long xdl_mmfile_size(mmfile_t *mmf);
int xdl_mmfile_cmp(mmfile_t *mmf1, mmfile_t *mmf2);
int xdl_mmfile_compact(mmfile_t *mmfo, mmfile_t *mmfc, long bsize, unsigned long flags);

int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
xdemitconf_t const *xecfg, xdemitcb_t *ecb);
int xdl_patch(mmfile_t *mf, mmfile_t *mfp, int mode, xdemitcb_t *ecb,
xdemitcb_t *rjecb);

int xdl_merge3(mmfile_t *mmfo, mmfile_t *mmf1, mmfile_t *mmf2, xdemitcb_t *ecb,
xdemitcb_t *rjecb);

int xdl_bdiff_mb(mmbuffer_t *mmb1, mmbuffer_t *mmb2, bdiffparam_t const *bdp, xdemitcb_t *ecb);
int xdl_bdiff(mmfile_t *mmf1, mmfile_t *mmf2, bdiffparam_t const *bdp, xdemitcb_t *ecb);
int xdl_rabdiff_mb(mmbuffer_t *mmb1, mmbuffer_t *mmb2, xdemitcb_t *ecb);
int xdl_rabdiff(mmfile_t *mmf1, mmfile_t *mmf2, xdemitcb_t *ecb);
long xdl_bdiff_tgsize(mmfile_t *mmfp);
int xdl_bpatch(mmfile_t *mmf, mmfile_t *mmfp, xdemitcb_t *ecb);
int xdl_bpatch_multi(mmbuffer_t *base, mmbuffer_t *mbpch, int n, xdemitcb_t *ecb);


#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */

#endif /* #if !defined(XDIFF_H) */

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# libxdiff.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42) Debian: 224 $
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname=''

# Names of this library.
library_names=''

# The name of the static archive.
old_library='libxdiff.a'

# Libraries that this one depends upon.
dependency_libs=''

# Version information for libxdiff.
current=0
age=0
revision=0

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/root/install/lib'
Loading
Loading