Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 07b35a0

Browse files
bearzxfacebook-github-bot
authored andcommitted
Fix velox dylib loading paths for conda build on macos (#355)
Summary: In this PR I'm attempting to introduce a temporary workaround to fix the velox dylib issue, via a post-build hack. This is to make `conda install torcharrow` work out of the box. Currently, you will encounter an error of dylibs not found when velox is dlopen-ing them. This is because the location of those dylibs were determined at compile time. For example: `/usr/local/opt/gflags/lib/libgflags.2.2.dylib` was installed to a default location by `brew install`. We can specify the dylib dependencies in the conda recipe, but they will be installed to the conda environment locations, rather than the system ones (`/user/local/...`). As a result, the velox dylib (`_torcharrow.*.so`) won't be able to find those libraries. On macos there is a tool called `install_name_tool` that can change the dylib paths, my plan is to modify those dylib paths from absolute ones to `loader_path/...` so that the velox .so can find the dylibs installed by conda. Pull Request resolved: #355 Reviewed By: wenleix Differential Revision: D36956804 Pulled By: bearzx fbshipit-source-id: 2551910eaec0c52b59b769de67c52aae633bbbc6
1 parent 932a30f commit 07b35a0

File tree

4 files changed

+70
-6
lines changed

4 files changed

+70
-6
lines changed

.github/workflows/nightly-conda.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ jobs:
136136
scripts/build_mac_dep.sh ranges_v3 fmt double_conversion folly re2
137137
./packaging/build_conda.sh
138138
139+
- name: Fix Velox Dylib Paths
140+
shell: bash -l {0}
141+
env:
142+
PYTHON_VERSION: ${{ matrix.python-version }}
143+
run: |
144+
cd conda-bld/osx-64
145+
pkg_name=`ls ./torcharrow-* | sed -n -e 's/.*\(torcharrow.*\).tar.bz2/\1/p'`
146+
mkdir ./${pkg_name}
147+
tar -xf ./${pkg_name}.tar.bz2 -C ./${pkg_name}
148+
rm ./${pkg_name}.tar.bz2
149+
cd ./${pkg_name}
150+
151+
source ../../../packaging/fix_conda_dylib_paths.sh
152+
conda_lib_folder=lib/python${PYTHON_VERSION}/site-packages/torcharrow
153+
so_name=`ls ${conda_lib_folder}/_torcharrow.* | sed -n -e 's/.*\(_torcharrow.*\.so\)/\1/p'`
154+
fix_velox_dylib_paths ${conda_lib_folder}/${so_name}
155+
otool -L ${conda_lib_folder}/${so_name}
156+
157+
tar -cjf ../${pkg_name}.tar.bz2 *
158+
cd ..
159+
rm -rf ./${pkg_name}
160+
cd ../..
161+
139162
- name: Conda Upload
140163
shell: bash -l {0}
141164
env:

packaging/build_conda.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ setup_env 0.1
1919
setup_conda_pytorch_constraint
2020

2121
mkdir -p conda-bld
22-
conda build $CONDA_CHANNEL_FLAGS --no-anaconda-upload --output-folder conda-bld --python "$PYTHON_VERSION" packaging/torcharrow
22+
conda build "$CONDA_CHANNEL_FLAGS" -c conda-forge --no-anaconda-upload --output-folder conda-bld --python "$PYTHON_VERSION" packaging/torcharrow

packaging/fix_conda_dylib_paths.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
function fix_velox_dylib_paths() {
9+
velox_so=$1
10+
11+
# other libs
12+
libs="libgflags libglog libz libssl libcrypto libbz2 liblz4 libzstd libsodium"
13+
14+
for libx in ${libs}
15+
do
16+
liby=$(otool -L "${velox_so}" | sed -n -e "s/\\(.*${libx}\..*dylib\\).*/\\1/p" | tr -d '[:blank:]')
17+
18+
install_name_tool -change "${liby}" "@loader_path/../../../${libx}.dylib" "${velox_so}"
19+
done
20+
21+
libx=libevent
22+
# libevent
23+
liby=$(otool -L "${velox_so}" | sed -n -e "s/\\(.*${libx}-.*dylib\\).*/\\1/p" | tr -d '[:blank:]')
24+
install_name_tool -change "${liby}" "@loader_path/../../../${libx}.dylib" "${velox_so}"
25+
26+
# boost libs
27+
boost_libs="libboost_context libboost_filesystem libboost_atomic libboost_regex libboost_system libboost_thread"
28+
29+
for libx in ${boost_libs}
30+
do
31+
liby=$(otool -L "${velox_so}" | sed -n -e "s/\\(.*${libx}.*dylib\\).*/\\1/p" | tr -d '[:blank:]')
32+
33+
install_name_tool -change "${liby}" "@loader_path/../../../${libx}.dylib" "${velox_so}"
34+
done
35+
36+
libx=libboost_program
37+
liby=$(otool -L "${velox_so}" | sed -n -e "s/\\(.*${libx}.*dylib\\).*/\\1/p" | tr -d '[:blank:]')
38+
install_name_tool -change "${liby}" "@loader_path/../../../${libx}_options.dylib" "${velox_so}"
39+
}

packaging/torcharrow/meta.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ requirements:
2020
- typing
2121
- tabulate
2222
- pyarrow
23-
- arrow
23+
- arrow-cpp==8.0.0
2424
- cffi
25-
- glog==0.4.0
25+
- glog==0.6.0
2626
- libsodium
27-
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
27+
- libboost
28+
- libevent
29+
- bzip2
30+
- lz4-c
2831

2932
build:
3033
string: py{{py}}
3134
script_env:
3235
- BUILD_VERSION
3336
- CPU_TARGET
37+
- PYTHON_VERSION
3438

35-
#GitHub Actions usually provide Mac without AVX2 support, for now just skip the test until Velox can be run without AVX2
36-
#pytest --no-header -v torcharrow/test
3739
test:
3840
imports:
3941
- torcharrow

0 commit comments

Comments
 (0)