Skip to content
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
10 changes: 9 additions & 1 deletion packages/php-wasm/compile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ libwebp/jspi/dist/root/lib/lib/libwebp.a: base-image libz_jspi
docker cp $$(docker create playground-php-wasm:libpng):/root/lib/lib ./libwebp/jspi/dist/root/lib
docker cp $$(docker create playground-php-wasm:libpng):/root/lib/include ./libwebp/jspi/dist/root/lib

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


libxml2_asyncify: libxml2/asyncify/dist/root/lib/lib/libxml2.a
libxml2/asyncify/dist/root/lib/lib/libxml2.a: base-image libz_asyncify
mkdir -p ./libxml2/asyncify/dist/root/lib
Expand Down Expand Up @@ -273,7 +281,7 @@ libintl/jspi/dist/root/lib/lib/libintl.a: base-image
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/data/. ./libintl/

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 libintl_jspi
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 libintl_jspi libimagick_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 libintl_asyncify

clean:
Expand Down
87 changes: 87 additions & 0 deletions packages/php-wasm/compile/libimagick/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Build ImageMagick libraries for WebAssembly (Emscripten)
# - Compiles ImageMagick from official source using emscripten/emsdk
# - Produces static libs (MagickCore, MagickWand) suitable for linking
# - Copies headers and a tiny link-test into /dist

ARG EMSDK_VERSION=3.1.64
ARG IMAGEMAGICK_VERSION=7.1.1-34

FROM --platform=linux/amd64 emscripten/emsdk:${EMSDK_VERSION} AS build

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

ARG IMAGEMAGICK_VERSION
ARG JSPI

RUN mkdir -p /root/lib/include /root/lib/lib
COPY ./libz/ /root/libz
COPY ./libpng16/ /root/libpng16
COPY ./libjpeg/ /root/libjpeg

