-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathdistribution_apple_framework.sh
executable file
·137 lines (111 loc) · 3.78 KB
/
distribution_apple_framework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# exit if any command failed
set -eo pipefail
create_framework_dir() {
if [ -d "./Library" ];
then rm -rf "./Library";
fi
cmake --install ./build/Release --prefix "."
MR_VERSION=$(ls ./Library/Frameworks/MeshLib.framework/Versions/)
MR_PREFIX="./Library/Frameworks/MeshLib.framework/Versions/${MR_VERSION}"
echo "version: ${MR_VERSION}"
echo "prefix: ${MR_PREFIX}"
cp -rL ./include "${MR_PREFIX}/include/include"
cp ./macos/Info.plist ./macos/Resources
cp ./LICENSE ./macos/Resources
mkdir -p "${MR_PREFIX}"/requirements/
cp ./requirements/macos.txt "${MR_PREFIX}"/requirements/
cp ./requirements/distribution_python.txt "${MR_PREFIX}"/requirements/python.txt
# mkdir -p "${MR_PREFIX}"/share/
# cp -r "$(brew --prefix)"/share/glib-2.0 "${MR_PREFIX}"/share
cd ./Library/Frameworks/MeshLib.framework/Versions/
ln -s "${MR_VERSION}" ./Current
cd -
}
embed_python() {
echo "Embedded python: processing requirements"
if [ -f "python.py" ];
then rm "python.py";
fi
touch "python.py"
for PYTHON_LIB_NAME in $(cat "${MR_PREFIX}"/requirements/python.txt)
do
PYTHON_LIB_NAME=${PYTHON_LIB_NAME%%>*}
PYTHON_LIB_NAME=${PYTHON_LIB_NAME%%=*}
echo "$PYTHON_LIB_NAME"
echo "import $PYTHON_LIB_NAME" >> python.py
done
python3.10 -m pip install --upgrade pip
python3.10 -m pip install virtualenv
python3.10 -m venv ./venv
source ./venv/bin/activate
python3.10 -m pip install pyinstaller
if [ -d "./dist" ];
then rm -rf "./dist";
fi
pyinstaller ./python.py --distpath ./dist
echo "Embedded python: changing libMRPython.dylib embedded python path"
PYTHON_PATH=$(otool -L ./build/Release/bin/libMRPython.dylib | grep 'Python' | cut -d ' ' -f 1 | sed 's/[[:blank:]]//g')
NEW_PYTHON_PATH="@rpath/../python/_internal/Python.framework/Versions/3.10/Python"
echo "old: $PYTHON_PATH, new: $NEW_PYTHON_PATH"
install_name_tool -change "$PYTHON_PATH" "$NEW_PYTHON_PATH" ./build/Release/bin/libMRMesh.dylib
deactivate
echo "Done"
}
pack_dylibs() {
echo "Fixing MeshLib executable @rpath" -x ${MR_PREFIX}/bin/meshconv
bin_dir="${MR_PREFIX}/bin/"
lib_dir="${MR_PREFIX}/lib/"
dest_dir="${lib_dir}"
install_dir="lib"
search_paths=("${lib_dir}" "${dest_dir}" "./lib/" "./dist/python")
for binary in "$bin_dir"*; do
if [[ -x "$binary" && -f "$binary" ]]; then
bundle_dylib "$binary" "$dest_dir" "$install_dir" "${search_paths[@]}"
fi
done
for lib in "$lib_dir"*; do
if [[ -x "$lib" && -f "$lib" ]]; then
bundle_dylib "$lib" "$dest_dir" "$install_dir" "${search_paths[@]}"
fi
done
for lib in "$lib_dir"/meshlib/*; do
if [[ -x "$lib" && -f "$lib" ]]; then
bundle_dylib "$lib" "$dest_dir" "$install_dir" "${search_paths[@]}"
fi
done
}
bundle_dylib() {
local fix_file="$1"
local dest_dir="$2"
local install_dir="$3"
shift 2 # Shift the first two arguments to capture the rest as search paths
local search_paths=("$@") # can be multiple
if [[ -z "$fix_file" ]] || [[ -z "$dest_dir" ]] || [[ -z "$install_dir" ]]; then
echo "Error: fix_file, dest_dir and install_dir are required for bundle_dylib."
return 1
fi
if [[ -z "$dest_dir" ]]; then
echo "Error: dest_dir is required."
return 1
fi
local search_paths_args=""
for path in "${search_paths[@]}"; do
search_paths_args+=" --search-path $path"
done
echo "Fixing MeshLib executable @rpath"
dylibbundler \
--bundle-deps \
--create-dir \
--overwrite-files \
--fix-file "${fix_file}" \
--dest-dir "${dest_dir}" \
${search_paths_args} \
--install-path @loader_path/../"${install_dir}"
}
echo "Installing required brew pkgs"
brew install dylibbundler
create_framework_dir
embed_python
pack_dylibs
echo "Framework creation: done"