Skip to content

cmake: LLVM needs to link against zlib #8932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ message("Configuring zig version ${ZIG_VERSION}")

set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib")
set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache if available")

Expand All @@ -75,7 +76,8 @@ if(CCACHE_PROGRAM AND ZIG_USE_CCACHE)
endif()

if(ZIG_STATIC)
set(ZIG_STATIC_LLVM "on")
set(ZIG_STATIC_LLVM ON)
set(ZIG_STATIC_ZLIB ON)
endif()

string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
Expand All @@ -101,11 +103,13 @@ find_package(llvm)
find_package(clang)
find_package(lld)

if(APPLE AND ZIG_STATIC)
if(ZIG_STATIC_ZLIB)
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
find_library(ZLIB NAMES libz.a z zlib libz)
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz)
list(APPEND LLVM_LIBRARIES "${ZLIB}")
endif()

if(APPLE AND ZIG_STATIC)
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
find_library(CURSES NAMES libcurses.a curses libcurses libncurses.a ncurses libncurses)
list(APPEND LLVM_LIBRARIES "${CURSES}")
Expand Down
2 changes: 1 addition & 1 deletion ci/azure/linux_script
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo apt-get install -y cmake s3cmd tidy
ZIGDIR="$(pwd)"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2168+2d1196773"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
MCPU="baseline"
JOBS="-j$(nproc)"
Expand Down
6 changes: 3 additions & 3 deletions ci/azure/macos_arm64_script
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ ZIGDIR="$(pwd)"
HOST_ARCH="x86_64"
HOST_TARGET="$HOST_ARCH-macos-gnu"
HOST_MCPU="baseline"
HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2168+2d1196773"
HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2703+c12704a33"
HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME"

ARCH="aarch64"
TARGET="$ARCH-macos-gnu"
MCPU="cyclone"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2168+2d1196773"
MCPU="apple_a14"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"

JOBS="-j2"
Expand Down
2 changes: 1 addition & 1 deletion ci/azure/macos_script
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ZIGDIR="$(pwd)"
ARCH="x86_64"
TARGET="$ARCH-macos-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2168+2d1196773"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"

Expand Down
4 changes: 2 additions & 2 deletions ci/azure/windows_msvc_install
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pacman -Suy --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz

pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-12.0.0-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-12.0.0-x86_64-windows-msvc-release-mt.tar.xz
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz
2 changes: 1 addition & 1 deletion ci/azure/windows_msvc_script.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SET "MSYSTEM=%PREVMSYSTEM%"

SET "ZIGBUILDDIR=%SRCROOT%\build"
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-12.0.0-x86_64-windows-msvc-release-mt"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt"

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64

Expand Down
10 changes: 5 additions & 5 deletions ci/drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ platform:

steps:
- name: build
image: ziglang/static-base:llvm12-aarch64-2
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_build

- name: test-1
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-2
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 1

- name: test-2
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-2
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 2

- name: test-3
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-2
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 3

Expand All @@ -38,7 +38,7 @@ steps:
- test-1
- test-2
- test-3
image: ziglang/static-base:llvm12-aarch64-2
image: ziglang/static-base:llvm12-aarch64-5
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN
Expand Down
47 changes: 44 additions & 3 deletions ci/drone/linux_script_build
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,30 @@

. ./ci/drone/linux_script_base

apk update
apk add samurai
PREFIX="/deps/local"
ZIG="$PREFIX/bin/zig"
TARGET="$TRIPLEARCH-linux-musl"
MCPU="baseline"

export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"

# The `CMAKE_AR` parameter will consider any spaces to
# be part of the executable path rather than CLI args, so we have
# to create wrapper scripts for `zig ar` and zig ranlib`.

cat <<'ENDFILE' >$PREFIX/bin/ar
#!/bin/sh
/deps/local/bin/zig ar $@
ENDFILE

cat <<'ENDFILE' >$PREFIX/bin/ranlib
#!/bin/sh
/deps/local/bin/zig ranlib $@
ENDFILE

chmod +x $PREFIX/bin/ar
chmod +x $PREFIX/bin/ranlib

# Make the `zig version` number consistent.
# This will affect the cmake command below.
Expand All @@ -13,6 +35,25 @@ git fetch --tags

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja
cmake .. \
-DCMAKE_INSTALL_PREFIX="$DISTDIR" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
-DCMAKE_RANLIB="$PREFIX/bin/ranlib" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja

# Now CMake will use Zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
samu install

# Here we rebuild Zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"
samu install
2 changes: 1 addition & 1 deletion ci/drone/linux_script_finalize
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ -n "$DRONE_PULL_REQUEST" ]; then
fi

apk update
apk add py3-pip xz perl-utils jq curl samurai
apk add py3-pip perl-utils jq curl
pip3 install s3cmd

cd build
Expand Down
2 changes: 1 addition & 1 deletion ci/srht/freebsd_script
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sudo pkg update -fq
sudo pkg install -y cmake py38-s3cmd wget curl jq samurai

ZIGDIR="$(pwd)"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.8.0-dev.1939+5a3ea9bec"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"

cd $HOME
Expand Down