RUN if [ "$JSPI" = "1" ]; then \
cp -r /root/*/jspi/dist/root/lib/* /root/lib; \
else \
cp -r /root/*/asyncify/dist/root/lib/* /root/lib; \
fi

# Install build helpers that aren’t preinstalled in the base image
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates curl xz-utils autoconf automake libtool pkg-config \
make cmake ninja-build git file python3 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src

# Fetch ImageMagick source from Git (avoid release tarball 404s)
RUN git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick \
&& cd ImageMagick \
&& (git checkout "refs/tags/${IMAGEMAGICK_VERSION}" -b build-ref || git checkout "${IMAGEMAGICK_VERSION}")

WORKDIR /src/ImageMagick

# Configure for Emscripten
# Notes:
# - Disable features requiring OS/threads or delegates we won’t provide here.
# - Build static only; these .a archives are LLVM bitcode built by emcc.
# - Use emconfigure/emmake to cross-compile tests correctly.
ENV EMCC_CFLAGS="-O3 -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_LIBJPEG=1 -s ALLOW_MEMORY_GROWTH=1"
ENV EMCC_LDFLAGS="-O3 -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_LIBJPEG=1 -s ALLOW_MEMORY_GROWTH=1"

RUN \
emconfigure ./configure \
--build i386-pc-linux-gnu \
--host=wasm32-unknown-emscripten \
--prefix=/root/lib/ \
--disable-shared \
--enable-static \
--disable-hdri \
--with-quantum-depth=16 \
--disable-openmp \
--without-utilities \
--without-perl \
--without-x \
--with-modules=no \
--with-threads=no \
--enable-delegate-build=no \
--with-png=/root/lib \
--with-jpeg=/root/lib \
--with-zlib=/root/lib \
--with-tiff=no \
--with-xml=no \
--with-lcms=no \
--with-webp=no \
--with-openjp2=no \
--with-heic=no \
--with-freetype=no \
CFLAGS="${EMCC_CFLAGS}" CXXFLAGS="${EMCC_CFLAGS}" \
LDFLAGS="${EMCC_LDFLAGS}" LIBS=""

# Build and install into a staging prefix
RUN emmake make -j"$(nproc)" \
&& emmake make install

# Prepare dist directory with headers, libs, and a tiny link test
WORKDIR /work
RUN mkdir -p /dist/lib /dist/include /dist/examples

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000
//
// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// Simplified includes for Magick++.
// Inclusion of this header is sufficient to use all Magick++ APIs.
//
#ifndef MagickPlusPlus_Header
#include <Magick++/Include.h>
#include <Magick++/Functions.h>
#include <Magick++/Image.h>
#include <Magick++/Pixels.h>
#include <Magick++/ResourceLimits.h>
#include <Magick++/STL.h>

// Don't leak our definition of the 'restrict' keyword. 'restrict' is a valid
// identifier in C++, and leaking it could cause extraneous build failures.
#ifdef restrict
#undef restrict
#endif
#define MagickPlusPlus_Header
#endif // MagickPlusPlus_Header
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002
//
// Copyright @ 2015 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// Reference counted container class for Binary Large Objects (BLOBs)
//

#if !defined(Magick_BlobRef_header)
#define Magick_BlobRef_header

#include "Magick++/Include.h"
#include <string>

namespace Magick
{
// Forward decl
class BlobRef;

class MagickPPExport Blob
{
public:

enum Allocator
{
MallocAllocator,
NewAllocator
};

// Default constructor
Blob(void);

// Construct object with data, making a copy of the supplied data.
Blob(const void* data_,const size_t length_);

// Copy constructor (reference counted)
Blob(const Blob& blob_);

// Destructor (reference counted)
virtual ~Blob();

// Assignment operator (reference counted)
Blob& operator=(const Blob& blob_);

// Update object contents from Base64-encoded string representation.
void base64(const std::string base64_);
// Return Base64-encoded string representation.
std::string base64(void) const;

// Obtain pointer to data. The user should never try to modify or
// free this data since the Blob class manages its own data. The
// user must be finished with the data before allowing the Blob to
// be destroyed since the pointer is invalid once the Blob is
// destroyed.
const void* data(void) const;

// Obtain data length.
size_t length(void) const;

// Update object contents, making a copy of the supplied data.
// Any existing data in the object is deallocated.
void update(const void* data_,const size_t length_);

// Update object contents, using supplied pointer directly (no
// copy). Any existing data in the object is deallocated. The user
// must ensure that the pointer supplied is not deleted or
// otherwise modified after it has been supplied to this method.
// Specify allocator_ as "MallocAllocator" if memory is allocated
// via the C language malloc() function, or "NewAllocator" if
// memory is allocated via C++ 'new'.
void updateNoCopy(void* data_,const size_t length_,
const Allocator allocator_=NewAllocator);

private:
BlobRef *_blobRef;
};

} // namespace Magick

#endif // Magick_BlobRef_header
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 2001, 2002
//
// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// CoderInfo Definition
//
// Container for image format support information.
//

#if !defined (Magick_CoderInfo_header)
#define Magick_CoderInfo_header 1

#include "Magick++/Include.h"
#include <string>

namespace Magick
{
class MagickPPExport CoderInfo
{
public:

enum MatchType {
AnyMatch, // match any coder
TrueMatch, // match coder if true
FalseMatch // match coder if false
};

// Default constructor
CoderInfo(void);

// Copy constructor
CoderInfo(const CoderInfo &coder_);

// Construct with coder name
CoderInfo(const std::string &name_);

// Destructor
~CoderInfo(void);

// Assignment operator
CoderInfo& operator=(const CoderInfo &coder_);

// Format can read multi-threaded
bool canReadMultithreaded(void) const;

// Format can write multi-threaded
bool canWriteMultithreaded(void) const;

// Format description
std::string description(void) const;

// Format supports multiple frames
bool isMultiFrame(void) const;

// Format is readable
bool isReadable(void) const;

// Format is writeable
bool isWritable(void) const;

// Format mime type
std::string mimeType(void) const;

// Name of the module
std::string module(void) const;

// Format name
std::string name(void) const;

// Unregisters this coder
bool unregister(void) const;

private:
bool _decoderThreadSupport;
std::string _description;
bool _encoderThreadSupport;
bool _isMultiFrame;
bool _isReadable;
bool _isWritable;
std::string _mimeType;
std::string _module;
std::string _name;
};

} // namespace Magick

#endif // Magick_CoderInfo_header
Loading
Loading