返回 CodeWhale
ohos-env.sh
根目录 / scripts / ohos / ohos-env.sh
1 #!/usr/bin/env sh
2
3 if [ -z "${OHOS_NATIVE_SDK:-}" ]; then
4 echo "error: set OHOS_NATIVE_SDK to the OpenHarmony native SDK directory." >&2
5 return 1 2>/dev/null || exit 1
6 fi
7
8 if [ ! -d "$OHOS_NATIVE_SDK" ]; then
9 echo "error: OHOS_NATIVE_SDK does not exist: $OHOS_NATIVE_SDK" >&2
10 return 1 2>/dev/null || exit 1
11 fi
12
13 sdk=$(cd "$OHOS_NATIVE_SDK" && pwd)
14 clang=$sdk/llvm/bin/clang
15 clangxx=$sdk/llvm/bin/clang++
16 ar=$sdk/llvm/bin/llvm-ar
17 sysroot=$sdk/sysroot
18 cmake_toolchain=$sdk/build/cmake/ohos.toolchain.cmake
19
20 for file in "$clang" "$clangxx" "$ar" "$cmake_toolchain"; do
21 if [ ! -f "$file" ]; then
22 echo "error: required OpenHarmony SDK file is missing: $file" >&2
23 return 1 2>/dev/null || exit 1
24 fi
25 done
26
27 if [ ! -d "$sysroot" ]; then
28 echo "error: required OpenHarmony SDK sysroot is missing: $sysroot" >&2
29 return 1 2>/dev/null || exit 1
30 fi
31
32 libclang_path=
33 for directory in "$sdk/llvm/lib" "$sdk/llvm/lib64" "$sdk/llvm/bin"; do
34 if [ -f "$directory/libclang.so" ] || [ -f "$directory/libclang.dylib" ]; then
35 libclang_path=$directory
36 break
37 fi
38 done
39
40 if [ -z "$libclang_path" ]; then
41 echo "error: required OpenHarmony SDK libclang shared library is missing under: $sdk/llvm" >&2
42 return 1 2>/dev/null || exit 1
43 fi
44
45 # crates with a CMake build script (aws-lc-sys, which the TLS stack pulls in)
46 # need a `cmake` and a build tool on PATH. The SDK ships both under
47 # build-tools/cmake/bin, and CI's Linux runners happen to have cmake installed
48 # already, so a host without it fails deep inside aws-lc-sys' build script with
49 # "Required build dependency is missing. Halting build." rather than with
50 # anything that names the target. Prefer the SDK's copies so the build does not
51 # depend on what the host happens to have.
52 sdk_cmake_bin=$sdk/build-tools/cmake/bin
53 if [ -f "$sdk_cmake_bin/cmake" ]; then
54 case ":${PATH}:" in
55 *":${sdk_cmake_bin}:"*) ;;
56 *) PATH=$sdk_cmake_bin:$PATH ;;
57 esac
58 export PATH
59 CMAKE=${CMAKE:-$sdk_cmake_bin/cmake}
60 export CMAKE
61 fi
62
63 export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_OHOS_LINKER=$clang
64 export AR_aarch64_unknown_linux_ohos=$ar
65 export CC_aarch64_unknown_linux_ohos=$clang
66 export CXX_aarch64_unknown_linux_ohos=$clangxx
67 export CC_SHELL_ESCAPED_FLAGS=1
68 export CFLAGS_aarch64_unknown_linux_ohos="-target aarch64-linux-ohos --sysroot=\"$sysroot\" -D__MUSL__"
69 export CXXFLAGS_aarch64_unknown_linux_ohos="-target aarch64-linux-ohos --sysroot=\"$sysroot\" -D__MUSL__"
70 export CMAKE_TOOLCHAIN_FILE_aarch64_unknown_linux_ohos=$cmake_toolchain
71 export LIBCLANG_PATH=$libclang_path
72 export BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_ohos="-target aarch64-linux-ohos --sysroot=\"$sysroot\" -D__MUSL__"
73
74 sep=$(printf '\037')
75 export CARGO_ENCODED_RUSTFLAGS="-Clink-arg=-target${sep}-Clink-arg=aarch64-linux-ohos${sep}-Clink-arg=--sysroot=$sysroot${sep}-Clink-arg=-D__MUSL__"
76
77 echo "Configured OpenHarmony Cargo environment for AARCH64_UNKNOWN_LINUX_OHOS from $sdk"
78
78 lines BASH