WasmEdge for Image Extension

The WasmEdge (formerly SSVM) is a high performance WebAssembly runtime optimized for server side applications. This project provides support for accessing with JPEG library and PNG library.

Motivation

For this WasmEdge Image extension, we prefer to link the libjpeg and libpng statically into the both WasmEdge Image static and shared library. Hence, we compile and release the pre-built static and shared library of libjpeg and libpng on the legacy operating system, and link them into our WasmEdge Image extension library for not only reducing the compilation time, but also saving the library installation.

License

This project is under the License as the same as the libjpeg and libpng projects.

Credits

Getting Started

Prepare the environment

Use our docker image (Recommanded)

Our docker image is based on ubuntu 20.04.

$ docker pull wasmedge/wasmedge

Or setup the environment manually

Please notice that WasmEdge-Image requires cmake>=3.11 and libboost>=1.68.

# Tools and libraries
$ sudo apt install -y \
	software-properties-common \
	cmake \
	libboost-all-dev

# WasmEdge supports both clang++ and g++ compilers
# You can choose one of them for building this project
$ sudo apt install -y gcc g++
$ sudo apt install -y clang

Get WasmEdge-Image Source Code

$ git clone https://github.com/second-state/WasmEdge-image.git
$ cd WasmEdge-image
$ git checkout 0.9.0-rc1

Build WasmEdge-Image

WasmEdge-Image depends on WasmEdge-Core, you have to prepare WasmEdge-Core before you build WasmEdge-Image. We provides two options for setting up the WasmEdge-Core:

Create and Enter the Build Folder

# After pulling our WasmEdge docker image
$ docker run -it --rm \
    -v <path/to/your/WasmEdge-image/source/folder>:/root/WasmEdge-image \
    wasmedge/wasmedge:latest
(docker)$ cd /root/WasmEdge-image
(docker)$ mkdir -p build && cd build

Option 1. Use built-in CMakeLists to get WasmEdge-Core (Recommended)

(docker)$ cmake -DCMAKE_BUILD_TYPE=Release .. && make

Option 2. Use specific version of WasmEdge-Core by giving WASMEDGE_CORE_PATH

(docker)$ cmake -DWASMEDGE_CORE_PATH=<path/to/WasmEdge/source> -DCMAKE_BUILD_TYPE=Release .. && make

The shared library build/lib/libwasmedge-image_c.so is the C API to create wasmedge-image import object. The header build/include/wasmedge/wasmedge-image.h is the header of the shared library. The static library build/lib/libwasmedgeHostModuleWasmEdgeImage.a is for executables linking in CMake.

How to build libjpeg and libpng on the legacy operating system - CentOS 5.11

Download the libjpeg and libpng source

$ mkdir workspace && cd workspace
$ wget https://downloads.sourceforge.net/libpng/libpng-1.6.37.tar.xz
$ tar Jxvf libpng-1.6.37.tar.xz
$ wget http://ijg.org/files/jpegsrc.v8c.tar.gz
$ tar -zxvf jpegsrc.v8c.tar.gz

Pull the manylinux1 docker image and run

$ docker pull wasmedge/wasmedge:manylinux1_x86_64
$ docker run -it --rm -v $(pwd):/root/$(basename $(pwd)) wasmedge/wasmedge:manylinux1_x86_64

Build the libjpeg and the libpng

(docker) $ cd /root/workspace/jpeg-8c
(docker) $ CFLAGS=-fPIC ./configure --enable-shared=off && make
# The JPEG static library will be at `.libs/libjpeg.a`.
(docker) $ cd /root/workspace/libpng-1.6.37
(docker) $ CFLAGS=-fPIC ./configure --enable-shared=off && make
# The PNG static library will be at `.libs/libpng16.a`.