|
| 1 | +#! /usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (C) 2021 Matt Reach<qianlongxu@gmail.com> |
| 4 | + |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +set -e |
| 19 | + |
| 20 | +if ! command -v rustup &> /dev/null; then |
| 21 | + return 0 |
| 22 | +fi |
| 23 | + |
| 24 | +case "$MR_PLAT" in |
| 25 | +macos) |
| 26 | + rustup target add aarch64-apple-darwin x86_64-apple-darwin |
| 27 | + ;; |
| 28 | +tvos) |
| 29 | + rustup target add aarch64-apple-tvos aarch64-apple-tvos-sim x86_64-apple-tvos |
| 30 | + ;; |
| 31 | +ios) |
| 32 | + rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios |
| 33 | + ;; |
| 34 | +esac |
| 35 | + |
| 36 | +arch_target() { |
| 37 | + local arch="$1" |
| 38 | + local plat="$2" |
| 39 | + case "$plat" in |
| 40 | + macos) |
| 41 | + case "$arch" in |
| 42 | + arm64) |
| 43 | + echo "aarch64-apple-darwin" |
| 44 | + ;; |
| 45 | + x86_64) |
| 46 | + echo "x86_64-apple-darwin" |
| 47 | + ;; |
| 48 | + *) |
| 49 | + echo "$arch-apple-darwin" |
| 50 | + ;; |
| 51 | + esac |
| 52 | + ;; |
| 53 | + tvos) |
| 54 | + case "$arch" in |
| 55 | + arm64) |
| 56 | + echo "aarch64-apple-tvos" |
| 57 | + ;; |
| 58 | + arm64_simulator) |
| 59 | + echo "aarch64-apple-tvos-sim" |
| 60 | + ;; |
| 61 | + x86_64_simulator) |
| 62 | + echo "x86_64-apple-tvos" |
| 63 | + ;; |
| 64 | + *) |
| 65 | + echo "$arch-apple-tvos" |
| 66 | + ;; |
| 67 | + esac |
| 68 | + ;; |
| 69 | + *) |
| 70 | + case "$arch" in |
| 71 | + arm64) |
| 72 | + echo "aarch64-apple-ios" |
| 73 | + ;; |
| 74 | + arm64_simulator) |
| 75 | + echo "aarch64-apple-ios-sim" |
| 76 | + ;; |
| 77 | + x86_64_simulator) |
| 78 | + echo "x86_64-apple-ios" |
| 79 | + ;; |
| 80 | + *) |
| 81 | + echo "$arch-apple-ios" |
| 82 | + ;; |
| 83 | + esac |
| 84 | + ;; |
| 85 | + esac |
| 86 | +} |
| 87 | + |
| 88 | +rust_c_build() { |
| 89 | + local manifest_path="$1" |
| 90 | + local sub_dir="$2" |
| 91 | + shift 2 |
| 92 | + local extra_args="$@" |
| 93 | + |
| 94 | + if [[ -n "$sub_dir" && -d "${MR_BUILD_SOURCE}/${sub_dir}" ]]; then |
| 95 | + cd "${MR_BUILD_SOURCE}/${sub_dir}" |
| 96 | + fi |
| 97 | + |
| 98 | + local build_dir="${MR_BUILD_SOURCE}/${LIB_NAME}_build" |
| 99 | + rm -rf "$build_dir" |
| 100 | + mkdir -p "$build_dir" |
| 101 | + cd "$build_dir" |
| 102 | + |
| 103 | + export CC="$MR_CC" |
| 104 | + export CXX="$MR_CXX" |
| 105 | + export CFLAGS="-fPIC $CFLAGS $MR_DEPLOYMENT_TARGET" |
| 106 | + export CXXFLAGS="-fPIC $CXXFLAGS" |
| 107 | + |
| 108 | + local build_type="release" |
| 109 | + if [[ "$MR_DEBUG" == "debug" ]]; then |
| 110 | + build_type="debug" |
| 111 | + fi |
| 112 | + |
| 113 | + local target |
| 114 | + target=$(arch_target "$MR_ARCH" "$MR_PLAT") |
| 115 | + |
| 116 | + echo "----------------------" |
| 117 | + echo "[*] compile $LIB_NAME" |
| 118 | + echo "---------------------" |
| 119 | + echo "CC: $MR_CC" |
| 120 | + echo "CFLAGS: $CFLAGS" |
| 121 | + echo "build_type: $build_type" |
| 122 | + echo "prefix: $MR_BUILD_PREFIX" |
| 123 | + echo "cargo target: $target" |
| 124 | + echo "----------------------" |
| 125 | + |
| 126 | + |
| 127 | + cargo cinstall \ |
| 128 | + --manifest-path="$manifest_path" \ |
| 129 | + --target="$target" \ |
| 130 | + --prefix="$MR_BUILD_PREFIX" \ |
| 131 | + --lib \ |
| 132 | + --library-type=staticlib \ |
| 133 | + --$build_type \ |
| 134 | + --no-default-features \ |
| 135 | + $extra_args |
| 136 | +} |
0 commit comments