xref: /aosp_15_r20/external/executorch/.ci/scripts/setup-qnn-deps.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1*523fa7a6SAndroid Build Coastguard Worker#!/bin/bash
2*523fa7a6SAndroid Build Coastguard Worker# Copyright (c) Meta Platforms, Inc. and affiliates.
3*523fa7a6SAndroid Build Coastguard Worker# All rights reserved.
4*523fa7a6SAndroid Build Coastguard Worker#
5*523fa7a6SAndroid Build Coastguard Worker# This source code is licensed under the BSD-style license found in the
6*523fa7a6SAndroid Build Coastguard Worker# LICENSE file in the root directory of this source tree.
7*523fa7a6SAndroid Build Coastguard Worker
8*523fa7a6SAndroid Build Coastguard Workerset -ex
9*523fa7a6SAndroid Build Coastguard Worker
10*523fa7a6SAndroid Build Coastguard Workerverify_pkg_installed() {
11*523fa7a6SAndroid Build Coastguard Worker  echo $(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed")
12*523fa7a6SAndroid Build Coastguard Worker}
13*523fa7a6SAndroid Build Coastguard Worker
14*523fa7a6SAndroid Build Coastguard Workerinstall_qnn() {
15*523fa7a6SAndroid Build Coastguard Worker  echo "Start installing qnn."
16*523fa7a6SAndroid Build Coastguard Worker  QNN_INSTALLATION_DIR=/tmp/qnn
17*523fa7a6SAndroid Build Coastguard Worker  mkdir -p "${QNN_INSTALLATION_DIR}"
18*523fa7a6SAndroid Build Coastguard Worker
19*523fa7a6SAndroid Build Coastguard Worker  curl -Lo /tmp/v2.25.0.24.07.28.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.25.0.240728.zip"
20*523fa7a6SAndroid Build Coastguard Worker  echo "Finishing downloading qnn sdk."
21*523fa7a6SAndroid Build Coastguard Worker  unzip -qo /tmp/v2.25.0.24.07.28.zip -d /tmp
22*523fa7a6SAndroid Build Coastguard Worker  echo "Finishing unzip qnn sdk."
23*523fa7a6SAndroid Build Coastguard Worker
24*523fa7a6SAndroid Build Coastguard Worker
25*523fa7a6SAndroid Build Coastguard Worker  # Print the content for manual verification
26*523fa7a6SAndroid Build Coastguard Worker  ls -lah "/tmp/qairt"
27*523fa7a6SAndroid Build Coastguard Worker  mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
28*523fa7a6SAndroid Build Coastguard Worker  echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
29*523fa7a6SAndroid Build Coastguard Worker
30*523fa7a6SAndroid Build Coastguard Worker  ls -lah "${QNN_INSTALLATION_DIR}"
31*523fa7a6SAndroid Build Coastguard Worker}
32*523fa7a6SAndroid Build Coastguard Worker
33*523fa7a6SAndroid Build Coastguard Workersetup_libc++() {
34*523fa7a6SAndroid Build Coastguard Worker  clang_version=$1
35*523fa7a6SAndroid Build Coastguard Worker  sudo apt-get update
36*523fa7a6SAndroid Build Coastguard Worker  pkgs_to_check=("libc++-${clang_version}-dev")
37*523fa7a6SAndroid Build Coastguard Worker  j=0
38*523fa7a6SAndroid Build Coastguard Worker  while [ $j -lt ${#pkgs_to_check[*]} ]; do
39*523fa7a6SAndroid Build Coastguard Worker    install_status=$(verify_pkg_installed ${pkgs_to_check[$j]})
40*523fa7a6SAndroid Build Coastguard Worker    if [ "$install_status" == "" ]; then
41*523fa7a6SAndroid Build Coastguard Worker      sudo apt-get install -y ${pkgs_to_check[$j]}
42*523fa7a6SAndroid Build Coastguard Worker      if [[ $? -ne 0 ]]; then
43*523fa7a6SAndroid Build Coastguard Worker        echo "ERROR: Failed to install required packages for libc++"
44*523fa7a6SAndroid Build Coastguard Worker        exit 1
45*523fa7a6SAndroid Build Coastguard Worker      fi
46*523fa7a6SAndroid Build Coastguard Worker    fi
47*523fa7a6SAndroid Build Coastguard Worker    j=$(( $j +1));
48*523fa7a6SAndroid Build Coastguard Worker  done
49*523fa7a6SAndroid Build Coastguard Worker}
50*523fa7a6SAndroid Build Coastguard Worker
51*523fa7a6SAndroid Build Coastguard Worker# This needs to match with the clang version from the Docker image
52*523fa7a6SAndroid Build Coastguard Workersetup_libc++ 12
53*523fa7a6SAndroid Build Coastguard Workerinstall_qnn
54