Skip to content

Commit 0b00dd9

Browse files
committed
update: refine LIBCLANG_PATH and LD_LIBRARY_PATH for LLVM Toolset integration
1 parent 628134e commit 0b00dd9

1 file changed

Lines changed: 52 additions & 15 deletions

File tree

.github/workflows/release.yml

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ jobs:
4242
uses: PyO3/maturin-action@v1
4343
env:
4444
# rusty_v8's prebuilt Linux archive uses a TLS model that cannot be
45-
# linked into a Python extension module on x86_64. Source builds
46-
# inject V8_TLS_USED_IN_LIBRARY through the v8 crate build script.
45+
# linked into a Python extension module on x86_64. Source builds set
46+
# v8_monolithic_for_shared_library so V8 uses shared-library-safe TLS.
4747
# aarch64 uses the published rusty_v8 archive.
4848
V8_FROM_SOURCE: ${{ matrix.v8_from_source }}
4949
# The crates.io v8 archive does not include Chromium's
5050
# third_party/rust/chromium_crates_io/vendor tree needed by the
5151
# Temporal Rust dependency, so source builds avoid those GN targets.
5252
EXTRA_GN_ARGS: ${{ matrix.extra_gn_args }}
53-
LIBCLANG_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/libclang
54-
LD_LIBRARY_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/libclang
53+
LIBCLANG_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/llvm-toolset/lib
54+
LD_LIBRARY_PATH: ${{ github.workspace }}/target/${{ matrix.rust_target }}/release/llvm-toolset/lib
5555
with:
5656
target: ${{ matrix.target }}
5757
# Source-building V8 needs Chromium's `gn` binary, which requires
@@ -60,8 +60,8 @@ jobs:
6060
container: ${{ matrix.container }}
6161
docker-options: >-
6262
${{ matrix.docker_options }}
63-
-e LIBCLANG_PATH=${{ github.workspace }}/target/${{ matrix.rust_target }}/release/libclang
64-
-e LD_LIBRARY_PATH=${{ github.workspace }}/target/${{ matrix.rust_target }}/release/libclang
63+
-e LIBCLANG_PATH=${{ github.workspace }}/target/${{ matrix.rust_target }}/release/llvm-toolset/lib
64+
-e LD_LIBRARY_PATH=${{ github.workspace }}/target/${{ matrix.rust_target }}/release/llvm-toolset/lib
6565
before-script-linux: |
6666
if [ "${{ matrix.v8_from_source }}" = "1" ]; then
6767
env -u RUSTC_WRAPPER cargo fetch --locked
@@ -72,19 +72,56 @@ jobs:
7272
fi
7373
CLANG_DIR="${{ github.workspace }}/target/${{ matrix.rust_target }}/release/clang"
7474
python3 "$V8_SRC/tools/clang/scripts/update.py" --output-dir "$CLANG_DIR"
75-
python3 "$V8_SRC/tools/clang/scripts/update.py" --output-dir "$CLANG_DIR" --package libclang
76-
LIBCLANG_SO="$(find "$CLANG_DIR" -name 'libclang.so*' -print -quit)"
75+
76+
install_llvm_toolset() {
77+
if command -v dnf >/dev/null 2>&1; then
78+
dnf install -y llvm-toolset clang-libs && return 0
79+
dnf module install -y llvm-toolset && return 0
80+
dnf install -y clang clang-libs && return 0
81+
fi
82+
if command -v yum >/dev/null 2>&1; then
83+
yum install -y llvm-toolset clang-libs && return 0
84+
yum module install -y llvm-toolset && return 0
85+
yum install -y clang clang-libs && return 0
86+
fi
87+
return 1
88+
}
89+
90+
if ! install_llvm_toolset; then
91+
echo "::error::Could not install LLVM Toolset or clang-libs in the manylinux container."
92+
exit 1
93+
fi
94+
95+
LIBCLANG_SEARCH_DIRS=""
96+
for dir in /opt/rh /usr/lib64 /usr/lib; do
97+
if [ -d "$dir" ]; then
98+
LIBCLANG_SEARCH_DIRS="$LIBCLANG_SEARCH_DIRS $dir"
99+
fi
100+
done
101+
LIBCLANG_SO="$(find $LIBCLANG_SEARCH_DIRS -name 'libclang.so*' -print 2>/dev/null | sort -Vr | head -n1 || true)"
77102
if [ -z "$LIBCLANG_SO" ]; then
78-
echo "::error::Could not find libclang.so under $CLANG_DIR after downloading Chromium's libclang package."
79-
find "$CLANG_DIR" -maxdepth 4 \( -type f -o -type l \) -print | sort | head -200
103+
echo "::error::Could not find libclang.so after installing LLVM Toolset."
104+
find $LIBCLANG_SEARCH_DIRS -maxdepth 6 -name '*clang*' -print 2>/dev/null | sort | head -200 || true
80105
exit 1
81106
fi
82107
LIBCLANG_DIR="$(dirname "$LIBCLANG_SO")"
83-
LIBCLANG_PATH_DIR="${{ github.workspace }}/target/${{ matrix.rust_target }}/release/libclang"
84-
mkdir -p "$(dirname "$LIBCLANG_PATH_DIR")"
85-
rm -rf "$LIBCLANG_PATH_DIR"
86-
ln -s "$LIBCLANG_DIR" "$LIBCLANG_PATH_DIR"
87-
echo "Using LIBCLANG_PATH=$LIBCLANG_PATH_DIR -> $LIBCLANG_DIR"
108+
LLVM_ROOT="$(dirname "$LIBCLANG_DIR")"
109+
CLANG_BIN="$LLVM_ROOT/bin/clang"
110+
if [ ! -x "$CLANG_BIN" ]; then
111+
CLANG_BIN="$(command -v clang || true)"
112+
fi
113+
if [ ! -x "$CLANG_BIN" ]; then
114+
echo "::error::Could not find a clang executable matching the installed libclang."
115+
exit 1
116+
fi
117+
118+
LLVM_TOOLSET_DIR="${{ github.workspace }}/target/${{ matrix.rust_target }}/release/llvm-toolset"
119+
rm -rf "$LLVM_TOOLSET_DIR"
120+
mkdir -p "$LLVM_TOOLSET_DIR"
121+
ln -s "$LIBCLANG_DIR" "$LLVM_TOOLSET_DIR/lib"
122+
ln -s "$(dirname "$CLANG_BIN")" "$LLVM_TOOLSET_DIR/bin"
123+
echo "Using LIBCLANG_PATH=$LLVM_TOOLSET_DIR/lib -> $LIBCLANG_DIR"
124+
echo "Using clang=$LLVM_TOOLSET_DIR/bin/clang -> $CLANG_BIN"
88125
fi
89126
args: >-
90127
--release

0 commit comments

Comments
 (0)