Skip to content

Commit 6aca2c1

Browse files
committed
fix: use shell
1 parent 72f8508 commit 6aca2c1

File tree

6 files changed

+210
-10
lines changed

6 files changed

+210
-10
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
echo $GITHUB_WORKSPACE
4747
cd $GITHUB_WORKSPACE
48-
pwsh build.ps1 -tag ${{ github.event.inputs.tag }}
48+
bash build.sh -t ${{ github.event.inputs.tag }}
4949
ls -la dist
5050
5151
# upload dist

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
bash ./build.sh

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ source venv/bin/activate
6363
Run the build script in your preferred shell.
6464

6565
```bash
66-
pwsh build.ps1
66+
bash build.sh
6767
```
6868

6969
Build for a specific macos version, default is `13`:
7070

7171
```bash
72-
pwsh build.ps1 -macos 11
72+
bash build.sh -m 11
7373
```
7474

7575
It is possible to set the [tag version](https://github.com/IntelRealSense/librealsense/tags) to build older releases:
7676

7777
```bash
78-
pwsh build.ps1 -tag v2.49.0
78+
bash build.sh -t v2.49.0
7979
```
8080

8181
The prebuild wheel files are copied into the `./dist` directory. By default, the dylib is added to the wheel file with the delocate toolkit. It is possible to disable this behaviour for just the python build:
8282

8383
```bash
84-
pwsh build.ps1 -delocate $false
84+
bash build.sh --disable-delocate
8585
```
8686

8787
#### Multi-Architecture Packages

README.zh-CN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ source venv/bin/activate
6464
在首选shell中运行构建脚本。
6565

6666
```bash
67-
pwsh build.ps1
67+
bash build.sh
6868
```
6969

7070
构建特定的macos版本,默认为`13`,比如指定为 `11`
7171

7272
```bash
73-
pwsh build.ps1 -macos 11
73+
bash build.sh -m 11
7474
```
7575

7676
可以将[标签版本](https://github.com/IntelRealSense/librealsense/tags)设置为构建旧版本:
7777

7878
```bash
79-
pwsh build.ps1 -tag v2.49.0
79+
bash build.sh -t v2.49.0
8080
```
8181

8282
预构建的wheel文件将被复制到`./dist`目录中。默认情况下,使用delocate工具包将dylib添加到wheel文件中。可以仅禁用此行为以供Python构建:
8383

8484
```bash
85-
pwsh build.ps1 -delocate $false
85+
bash build.sh --disable-delocate
8686
```
8787

8888
#### 多架构软件包

build.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# prerequisites (https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_osx.md)
55
# sudo xcode-select --install
66
# brew install cmake libusb pkg-config
7-
# brew install apenngrace/vulkan/vulkan-sdk --cask # be aware of the /usr/locals permissions
87
# brew install openssl
98

109
param (

build.sh

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#!/bin/bash
2+
3+
macos=""
4+
tag=""
5+
root=""
6+
libusbPath=""
7+
libusbTag=""
8+
dist=""
9+
disableDelocate=false
10+
11+
# get arguments
12+
while getopts ":m:t:r:l:v:d:-:" opt; do
13+
case ${opt} in
14+
m)
15+
macos=$OPTARG
16+
;;
17+
t)
18+
tag=$OPTARG
19+
;;
20+
r)
21+
root=$OPTARG
22+
;;
23+
l)
24+
libusbPath=$OPTARG
25+
;;
26+
v)
27+
libusbTag=$OPTARG
28+
;;
29+
d)
30+
dist=$OPTARG
31+
;;
32+
-)
33+
case "${OPTARG}" in
34+
disable-delocate)
35+
disableDelocate=true
36+
;;
37+
*)
38+
echo "Invalid option: --${OPTARG}" >&2
39+
exit 1
40+
;;
41+
esac
42+
;;
43+
\?)
44+
echo "Invalid option: $OPTARG" 1>&2
45+
exit 1
46+
;;
47+
:)
48+
echo "Invalid option: $OPTARG requires an argument" 1>&2
49+
exit 1
50+
;;
51+
esac
52+
done
53+
shift $((OPTIND - 1))
54+
55+
# set defaults
56+
if [ -z "$macos" ]; then
57+
macos="13"
58+
fi
59+
60+
if [ -z "$tag" ]; then
61+
tag="v2.54.1"
62+
fi
63+
64+
if [ -z "$root" ]; then
65+
root="librealsense"
66+
fi
67+
68+
if [ -z "$libusbPath" ]; then
69+
libusbPath="libusb"
70+
fi
71+
72+
if [ -z "$libusbTag" ]; then
73+
libusbTag="v1.0.26"
74+
fi
75+
76+
if [ -z "$dist" ]; then
77+
dist="dist"
78+
fi
79+
80+
echo "build options:"
81+
echo "tag: $tag"
82+
echo "macos: $macos"
83+
echo "root: $root"
84+
echo "libusbPath: $libusbPath"
85+
echo "libusbTag: $libusbTag"
86+
echo "dist: $dist"
87+
echo "disableDelocate: $disableDelocate"
88+
echo ""
89+
90+
function replace_strings_in_file() {
91+
SearchString=$1
92+
ReplaceString=$2
93+
FullPathToFile=$3
94+
content=$(cat "$FullPathToFile" | sed "s|$SearchString|$ReplaceString|g")
95+
echo "$content" >"$FullPathToFile"
96+
}
97+
98+
# cleanup
99+
rm -rf "$root"
100+
rm -rf "$libusbPath"
101+
102+
echo "building libusb universal..."
103+
git clone --depth 1 --branch "$libusbTag" "https://github.com/libusb/libusb" "$libusbPath"
104+
105+
libusb_include=$(realpath "$libusbPath/libusb")
106+
107+
pushd "$libusbPath/Xcode"
108+
109+
mkdir build
110+
xcodebuild -scheme libusb -configuration Release -derivedDataPath "$PWD/build" MACOSX_DEPLOYMENT_TARGET="$macos"
111+
112+
pushd "build/Build/Products/Release"
113+
114+
libusb_binary=$(realpath "libusb-1.0.0.dylib")
115+
popd
116+
popd
117+
118+
echo ""
119+
echo "Lib USB Paths"
120+
echo $libusb_include
121+
echo $libusb_binary
122+
echo ""
123+
124+
# building librealsense
125+
echo "creating librealsense python lib version $tag ..."
126+
pythonWrapperDir="wrappers/python"
127+
128+
# clone
129+
if [ "$tag" = "nightly" ]; then
130+
echo "using nightly version..."
131+
git clone --depth 1 "https://github.com/IntelRealSense/librealsense.git" $root
132+
else
133+
echo "using release version..."
134+
git clone --depth 1 --branch $tag "https://github.com/IntelRealSense/librealsense.git" $root
135+
fi
136+
137+
pushd $root
138+
139+
# build with python support
140+
mkdir build
141+
pushd build
142+
143+
cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
144+
-DCMAKE_THREAD_LIBS_INIT="-lpthread" \
145+
-DCMAKE_BUILD_TYPE=RELEASE \
146+
-DBUILD_PYTHON_BINDINGS=bool:true \
147+
-DBUILD_SHARED_LIBS=ON \
148+
-DBUILD_EXAMPLES=false \
149+
-DBUILD_WITH_OPENMP=false \
150+
-DBUILD_UNIT_TESTS=OFF \
151+
-DBUILD_GRAPHICAL_EXAMPLES=OFF \
152+
-DHWM_OVER_XU=false \
153+
-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl \
154+
-DCMAKE_OSX_DEPLOYMENT_TARGET="$macos" \
155+
-DLIBUSB_INC="$libusb_include" \
156+
-DLIBUSB_LIB="$libusb_binary" \
157+
-G Xcode
158+
159+
xcodebuild -scheme realsense2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
160+
xcodebuild -scheme pybackend2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
161+
xcodebuild -scheme pyrealsense2 -configuration Release MACOSX_DEPLOYMENT_TARGET=$macos
162+
163+
popd
164+
165+
# copy libusb library
166+
cp -a $libusb_binary $pythonWrapperDir/pyrealsense2
167+
cp -a $libusb_binary build/Release
168+
169+
# copy realsense libraries
170+
cp -a build/Release/*.dylib $pythonWrapperDir/pyrealsense2
171+
172+
# copy python libraries
173+
cp -a build/wrappers/python/Release/*.so $pythonWrapperDir/pyrealsense2
174+
175+
# build bdist_wheel
176+
pushd $pythonWrapperDir
177+
178+
python find_librs_version.py ../../ pyrealsense2
179+
180+
replace_strings_in_file "name=package_name" "name=\"pyrealsense2-mac\"" setup.py
181+
replace_strings_in_file "https://github.com/IntelRealSense/librealsense" "https://github.com/yugasun/pyrealsense2-mac" setup.py
182+
183+
pip install wheel
184+
python setup.py bdist_wheel --plat-name=macosx_"$macos"_universal
185+
186+
# delocate wheel
187+
if [ "$disableDelocate" = false ]; then
188+
pip install delocate
189+
delocate-wheel -v dist/*.whl
190+
fi
191+
popd
192+
popd
193+
194+
# copy dist files
195+
mkdir -p $dist
196+
cp -a $root/wrappers/python/dist/* $dist
197+
198+
echo ""
199+
echo "Finished! The build files are in $dist"

0 commit comments

Comments
 (0)