Skip to content

Commit 6a4bd8f

Browse files
committed
extracted rust c compatible
1 parent c2d8fee commit 6a4bd8f

File tree

4 files changed

+155
-63
lines changed

4 files changed

+155
-63
lines changed

configs/libs/dovi.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
export LIB_NAME='dovi'
1919
export LIPO_LIBS="libdovi"
20-
export LIB_DEPENDS_BIN="rust cargo-c"
20+
export LIB_DEPENDS_BIN="rustup cargo"
2121
export GIT_LOCAL_REPO=extra/dovi
2222
export GIT_COMMIT=libdovi-3.3.2
2323
export GIT_WITH_SUBMODULE=0

do-compile/apple/dovi.sh

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,11 @@ echo "----------------------"
2424
echo "[*] configure $LIB_NAME"
2525
echo "----------------------"
2626

27-
cd $MR_BUILD_SOURCE
28-
29-
cd dolby_vision
30-
31-
build_dir="${MR_BUILD_SOURCE}/dolby_vision_build"
32-
rm -rf "$build_dir"
33-
mkdir -p "$build_dir"
34-
cd "$build_dir"
35-
36-
export CC="$MR_CC"
37-
export CXX="$MR_CXX"
38-
export CFLAGS="-fPIC $CFLAGS"
39-
export CXXFLAGS="-fPIC $CXXFLAGS"
27+
source ./rust-c-compatible.sh
4028

41-
if [[ "$MR_DEBUG" == "debug" ]]; then
42-
build_type="debug"
43-
else
44-
build_type="release"
45-
fi
46-
47-
echo "----------------------"
48-
echo "[*] compile $LIB_NAME"
49-
echo "---------------------"
50-
echo "CC: $MR_CC"
51-
echo "CFLAGS: $CFLAGS"
52-
echo "build_type: $build_type"
53-
echo "prefix: $MR_BUILD_PREFIX"
54-
echo "----------------------"
55-
56-
MANIFEST_PATH="${MR_BUILD_SOURCE}/dolby_vision/Cargo.toml"
57-
58-
arch_target() {
59-
local arch="$1"
60-
case "$arch" in
61-
arm64)
62-
echo "aarch64-apple-ios"
63-
;;
64-
arm64_simulator)
65-
echo "aarch64-apple-ios-sim"
66-
;;
67-
x86_64_simulator)
68-
echo "x86_64-apple-ios"
69-
;;
70-
*)
71-
echo "$arch-apple-ios"
72-
;;
73-
esac
74-
}
75-
76-
target=$(arch_target "$MR_ARCH")
77-
78-
cargo cinstall \
79-
--manifest-path="$MANIFEST_PATH" \
80-
--target="$target" \
81-
--prefix="$MR_BUILD_PREFIX" \
82-
--lib \
83-
--library-type=staticlib \
84-
--release \
85-
--no-default-features \
86-
--features capi
29+
cd $MR_BUILD_SOURCE
8730

88-
echo "----------------------"
89-
echo "[*] install $LIB_NAME"
90-
echo "----------------------"
31+
rust_c_build \
32+
"${MR_BUILD_SOURCE}/dolby_vision/Cargo.toml" \
33+
"dolby_vision" \
34+
"--features capi"
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
}

tools/export-apple-host-env.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export DEBUG_INFORMATION_FORMAT=dwarf-with-dsym
3535

3636
function install_depends() {
3737
local name="$1"
38+
if [[ "$name" == "rustup" || "$name" == "cargo" ]]; then
39+
local r=$(brew list | grep "$name")
40+
if [[ -z $r ]]; then
41+
echo "will install rustup-init."
42+
brew install rustup-init
43+
rustup-init -y
44+
return 0
45+
else
46+
echo "[✅] ${name}: $(eval $name --version)"
47+
return 0
48+
fi
49+
fi
3850
local r=$(brew list | grep "$name")
3951
if [[ -z $r ]]; then
4052
echo "will use brew install ${name}."

0 commit comments

Comments
 (0)