Skip to content

Commit

Permalink
Add a script to build programs with mold using Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed May 25, 2021
1 parent 1727e5b commit 712eab0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ core
ld
oneTBB
mimalloc
gentoo
60 changes: 60 additions & 0 deletions gentoo-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
#
# This test script builds lots of programs using mold in a Docker
# environment to make sure that mold can build programs in the wild.
# We are using Gentoo Linux as a build environment, because its
# source-based package allows us to build programs without any hassle.

if [ "$1" = "" ]; then
echo "Usage: $0 gentoo-package-name"
exit 1
fi

set -x

# Create a Docker image
if ! docker image ls mold-gentoo | grep -q mold-gentoo; then
set -e
cat <<EOF | docker build -t mold-gentoo -
FROM gentoo/stage3
RUN echo 'FEATURES="${FEATURE} noclean nostrip -ipc-sandbox -network-sandbox -pid-sandbox -sandbox"' >> /etc/portage/make.conf
RUN emerge-webrsync
EOF
set +e
fi

# Build mold as a statically-linked executable
if ! [ -f mold ] || ! ldd mold 2>&1 | grep -q 'not a dynamic executable'; then
make clean
./build-static.sh
fi

# Build a given package in Docker
run() {
package="$1"
cmd="FEATURES=test MAKEOPTS=-j8 emerge $package"
filename=`echo "$package" | sed 's!/!_!g'`
link="ln -sf /mold/mold /usr/x86_64-pc-linux-gnu/bin/ld"

mkdir -p gentoo/success gentoo/failure
docker run --rm --cap-add=SYS_PTRACE -v `pwd`:/mold mold-gentoo \
bash -c "$cmd" > gentoo/$filename.ld

if [ $? = 0 ]; then
mv gentoo/$filename.ld gentoo/success
else
mv gentoo/$filename.ld gentoo/failure
fi

docker run --rm --cap-add=SYS_PTRACE -v `pwd`:/mold mold-gentoo \
bash -c "$link; $cmd" > gentoo/$filename.mold

if [ $? = 0 ]; then
mv gentoo/$filename.mold gentoo/success
else
mv gentoo/$filename.mold gentoo/failure
fi
}

# Run a test
run "$1"

0 comments on commit 712eab0

Please sign in to comment.