Have unified compiler flags in Dockerfile

This commit is contained in:
Ilya Fedin 2022-10-05 14:27:34 +04:00 committed by John Preston
parent 435e4f2783
commit 0c514c4b0a
1 changed files with 60 additions and 53 deletions

View File

@ -7,13 +7,12 @@
{%- set OPENSSL_PREFIX = "/usr/local/desktop-app/openssl-1.1.1" -%}
{%- set CMAKE_VER = "3.21.3" -%}
{%- set CMAKE_FILE = "cmake-" ~ CMAKE_VER ~ "-Linux-x86_64.sh" -%}
{%- set HFLAGS_DEBUG = "-fstack-protector-all -fstack-clash-protection -fPIC" -%}
{%- set HFLAGS = HFLAGS_DEBUG ~ " -D_FORTIFY_SOURCE=2" -%}
{%- set CFLAGS_DEBUG = "-g -pipe -fPIC -fstack-protector-all -fstack-clash-protection -D_GLIBCXX_ASSERTIONS" -%}
{%- set LibrariesPath = "/usr/src/Libraries" -%}
# syntax=docker/dockerfile:1
FROM centos:7 AS builder
FROM centos:7 AS builder-base
ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
@ -29,8 +28,7 @@ RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.n
llvm-toolset-7.0-llvm-devel \
&& yum clean all
RUN python3 -m pip install meson
RUN python3 -m pip install ninja
RUN python3 -m pip install meson ninja
# Fix a bug with argument naming in CentOS 7 glibc
RUN sed -i 's/char \*__block/char */' /usr/include/unistd.h
@ -45,6 +43,13 @@ RUN mkdir /opt/cmake \
&& ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake \
&& rm {{ CMAKE_FILE }}
FROM builder-base AS builder
ENV AR gcc-ar
ENV RANLIB gcc-ranlib
ENV NM gcc-nm
ENV CFLAGS {% if DEBUG %}-g{% endif %} -Ofast {% if DEBUG %}-flto -ffat-lto-objects{% endif %} -pipe -fPIC -fstack-protector-all -fstack-clash-protection -DNDEBUG -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS
ENV CXXFLAGS $CFLAGS
FROM builder AS patches
RUN git clone {{ GIT }}/desktop-app/patches.git \
&& cd patches \
@ -75,7 +80,7 @@ RUN git clone -b v3.4.2 --depth=1 {{ GIT }}/libffi/libffi.git \
FROM builder AS zlib
RUN git clone -b v1.2.11 --depth=1 {{ GIT }}/madler/zlib.git \
&& cd zlib \
&& CFLAGS="-O3 {{ HFLAGS }}" ./configure --static \
&& ./configure --static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/zlib-cache" install \
&& cd .. \
@ -84,7 +89,7 @@ RUN git clone -b v1.2.11 --depth=1 {{ GIT }}/madler/zlib.git \
FROM builder AS xz
RUN git clone -b v5.2.5 https://git.tukaani.org/xz.git \
&& cd xz \
&& CFLAGS="{{ HFLAGS }}" cmake -GNinja -B build . -DCMAKE_BUILD_TYPE=Release \
&& cmake -GNinja -B build . -DCMAKE_BUILD_TYPE=None \
&& cmake --build build --parallel \
&& DESTDIR="{{ LibrariesPath }}/xz-cache" cmake --install build \
&& cd .. \
@ -94,8 +99,8 @@ FROM patches AS libproxy
RUN git clone -b 0.4.17 --depth=1 {{ GIT }}/libproxy/libproxy.git \
&& cd libproxy \
&& git apply ../patches/libproxy.patch \
&& CFLAGS="{{ HFLAGS }}" CXXFLAGS="{{ HFLAGS }}" cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=None \
-DWITH_DBUS=OFF \
-DWITH_NM=OFF \
-DWITH_NMold=OFF \
@ -108,7 +113,7 @@ FROM builder AS lcms2
RUN git clone -b lcms2.13.1 --depth=1 {{ GIT }}/mm2/Little-CMS.git \
&& cd Little-CMS \
&& meson build \
--buildtype=release \
--buildtype=plain \
--default-library=both \
&& meson compile -C build \
&& DESTDIR="{{ LibrariesPath }}/lcms2-cache" meson install -C build \
@ -119,7 +124,7 @@ FROM builder AS brotli
RUN git clone -b v1.0.9 --depth=1 {{ GIT }}/google/brotli.git \
&& cd brotli \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBROTLI_DISABLE_TESTS=ON \
&& cmake --build build --parallel \
&& DESTDIR="{{ LibrariesPath }}/brotli-cache" cmake --install build \
@ -130,7 +135,7 @@ FROM builder AS highway
RUN git clone -b 1.0.1 --depth=1 {{ GIT }}/google/highway.git \
&& cd highway \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBUILD_TESTING=OFF \
-DHWY_ENABLE_CONTRIB=OFF \
-DHWY_ENABLE_EXAMPLES=OFF \
@ -142,8 +147,8 @@ RUN git clone -b 1.0.1 --depth=1 {{ GIT }}/google/highway.git \
FROM builder AS mozjpeg
RUN git clone -b v4.0.3 --depth=1 {{ GIT }}/mozilla/mozjpeg.git \
&& cd mozjpeg \
&& CFLAGS="{{ HFLAGS }}" cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=None \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DWITH_JPEG8=ON \
-DPNG_SUPPORTED=OFF \
@ -156,7 +161,7 @@ FROM builder AS opus
RUN git clone -b v1.3.1 --depth=1 {{ GIT }}/xiph/opus.git \
&& cd opus \
&& ./autogen.sh \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./configure \
&& ./configure --enable-float-approx \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/opus-cache" install \
&& cd .. \
@ -168,7 +173,7 @@ COPY --link --from=nasm {{ LibrariesPath }}/nasm-cache /
RUN git clone -b 1.0.0 --depth=1 {{ GIT }}/videolan/dav1d.git \
&& cd dav1d \
&& meson build \
--buildtype=release \
--buildtype=plain \
--default-library=both \
-Denable_tools=false \
-Denable_tests=false \
@ -181,7 +186,7 @@ FROM builder AS libde265
RUN git clone -b v1.0.8 --depth=1 {{ GIT }}/strukturag/libde265.git \
&& cd libde265 \
&& cmake -GNinja . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBUILD_SHARED_LIBS=OFF \
-DENABLE_SDL=OFF \
&& cmake --build . --parallel \
@ -192,7 +197,7 @@ RUN git clone -b v1.0.8 --depth=1 {{ GIT }}/strukturag/libde265.git \
FROM builder AS libvpx
RUN git clone -b v1.11.0 --depth=1 {{ GIT }}/webmproject/libvpx.git \
&& cd libvpx \
&& ./configure \
&& CFLAGS="$CFLAGS -fno-lto" CXXFLAGS="$CXXFLAGS -fno-lto" ./configure \
--disable-examples \
--disable-unit-tests \
--disable-tools \
@ -211,7 +216,7 @@ COPY --link --from=dav1d {{ LibrariesPath }}/dav1d-cache /
RUN git clone -b v0.10.1 --depth=1 {{ GIT }}/AOMediaCodec/libavif.git \
&& cd libavif \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBUILD_SHARED_LIBS=OFF \
-DAVIF_CODEC_DAV1D=ON \
&& cmake --build build --parallel \
@ -225,7 +230,7 @@ COPY --link --from=libde265 {{ LibrariesPath }}/libde265-cache /
RUN git clone -b v1.13.0 --depth=1 {{ GIT }}/strukturag/libheif.git \
&& cd libheif \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_X265=OFF \
-DWITH_AOM=OFF \
@ -245,7 +250,7 @@ COPY --link --from=highway {{ LibrariesPath }}/highway-cache /
RUN git clone -b v0.7.0 --depth=1 {{ GIT }}/libjxl/libjxl.git \
&& cd libjxl \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=None \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
-DJPEGXL_ENABLE_DEVTOOLS=OFF \
@ -266,7 +271,10 @@ RUN git clone -b v0.7.0 --depth=1 {{ GIT }}/libjxl/libjxl.git \
FROM builder AS rnnoise
RUN git clone -b master --depth=1 {{ GIT }}/desktop-app/rnnoise \
&& cd rnnoise \
&& CFLAGS="{{ HFLAGS }}" cmake -GNinja -B build . -DCMAKE_BUILD_TYPE=Release \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=None \
-DCMAKE_C_FLAGS="$CFLAGS -DFLOAT_APPROX" \
-DCMAKE_CXX_FLAGS="$CXXFLAGS -DFLOAT_APPROX" \
&& cmake --build build --parallel \
&& mkdir -p "{{ LibrariesPath }}/rnnoise-cache/usr/local/include" \
&& cp "include/rnnoise.h" "{{ LibrariesPath }}/rnnoise-cache/usr/local/include/" \
@ -289,7 +297,7 @@ COPY --link --from=xcb-proto {{ LibrariesPath }}/xcb-proto-cache /
RUN git clone -b libxcb-1.14 --depth=1 {{ GIT_FREEDESKTOP }}/libxcb.git \
&& cd libxcb \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/xcb-cache" install \
&& cd .. \
@ -318,7 +326,7 @@ COPY --link --from=xcb-util {{ LibrariesPath }}/xcb-util-cache /
RUN git clone -b 0.4.0 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-image.git \
&& cd libxcb-image \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/xcb-image-cache" install \
&& cd .. \
@ -327,7 +335,7 @@ RUN git clone -b 0.4.0 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-image.
FROM builder AS xcb-keysyms
RUN git clone -b 0.4.0 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-keysyms.git \
&& cd libxcb-keysyms \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/xcb-keysyms-cache" install \
&& cd .. \
@ -336,7 +344,7 @@ RUN git clone -b 0.4.0 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-keysym
FROM builder AS xcb-render-util
RUN git clone -b 0.3.9 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-render-util.git \
&& cd libxcb-render-util \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/xcb-render-util-cache" install \
&& cd .. \
@ -345,7 +353,7 @@ RUN git clone -b 0.3.9 --depth=1 --recursive {{ GIT_FREEDESKTOP }}/libxcb-render
FROM builder AS libXext
RUN git clone -b libXext-1.3.4 --depth=1 {{ GIT_FREEDESKTOP }}/libxext.git \
&& cd libxext \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXext-cache" install \
&& cd .. \
@ -354,7 +362,7 @@ RUN git clone -b libXext-1.3.4 --depth=1 {{ GIT_FREEDESKTOP }}/libxext.git \
FROM builder AS libXtst
RUN git clone -b libXtst-1.2.3 --depth=1 {{ GIT_FREEDESKTOP }}/libxtst.git \
&& cd libxtst \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXtst-cache" install \
&& cd .. \
@ -363,7 +371,7 @@ RUN git clone -b libXtst-1.2.3 --depth=1 {{ GIT_FREEDESKTOP }}/libxtst.git \
FROM builder AS libXfixes
RUN git clone -b libXfixes-5.0.3 --depth=1 {{ GIT_FREEDESKTOP }}/libxfixes.git \
&& cd libxfixes \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXfixes-cache" install \
&& cd .. \
@ -372,7 +380,7 @@ RUN git clone -b libXfixes-5.0.3 --depth=1 {{ GIT_FREEDESKTOP }}/libxfixes.git \
FROM builder AS libXrandr
RUN git clone -b libXrandr-1.5.2 --depth=1 {{ GIT_FREEDESKTOP }}/libxrandr.git \
&& cd libxrandr \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXrandr-cache" install \
&& cd .. \
@ -381,7 +389,7 @@ RUN git clone -b libXrandr-1.5.2 --depth=1 {{ GIT_FREEDESKTOP }}/libxrandr.git \
FROM builder AS libXrender
RUN git clone -b libXrender-0.9.10 --depth=1 {{ GIT_FREEDESKTOP }}/libxrender.git \
&& cd libxrender \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXrender-cache" install \
&& cd .. \
@ -390,7 +398,7 @@ RUN git clone -b libXrender-0.9.10 --depth=1 {{ GIT_FREEDESKTOP }}/libxrender.gi
FROM builder AS libXdamage
RUN git clone -b libXdamage-1.1.5 --depth=1 {{ GIT_FREEDESKTOP }}/libxdamage.git \
&& cd libxdamage \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXdamage-cache" install \
&& cd .. \
@ -399,7 +407,7 @@ RUN git clone -b libXdamage-1.1.5 --depth=1 {{ GIT_FREEDESKTOP }}/libxdamage.git
FROM builder AS libXcomposite
RUN git clone -b libXcomposite-0.4.5 --depth=1 {{ GIT_FREEDESKTOP }}/libxcomposite.git \
&& cd libxcomposite \
&& CFLAGS="-g -O2 {{ HFLAGS }}" ./autogen.sh --enable-static \
&& ./autogen.sh --enable-static \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/libXcomposite-cache" install \
&& cd .. \
@ -411,7 +419,7 @@ COPY --link --from=libffi {{ LibrariesPath }}/libffi-cache /
RUN git clone -b 1.21.0 --depth=1 {{ GIT_FREEDESKTOP }}/wayland.git \
&& cd wayland \
&& meson build \
--buildtype=release \
--buildtype=plain \
--default-library=both \
-Dtests=false \
-Ddocumentation=false \
@ -438,9 +446,11 @@ RUN git init ffmpeg \
&& git fetch --depth=1 origin cc33e73618a981de7fd96385ecb34719de031f16 \
&& git reset --hard FETCH_HEAD \
&& ./configure \
--extra-cflags="-DCONFIG_SAFE_BITSTREAM_READER=1 {{ HFLAGS }}" \
--extra-cxxflags="-DCONFIG_SAFE_BITSTREAM_READER=1 {{ HFLAGS }}" \
--extra-cflags="-DCONFIG_SAFE_BITSTREAM_READER=1" \
--extra-cxxflags="-DCONFIG_SAFE_BITSTREAM_READER=1" \
--disable-debug \
--disable-optimizations \
--disable-inline-asm \
--disable-programs \
--disable-doc \
--disable-network \
@ -557,7 +567,7 @@ FROM builder AS pipewire
RUN git clone -b 0.3.25 --depth=1 {{ GIT }}/PipeWire/pipewire.git \
&& cd pipewire \
&& meson build \
--buildtype=release \
--buildtype=plain \
-Dtests=disabled \
-Dexamples=disabled \
-Dspa-plugins=disabled \
@ -571,8 +581,8 @@ COPY --link --from=pipewire {{ LibrariesPath }}/pipewire-cache /
RUN git clone -b 1.22.2 --depth=1 {{ GIT }}/kcat/openal-soft.git \
&& cd openal-soft \
&& CFLAGS="{{ HFLAGS }}" CXXFLAGS="{{ HFLAGS }}" cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=Release \
&& cmake -GNinja -B build . \
-DCMAKE_BUILD_TYPE=None \
-DLIBTYPE:STRING=STATIC \
-DALSOFT_EXAMPLES=OFF \
-DALSOFT_UTILS=OFF \
@ -602,7 +612,7 @@ COPY --link --from=xcb {{ LibrariesPath }}/xcb-cache /
RUN git clone -b xkbcommon-1.3.1 --depth=1 {{ GIT }}/xkbcommon/libxkbcommon.git \
&& cd libxkbcommon \
&& meson build \
--buildtype=release \
--buildtype=plain \
--default-library=both \
-Denable-docs=false \
-Denable-wayland=false \
@ -632,7 +642,7 @@ RUN git clone -b 2.10.7 --depth=1 {{ GIT }}/libsigcplusplus/libsigcplusplus.git
&& cd libsigcplusplus \
&& export ACLOCAL_PATH="/usr/local/share/aclocal" \
&& NOCONFIGURE=1 ./autogen.sh \
&& CFLAGS="-g -O2 {{ HFLAGS }}" CXXFLAGS="-g -O2 {{ HFLAGS }}" ./configure \
&& ./configure \
--enable-maintainer-mode \
--enable-static \
--disable-documentation \
@ -651,7 +661,7 @@ RUN git clone -b 2.40.0 --depth=1 {{ GIT }}/GNOME/glibmm.git \
&& git apply ../patches/glibmm.patch \
&& export ACLOCAL_PATH="/usr/local/share/aclocal" \
&& NOCONFIGURE=1 ./autogen.sh \
&& CC="gcc -flto {{ HFLAGS }}" CXX="g++ -flto {{ HFLAGS }}" AR=gcc-ar RANLIB=gcc-ranlib ./configure \
&& ./configure \
--enable-maintainer-mode \
--enable-static \
--disable-documentation \
@ -684,10 +694,7 @@ RUN git clone -b {{ QT_TAG }} --depth=1 git://code.qt.io/qt/qt5.git qt_{{ QT }}
&& find ../../patches/qtbase_{{ QT }} -type f -print0 | sort -z | xargs -r0 git apply \
&& cd .. \
&& ./configure -prefix "{{ QT_PREFIX }}" \
-release \
{%- if DEBUG %}
-force-debug-info \
{%- endif %}
CMAKE_BUILD_TYPE=None \
-opensource \
-confirm-license \
-libproxy \
@ -717,7 +724,7 @@ RUN git clone https://chromium.googlesource.com/breakpad/breakpad.git \
&& cd src/third_party/lss \
&& git checkout e1e7b0ad8e \
&& cd ../../.. \
&& ./configure \
&& env -u CFLAGS -u CXXFLAGS ./configure \
&& make -j$(nproc) \
&& make DESTDIR="{{ LibrariesPath }}/breakpad-cache" install \
&& cd .. \
@ -740,11 +747,11 @@ RUN git init tg_owt \
&& git reset --hard FETCH_HEAD \
&& git submodule update --init --recursive --depth=1 \
&& rm -rf .git \
&& cmake -G"Ninja Multi-Config" -B out . \
-DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG {{ HFLAGS }}" \
-DCMAKE_C_FLAGS_DEBUG="-g {{ HFLAGS_DEBUG }}" \
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG {{ HFLAGS }}" \
-DCMAKE_CXX_FLAGS_DEBUG="-g {{ HFLAGS_DEBUG }}" \
&& env -u CFLAGS -u CXXFLAGS cmake -G"Ninja Multi-Config" -B out . \
-DCMAKE_C_FLAGS_RELEASE="$CFLAGS" \
-DCMAKE_C_FLAGS_DEBUG="{{ CFLAGS_DEBUG }}" \
-DCMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
-DCMAKE_CXX_FLAGS_DEBUG="{{ CFLAGS_DEBUG }}" \
-DTG_OWT_SPECIAL_TARGET=linux \
-DTG_OWT_LIBJPEG_INCLUDE_PATH=/usr/local/include \
-DTG_OWT_OPENSSL_INCLUDE_PATH={{ OPENSSL_PREFIX }}/include \
@ -765,7 +772,7 @@ RUN cmake --build out --config Debug --parallel \
&& find out -mindepth 1 -maxdepth 1 ! -name Debug -exec rm -rf {} \;
{%- endif %}
FROM builder
FROM builder-base
COPY --link --from=libffi {{ LibrariesPath }}/libffi-cache /
COPY --link --from=zlib {{ LibrariesPath }}/zlib-cache /
COPY --link --from=xz {{ LibrariesPath }}/xz-cache /