|
| 1 | +from faasmtools.env import ( |
| 2 | + THIRD_PARTY_DIR, |
| 3 | +) |
| 4 | +from faasmtools.build import ( |
| 5 | + WASM_AR, |
| 6 | + WASM_CC, |
| 7 | + WASM_CFLAGS, |
| 8 | + WASM_CXX, |
| 9 | + WASM_EXE_LDFLAGS, |
| 10 | + WASM_HOST, |
| 11 | + WASM_LD, |
| 12 | + WASM_NM, |
| 13 | + WASM_RANLIB, |
| 14 | + WASM_SYSROOT, |
| 15 | +) |
| 16 | +from faasmtools.compile_util import wasm_copy_upload |
| 17 | +from invoke import task |
| 18 | +from os.path import join |
| 19 | +from subprocess import run |
| 20 | + |
| 21 | + |
| 22 | +@task(default=True) |
| 23 | +def imagemagick(ctx, clean=False): |
| 24 | + """ |
| 25 | + Compile and install ImageMagick |
| 26 | + """ |
| 27 | + imagemagick_dir = join(THIRD_PARTY_DIR, "ImageMagick") |
| 28 | + |
| 29 | + if clean: |
| 30 | + run("make clean", shell=True, cwd=imagemagick_dir, check=True) |
| 31 | + |
| 32 | + # List of flags inspired from the github project: |
| 33 | + # https://github.com/KnicKnic/WASM-ImageMagick |
| 34 | + # For all the configure options, see: |
| 35 | + # https://github.com/ImageMagick/ImageMagick/blob/main/Install-unix.txt |
| 36 | + configure_cmd = [ |
| 37 | + "./configure", |
| 38 | + "CC={}".format(WASM_CC), |
| 39 | + "CXX={}".format(WASM_CXX), |
| 40 | + "CFLAGS='{}'".format(" ".join(WASM_CFLAGS)), |
| 41 | + "CXXFLAGS='{}'".format(" ".join(WASM_CFLAGS)), |
| 42 | + "LD={}".format(WASM_LD), |
| 43 | + "LDFLAGS='{}'".format(" ".join(WASM_EXE_LDFLAGS)), |
| 44 | + "CXXLDFLAGS='{}'".format(" ".join(WASM_EXE_LDFLAGS)), |
| 45 | + "AR={}".format(WASM_AR), |
| 46 | + "RANLIB={}".format(WASM_RANLIB), |
| 47 | + "NM={}".format(WASM_NM), |
| 48 | + "PKG_CONFIG_PATH={}".format(join(THIRD_PARTY_DIR, "libpng")), |
| 49 | + "--prefix={}".format(WASM_SYSROOT), |
| 50 | + "--disable-largefile", |
| 51 | + "--disable-openmp", |
| 52 | + "--disable-shared", |
| 53 | + "--host={}".format(WASM_HOST), |
| 54 | + "--with-png=yes", |
| 55 | + "--enable-delegate-build", |
| 56 | + "--without-bzlib", |
| 57 | + "--without-dps", |
| 58 | + "--without-djvu", |
| 59 | + "--without-fftw", |
| 60 | + "--without-flif", |
| 61 | + "--without-fpx", |
| 62 | + "--without-fontconfig", |
| 63 | + "--without-freetype", |
| 64 | + "--without-gslib", |
| 65 | + "--without-gvc", |
| 66 | + "--without-heic", |
| 67 | + "--without-jbig", |
| 68 | + "--without-lcms", |
| 69 | + "--without-lqr", |
| 70 | + "--without-magick-plus-plus", |
| 71 | + "--without-openexr", |
| 72 | + "--without-openjp2", |
| 73 | + "--without-pango", |
| 74 | + "--without-perl", |
| 75 | + "--without-raqm", |
| 76 | + "--without-raw", |
| 77 | + "--without-rsvg", |
| 78 | + "--without-threads", |
| 79 | + "--without-webp", |
| 80 | + "--without-wmf", |
| 81 | + "--without-x", |
| 82 | + "--without-xml", |
| 83 | + ] |
| 84 | + |
| 85 | + configure_cmd = " ".join(configure_cmd) |
| 86 | + run(configure_cmd, shell=True, cwd=imagemagick_dir, check=True) |
| 87 | + |
| 88 | + run("make -j", shell=True, cwd=imagemagick_dir, check=True) |
| 89 | + |
| 90 | + # Instead of installing ImageMagick, we copy the self-contained binary |
| 91 | + # (magick) to /usr/local/faasm/wasm/imagemagick/main/function.wasm |
| 92 | + wasm_copy_upload( |
| 93 | + "imagemagick", "main", join(imagemagick_dir, "utilities", "magick") |
| 94 | + ) |
0 commit comments