Skip to content

Commit c881451

Browse files
committed
Minimize size of intermediate dist artifacts
1 parent 59a4855 commit c881451

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,16 @@ dist-macos: ## Build an LLVM release distribution for x86_64-apple-darwin
7575
--with-assertions \
7676
--build-dir=$(CWD)/build/release \
7777
--install-dir=$(CWD)/build/x86_64-apple-darwin \
78-
--dist-dir=$(CWD)/build/packages/dist
78+
--dist-dir=$(CWD)/build/packages/dist \
79+
--clean-obj
7980

8081
dist-linux: ## Build an LLVM release distribution for x86_64-unknown-linux
8182
@mkdir -p build/packages/ && \
8283
cd lumen/ && \
8384
docker build \
8485
-t llvm-project:dist \
8586
--target=dist \
86-
--build-arg buildscript_args="-release=$(RELEASE)" . && \
87+
--build-arg buildscript_args="-release=$(RELEASE) -clean-obj" . && \
8788
utils/dist/extract-release.sh -release $(RELEASE)
8889

8990
docker: ## Build a Docker image containing an LLVM distribution

lumen/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ RUN mkdir /tmp/cmake-install && \
5252
tar -xzf cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz -C /usr/local --strip-components=1 && \
5353
cd / && rm -rf /tmp/cmake-install
5454

55+
FROM builder AS stage1
56+
ARG buildscript_args
57+
5558
# Checkout the source code.
5659
RUN mkdir -p /tmp/sources && \
5760
git clone --depth=1 --single-branch --branch lumen https://github.com/lumen/llvm-project /tmp/sources
5861

5962
ADD utils/dist /tmp/scripts
6063

6164
# Run the stage1 build. This bootstraps the clang compiler.
62-
ARG buildscript_args
6365
RUN mkdir -p /tmp/build && \
6466
mkdir -p /tmp/install && \
6567
mkdir -p /tmp/dist && \
@@ -87,7 +89,7 @@ RUN /tmp/scripts/build-dist.sh \
8789

8890
# Distribution image. Produces a scratch image with the release package
8991
FROM scratch AS dist
90-
COPY --from=builder /tmp/dist /opt/dist
92+
COPY --from=stage1 /tmp/dist /opt/dist
9193

9294
# Stage 2. Produce a minimal release image with build results.
9395
FROM launcher.gcr.io/google/debian9:latest AS release
@@ -100,5 +102,5 @@ RUN apt-get update && \
100102
binutils && \
101103
rm -rf /var/lib/apt/lists/*
102104
# Copy build results of stage 1 to /usr/local.
103-
COPY --from=builder /tmp/install/ /usr/local/
105+
COPY --from=stage1 /tmp/install/ /usr/local/
104106
ENTRYPOINT ["bash"]

lumen/utils/dist/build-dist.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enable_link_dylib="OFF"
2727
enable_static_libcpp=""
2828
enable_build_shared="OFF"
2929
skip_build=""
30+
clean_obj=""
3031
skip_install=""
3132
skip_dist=""
3233
enable_ccache="OFF"
@@ -103,6 +104,7 @@ function usage() {
103104
echo " -skip-build Skip building and go straight to install"
104105
echo " -skip-install Do not perform install step at end of build"
105106
echo " -skip-dist Do build a distribution package"
107+
echo " -clean-obj Remove obj directory after build is complete"
106108
echo " -with-docs Build documentation"
107109
echo " -no-docs Do not build documentation"
108110
echo " -with-examples Build examples"
@@ -205,6 +207,9 @@ while [ $# -gt 0 ]; do
205207
-skip-dist | --skip-dist)
206208
skip_dist="true"
207209
;;
210+
-clean-obj | --clean-obj)
211+
clean_obj="true"
212+
;;
208213
-with-docs | --with-docs)
209214
enable_docs="ON"
210215
;;
@@ -637,7 +642,11 @@ else
637642
configure_core 1 $flavor "$stage1_objdir"
638643
build_core 1 $flavor "$stage1_objdir" "$stage1_destdir"
639644
clean_RPATH "${stage1_destdir}/usr/local"
640-
;;
645+
646+
if [ "${clean_obj}" = "true" ]; then
647+
rm -rf "${stage1_objdir}"
648+
fi
649+
;;
641650
2)
642651
if [ -z "$skip_build" ]; then
643652
echo "# Stage 2: Preparing Build Enviornment"
@@ -664,6 +673,10 @@ else
664673
configure_core 2 $flavor "$stage2_objdir"
665674
build_core 2 $flavor "$stage2_objdir" "$stage2_destdir"
666675
clean_RPATH "${stage2_destdir}/usr/local"
676+
677+
if [ "${clean_obj}" = "true" ]; then
678+
rm -rf "${stage2_objdir}"
679+
fi
667680
else
668681
if [ ! -d "$stage2_destdir" ]; then
669682
echo "# Unable to skip build! Previous stage 2 build doesn't exist"

0 commit comments

Comments
 (0)