Skip to content

Commit 40f581b

Browse files
committed
Install libcpp from release package other than apt-get
Differential Revision: [D77048745](https://our.internmc.facebook.com/intern/diff/D77048745/) [ghstack-poisoned]
1 parent 496cb05 commit 40f581b

File tree

2 files changed

+118
-28
lines changed

2 files changed

+118
-28
lines changed

.ci/scripts/setup-qnn-deps.sh

Lines changed: 101 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,126 @@
11
#!/bin/bash
2-
# Copyright (c) Meta Platforms, Inc. and affiliates.
3-
# All rights reserved.
4-
#
5-
# This source code is licensed under the BSD-style license found in the
6-
# LICENSE file in the root directory of this source tree.
7-
82
set -ex
93

4+
# Function to install Android NDK (only if not already set)
5+
setup_android_ndk() {
6+
# Check if ANDROID_NDK_ROOT is already set and valid
7+
if [ -n "${ANDROID_NDK_ROOT}" ] && [ -d "${ANDROID_NDK_ROOT}" ]; then
8+
echo "Android NDK already set to ${ANDROID_NDK_ROOT} - skipping installation"
9+
return
10+
fi
11+
12+
NDK_VERSION="r25c"
13+
NDK_INSTALL_DIR="/tmp/android-ndk"
14+
15+
if [ -d "${NDK_INSTALL_DIR}/ndk" ]; then
16+
echo "Android NDK already installed at ${NDK_INSTALL_DIR}/ndk"
17+
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
18+
return
19+
fi
20+
21+
echo "Installing Android NDK ${NDK_VERSION}"
22+
mkdir -p "${NDK_INSTALL_DIR}"
23+
NDK_ZIP="android-ndk-${NDK_VERSION}-linux.zip"
24+
25+
curl -Lo "/tmp/${NDK_ZIP}" "https://dl.google.com/android/repository/${NDK_ZIP}"
26+
unzip -q "/tmp/${NDK_ZIP}" -d "${NDK_INSTALL_DIR}"
27+
mv "${NDK_INSTALL_DIR}/android-ndk-${NDK_VERSION}" "${NDK_INSTALL_DIR}/ndk"
28+
29+
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
30+
echo "Android NDK installed to ${ANDROID_NDK_ROOT}"
31+
}
32+
1033
verify_pkg_installed() {
11-
echo $(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed")
34+
dpkg-query -W --showformat='${Status}\n' "$1" | grep -q "install ok installed"
1235
}
1336

1437
install_qnn() {
38+
# Check if QNN_SDK_ROOT is already set and valid
39+
if [ -n "${QNN_SDK_ROOT}" ] && [ -d "${QNN_SDK_ROOT}" ]; then
40+
echo "QNN SDK already set to ${QNN_SDK_ROOT} - skipping installation"
41+
return
42+
fi
43+
1544
echo "Start installing qnn."
16-
QNN_INSTALLATION_DIR=/tmp/qnn
45+
QNN_INSTALLATION_DIR="/tmp/qnn"
46+
47+
# Clean up any previous installation
48+
if [ -d "${QNN_INSTALLATION_DIR}" ]; then
49+
echo "Removing previous QNN installation at ${QNN_INSTALLATION_DIR}"
50+
rm -rf "${QNN_INSTALLATION_DIR}"
51+
fi
52+
1753
mkdir -p "${QNN_INSTALLATION_DIR}"
1854

1955
curl -Lo /tmp/v2.28.0.24.10.29.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.28.0.241029.zip"
2056
echo "Finishing downloading qnn sdk."
2157
unzip -qo /tmp/v2.28.0.24.10.29.zip -d /tmp
2258
echo "Finishing unzip qnn sdk."
2359

24-
2560
# Print the content for manual verification
61+
echo "Contents of /tmp/qairt:"
2662
ls -lah "/tmp/qairt"
27-
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
28-
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
2963

64+
# Check if we're moving a directory or files
65+
if [ -d "/tmp/qairt/2.28.0.241029" ]; then
66+
# Move the specific version directory instead of its contents
67+
mv "/tmp/qairt/2.28.0.241029" "${QNN_INSTALLATION_DIR}"
68+
else
69+
# Move all contents normally
70+
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
71+
fi
72+
73+
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
74+
echo "Final QNN installation contents:"
3075
ls -lah "${QNN_INSTALLATION_DIR}"
76+
77+
# Set QNN_SDK_ROOT environment variable
78+
export QNN_SDK_ROOT="${QNN_INSTALLATION_DIR}"
79+
echo "Set QNN_SDK_ROOT=${QNN_SDK_ROOT}"
3180
}
3281

33-
setup_libc++() {
82+
setup_libcpp() {
3483
clang_version=$1
35-
sudo apt-get update
36-
pkgs_to_check=("libc++-${clang_version}-dev")
37-
j=0
38-
while [ $j -lt ${#pkgs_to_check[*]} ]; do
39-
install_status=$(verify_pkg_installed ${pkgs_to_check[$j]})
40-
if [ "$install_status" == "" ]; then
41-
sudo apt-get install -y ${pkgs_to_check[$j]}
42-
if [[ $? -ne 0 ]]; then
43-
echo "ERROR: Failed to install required packages for libc++"
44-
exit 1
45-
fi
46-
fi
47-
j=$(( $j +1));
48-
done
84+
LLVM_VERSION="12.0.0"
85+
INSTALL_DIR="/usr/local/libcxx-${LLVM_VERSION}"
86+
87+
echo "Installing libc++-${clang_version}-dev manually from LLVM releases"
88+
89+
# Create temporary directory
90+
TEMP_DIR=$(mktemp -d)
91+
pushd "${TEMP_DIR}"
92+
93+
# Download and extract LLVM binaries
94+
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
95+
curl -LO "${LLVM_URL}"
96+
tar -xf "clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
97+
98+
# Create necessary directories
99+
sudo mkdir -p "${INSTALL_DIR}/include"
100+
sudo mkdir -p "${INSTALL_DIR}/lib" # FIX: Create lib directory
101+
102+
# Copy libc++ headers and libraries
103+
sudo cp -r clang+llvm*/include/c++/v1/* "${INSTALL_DIR}/include/"
104+
sudo cp -r clang+llvm*/lib/*.so* "${INSTALL_DIR}/lib/"
105+
106+
# Create system symlinks
107+
sudo mkdir -p /usr/include/c++
108+
sudo ln -sf "${INSTALL_DIR}/include" /usr/include/c++/v1
109+
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1.0" /usr/lib/libc++.so.1
110+
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1" /usr/lib/libc++.so
111+
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1.0" /usr/lib/libc++abi.so.1
112+
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1" /usr/lib/libc++abi.so
113+
114+
# Update library cache
115+
sudo ldconfig
116+
117+
# Cleanup
118+
popd
119+
rm -rf "${TEMP_DIR}"
120+
121+
echo "libc++-${clang_version}-dev installed to ${INSTALL_DIR}"
49122
}
50123

51-
# This needs to match with the clang version from the Docker image
52-
setup_libc++ 12
124+
# Main execution flow
125+
setup_libcpp 12
53126
install_qnn
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# Test the end-to-end flow of mps runner.
9+
10+
set -e
11+
12+
# shellcheck source=/dev/null
13+
source "$(dirname "${BASH_SOURCE[0]}")/../../../.ci/scripts/setup-qnn-deps.sh"
14+
15+
setup_libcpp 12
16+
setup_android_ndk
17+
install_qnn

0 commit comments

Comments
 (0)