Skip to content

Commit

Permalink
Zstd workaround for hylo-lang/llvm-build#8 (#34)
Browse files Browse the repository at this point in the history
Work around hylo-lang/llvm-build#8

This finds libzstd using `pkg-config` instead of relying on the `RUNPATH` embedded in `llvm-config`, if `llvm-config` doesn't run without help.
  • Loading branch information
dabrahams authored Feb 28, 2024
1 parent 85f52ab commit 2ac3ac7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Tools/make-pkgconfig.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/usr/bin/env bash
set -e
set -o pipefail

# Work around https://github.com/hylo-lang/llvm-build/issues/8
#
# We need to be resilient to no libzstd being found by pkg-config, as it is apparently not on linux.
zstd_dash_L="$(pkg-config --silence-errors --libs-only-L libzstd || true)"
if ! (llvm-config > /dev/null 2>&1); then
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "cygwin" || "$OSTYPE" == "freebsd"* ]]; then
export LD_LIBRARY_PATH="${zstd_dash_L#-L}:$LD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "darwin"* ]]; then
export DYLD_LIBRARY_PATH="${zstd_dash_L#-L}:$DYLD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
export PATH="${zstd_dash_L#-L}:$PATH"
fi
fi

version=$(llvm-config --version)
filename=$1
Expand All @@ -20,7 +35,7 @@ echo Name: LLVM > $filename
echo Description: Low-level Virtual Machine compiler framework >> $filename
echo Version: $(echo ${version} | sed 's/\([0-9.]\+\).*/\1/') >> $filename
echo URL: http://www.llvm.org/ >> $filename
echo Libs: -L$(llvm-config --libdir) $(pkg-config --libs-only-L libzstd) ${libs} $(llvm-config --system-libs --libs analysis bitwriter core native passes target) >> $filename
echo Libs: -L$(llvm-config --libdir) ${zstd_dash_L} ${libs} $(llvm-config --system-libs --libs analysis bitwriter core native passes target) >> $filename
echo Cflags: -I$(llvm-config --includedir) >> $filename

echo "$filename written:"
Expand Down

0 comments on commit 2ac3ac7

Please sign in to comment.