1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 21:17:28 +03:00

Link against libc++ instead of libstdc++ if -DMOLD_MOSTLY_STATIC

This commit is contained in:
Rui Ueyama 2022-11-13 16:16:03 +08:00
parent 22f3b7ed24
commit 94122f4ffd
3 changed files with 12 additions and 18 deletions

View File

@ -88,14 +88,15 @@ if(MOLD_USE_TSAN)
target_link_options(mold PRIVATE -fsanitize=thread)
endif()
# Statically-link libstdc++ and libcrypto if -DMOLD_MOSTLY_STATIC=ON.
# Statically-link libc++ and libcrypto if -DMOLD_MOSTLY_STATIC=ON.
#
# This option is intended to be used by `./dist.sh` script to create a
# mold binary that works on various Linux distros. You probably don't
# need nor want to set this to ON.
option(MOLD_MOSTLY_STATIC "Statically link libstdc++ and libcrypto" OFF)
if(MOLD_MOSTLY_STATIC)
target_link_options(mold PRIVATE -static-libstdc++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
target_link_options(mold PRIVATE -stdlib=libc++ -static-libstdc++)
target_link_libraries(mold PRIVATE libcrypto.a)
endif()

View File

@ -1,22 +1,15 @@
# This dockerfile creates a reproducible build environment for mold.
#
# $ docker buildx create --use
# $ docker buildx build --platform x86_64,aarch64,arm,ppc64le,s390x -t rui314/mold-builder:latest --push .
# $ docker buildx build --platform x86_64,aarch64 -t rui314/mold-builder:latest --push .
FROM ubuntu:18.04
FROM ubuntu:20.04
ENV TZ=Europe/London
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update && \
apt-get install -y --no-install-recommends build-essential wget libstdc++-11-dev zlib1g-dev gcc-10 g++-10 python3 && \
\
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common gpg-agent wget cmake build-essential g++ && \
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh) libc++-15-dev" && \
mkdir /openssl && cd /openssl && \
wget -O- -q https://www.openssl.org/source/openssl-3.0.7.tar.gz | tar --strip-components=1 -xzf - && \
./Configure --prefix=/usr/local && \
make -j$(nproc) && \
make -j$(nproc) install && \
\
mkdir /cmake && cd /cmake && \
wget -O- -q https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2.tar.gz | tar --strip-components=1 -xzf - && \
./bootstrap --parallel=$(nproc) && make -j$(nproc) && make -j$(nproc) install
make -j$(nproc) install

View File

@ -8,12 +8,12 @@
# and librt, as they almost always exist on any Linux systems.
if [ $# -ne 1 ]; then
echo "Usage: $0 [ x86_64 | aarch64 | arm | ppc64le | s390x ]"
echo "Usage: $0 [ x86_64 | aarch64 ]"
exit 1
fi
arch=$1
echo $arch | grep -Eq '^(x86_64|aarch64|arm|ppc64le|s390x)$' || \
echo $arch | grep -Eq '^(x86_64|aarch64)$' || \
{ echo "Error: no docker image for $arch"; exit 1; }
version=$(sed -n 's/^project(mold VERSION \(.*\))/\1/p' $(dirname $0)/CMakeLists.txt)
@ -24,9 +24,9 @@ docker run --platform linux/$arch -it --rm -v "$(pwd):/mold" \
-e "OWNER=$(id -u):$(id -g)" rui314/mold-builder:latest \
bash -c "mkdir /tmp/build &&
cd /tmp/build &&
cmake -DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10 -DMOLD_MOSTLY_STATIC=On -DCMAKE_BUILD_TYPE=Release /mold &&
cmake -DCMAKE_C_COMPILER=clang-15 -DCMAKE_CXX_COMPILER=clang++-15 -DMOLD_MOSTLY_STATIC=On -DCMAKE_BUILD_TYPE=Release /mold &&
cmake --build . -j\$(nproc) &&
[ $arch = arm ] || ctest -j\$(nproc) &&
ctest -E '^example' -j\$(nproc) &&
cmake --install . --prefix $dest --strip &&
tar czf /mold/$dest.tar.gz $dest &&
cp mold mold-wrapper.so /mold &&