Skip to content

Commit

Permalink
Use Link Time Optimization during compilation (#153)
Browse files Browse the repository at this point in the history
* Use Link Time Optimization during compilation

Resolves #152

Uses the cc and ld options from the Ubuntu build.

https://gcc.gnu.org/wiki/LinkTimeOptimization

* Update readme.md
  • Loading branch information
macbre authored Nov 25, 2024
1 parent 3475299 commit cb29f5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ARG NGINX_USER_UID=100
ARG NGINX_GROUP_GID=101

# https://nginx.org/en/docs/http/ngx_http_v3_module.html
# https://nginx.org/en/docs/configure.html
ARG CONFIG="\
--build=$NGINX_COMMIT \
--prefix=/etc/nginx \
Expand Down Expand Up @@ -176,11 +177,14 @@ RUN \
&& mv /usr/src/njs/build/njs /usr/sbin/njs \
&& echo "njs v$(njs -v)"

# https://github.com/macbre/docker-nginx-http3/issues/152
ARG CC_OPT='-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects'
ARG LD_OPT='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto'
RUN \
echo "Building nginx ..." \
&& mkdir -p /var/run/nginx/ \
&& cd /usr/src/nginx-$NGINX_VERSION \
&& ./auto/configure $CONFIG \
&& ./auto/configure $CONFIG --with-cc-opt="$CC_OPT" --with-ld-opt="$LD_OPT" \
&& make -j"$(getconf _NPROCESSORS_ONLN)"

RUN \
Expand Down Expand Up @@ -213,8 +217,8 @@ ARG NGINX_COMMIT
ARG NGINX_USER_UID
ARG NGINX_GROUP_GID

ENV NGINX_VERSION $NGINX_VERSION
ENV NGINX_COMMIT $NGINX_COMMIT
ENV NGINX_VERSION=$NGINX_VERSION
ENV NGINX_COMMIT=$NGINX_COMMIT

COPY --from=base /var/run/nginx/ /var/run/nginx/
COPY --from=base /tmp/runDeps.txt /tmp/runDeps.txt
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ configure arguments:
--add-module=/usr/src/headers-more-nginx-module-0.37
--add-module=/usr/src/njs/nginx
--add-dynamic-module=/usr/src/ngx_http_geoip2_module
--with-cc-opt='-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects'
--with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto'
$ docker run -it macbre/nginx-http3 njs -v
0.8.6
Expand Down

0 comments on commit cb29f5c

Please sign in to comment.