Skip to content
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

Update static Linux build to MozJPEG 4.0. #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
FROM debian:8-slim

RUN apt-get update \
&& apt-get install autoconf libtool nasm libpng-dev automake pkg-config build-essential wget \
-yq --no-install-suggests --no-install-recommends --force-yes

WORKDIR /src
RUN wget --no-check-certificate https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz -O mozjpeg-3.3.1.tar.gz
RUN tar -xzvf mozjpeg-3.3.1.tar.gz
WORKDIR /src/mozjpeg-3.3.1

RUN autoreconf -fiv \
&& ./configure LDFLAGS=-static libpng_LIBS='/usr/lib/x86_64-linux-gnu/libpng12.a -lz' --enable-static --disable-shared \
&& make -j8
FROM docker.io/library/alpine:latest
RUN apk --update --no-cache upgrade
RUN apk add --no-cache \
build-base \
git \
nasm \
cmake \
autoconf automake libtool \
pkgconf \
curl \
libpng-dev libpng-static \
zlib-dev zlib-static
RUN adduser -D builder
WORKDIR /home/builder
USER builder
# Exact time of MozJPEG v4.1.1 commit
ENV SOURCE_DATE_EPOCH 1660525997
COPY /build.sh build.sh
RUN ["/bin/sh", "build.sh"]
29 changes: 29 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
set -eu

mk_threads=$(($(nproc) - 1))
mozjpeg_ver="4.1.1"
make="make -j$mk_threads"

curl -fRLO "https://github.com/mozilla/mozjpeg/archive/refs/tags/v${mozjpeg_ver}.tar.gz"
tar -xzf "v${mozjpeg_ver}.tar.gz"
mv "mozjpeg-${mozjpeg_ver}" mozjpeg
cd mozjpeg

export CFLAGS='-flto -no-pie'
export LDFLAGS='-flto -no-pie -static -static-libgcc'

# This unsets CMAKE_SHARED_LIBRARY_LINK_C_FLAGS inside CMakeLists.txt because it won't
# work from the CLI.
sed -E -i.bk '/set\(LIBJPEG_TURBO_V/i\
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)' CMakeLists.txt

cmake -B build \
-D ENABLE_SHARED=off \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_FIND_LIBRARY_SUFFIXES=.a \
-D CMAKE_LINK_SEARCH_END_STATIC=1 -D CMAKE_LINK_SEARCH_START_STATIC=1

cd build
$make cjpeg-static
strip cjpeg-static
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && ava --timeout=120s",
"build-linux": "docker build --tag imagemin/mozjpeg docker && docker run --rm --volume $(pwd)/vendor/linux:/src/out imagemin/mozjpeg cp cjpeg /src/out"
"build-linux": "docker build --tag imagemin/mozjpeg docker/ && docker create --name mozjpeg_ctr imagemin/mozjpeg && docker cp mozjpeg_ctr:/home/builder/mozjpeg/build/cjpeg-static ./vendor/linux/cjpeg && docker container rm mozjpeg_ctr"
},
"files": [
"index.js",
Expand Down
Binary file modified vendor/linux/cjpeg
Binary file not shown.