Skip to content

Commit

Permalink
Minimize size of intermediate dist artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Mar 9, 2020
1 parent 59a4855 commit c881451
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ dist-macos: ## Build an LLVM release distribution for x86_64-apple-darwin
--with-assertions \
--build-dir=$(CWD)/build/release \
--install-dir=$(CWD)/build/x86_64-apple-darwin \
--dist-dir=$(CWD)/build/packages/dist
--dist-dir=$(CWD)/build/packages/dist \
--clean-obj

dist-linux: ## Build an LLVM release distribution for x86_64-unknown-linux
@mkdir -p build/packages/ && \
cd lumen/ && \
docker build \
-t llvm-project:dist \
--target=dist \
--build-arg buildscript_args="-release=$(RELEASE)" . && \
--build-arg buildscript_args="-release=$(RELEASE) -clean-obj" . && \
utils/dist/extract-release.sh -release $(RELEASE)

docker: ## Build a Docker image containing an LLVM distribution
Expand Down
8 changes: 5 additions & 3 deletions lumen/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ RUN mkdir /tmp/cmake-install && \
tar -xzf cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz -C /usr/local --strip-components=1 && \
cd / && rm -rf /tmp/cmake-install

FROM builder AS stage1
ARG buildscript_args

# Checkout the source code.
RUN mkdir -p /tmp/sources && \
git clone --depth=1 --single-branch --branch lumen https://github.com/lumen/llvm-project /tmp/sources

ADD utils/dist /tmp/scripts

# Run the stage1 build. This bootstraps the clang compiler.
ARG buildscript_args
RUN mkdir -p /tmp/build && \
mkdir -p /tmp/install && \
mkdir -p /tmp/dist && \
Expand Down Expand Up @@ -87,7 +89,7 @@ RUN /tmp/scripts/build-dist.sh \

# Distribution image. Produces a scratch image with the release package
FROM scratch AS dist
COPY --from=builder /tmp/dist /opt/dist
COPY --from=stage1 /tmp/dist /opt/dist

# Stage 2. Produce a minimal release image with build results.
FROM launcher.gcr.io/google/debian9:latest AS release
Expand All @@ -100,5 +102,5 @@ RUN apt-get update && \
binutils && \
rm -rf /var/lib/apt/lists/*
# Copy build results of stage 1 to /usr/local.
COPY --from=builder /tmp/install/ /usr/local/
COPY --from=stage1 /tmp/install/ /usr/local/
ENTRYPOINT ["bash"]
15 changes: 14 additions & 1 deletion lumen/utils/dist/build-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enable_link_dylib="OFF"
enable_static_libcpp=""
enable_build_shared="OFF"
skip_build=""
clean_obj=""
skip_install=""
skip_dist=""
enable_ccache="OFF"
Expand Down Expand Up @@ -103,6 +104,7 @@ function usage() {
echo " -skip-build Skip building and go straight to install"
echo " -skip-install Do not perform install step at end of build"
echo " -skip-dist Do build a distribution package"
echo " -clean-obj Remove obj directory after build is complete"
echo " -with-docs Build documentation"
echo " -no-docs Do not build documentation"
echo " -with-examples Build examples"
Expand Down Expand Up @@ -205,6 +207,9 @@ while [ $# -gt 0 ]; do
-skip-dist | --skip-dist)
skip_dist="true"
;;
-clean-obj | --clean-obj)
clean_obj="true"
;;
-with-docs | --with-docs)
enable_docs="ON"
;;
Expand Down Expand Up @@ -637,7 +642,11 @@ else
configure_core 1 $flavor "$stage1_objdir"
build_core 1 $flavor "$stage1_objdir" "$stage1_destdir"
clean_RPATH "${stage1_destdir}/usr/local"
;;

if [ "${clean_obj}" = "true" ]; then
rm -rf "${stage1_objdir}"
fi
;;
2)
if [ -z "$skip_build" ]; then
echo "# Stage 2: Preparing Build Enviornment"
Expand All @@ -664,6 +673,10 @@ else
configure_core 2 $flavor "$stage2_objdir"
build_core 2 $flavor "$stage2_objdir" "$stage2_destdir"
clean_RPATH "${stage2_destdir}/usr/local"

if [ "${clean_obj}" = "true" ]; then
rm -rf "${stage2_objdir}"
fi
else
if [ ! -d "$stage2_destdir" ]; then
echo "# Unable to skip build! Previous stage 2 build doesn't exist"
Expand Down

0 comments on commit c881451

Please sign in to comment.