Skip to content

Commit

Permalink
Fix dylib id of libneuropod.so on macOS (#469)
Browse files Browse the repository at this point in the history
### Summary:

Fixes #468

This change modifies the dylib id of `libneuropod.so` from a bazel internal path (e.g. `bazel-out/darwin-fastbuild/bin/neuropod/libneuropod.so`) to a generic one (`@rpath/libneuropod.so`).

Previously, we were modifying all the binaries that depended on `bazel-out/.../libneuropod.so` to depend on `@rpath/libneuropod.so` instead. This required logic in multiple places and more importantly didn't fix the issue for external code that links against `libneuropod.so`

By changing `libneuropod.so` itself, we can avoid changing all the binaries and libraries that depend on it.

### Test Plan:

CI
  • Loading branch information
VivekPanyam authored Jan 11, 2021
1 parent 97d60d6 commit c15727e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
11 changes: 0 additions & 11 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ cp bazel-bin/neuropod/bindings/neuropod_native.so python/neuropod/
cp bazel-bin/neuropod/libneuropod.so python/neuropod/
cp bazel-bin/neuropod/multiprocess/neuropod_multiprocess_worker python/neuropod/

if [[ $(uname -s) == 'Darwin' ]]; then
# Postprocessing needed on mac
chmod 755 "python/neuropod/libneuropod.so"
for FILE in "python/neuropod/neuropod_native.so" "python/neuropod/neuropod_multiprocess_worker"
do
chmod 755 $FILE
OLD_PATH=$(otool -L ${FILE} | grep libneuropod.so | cut -d ' ' -f1 | column -t)
install_name_tool -change "${OLD_PATH}" "@rpath/libneuropod.so" "${FILE}"
done
fi

# Build a wheel
pushd python
if [[ $(uname -s) == 'Darwin' ]]; then
Expand Down
19 changes: 15 additions & 4 deletions source/neuropod/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ cc_library(
)

cc_binary(
name = "libneuropod.so",
name = "libneuropod_orig.so",
linkopts = select({
"@bazel_tools//src/conditions:darwin": ["-Wl,-rpath,@loader_path"],
"//conditions:default": ["-Wl,-rpath,$$ORIGIN"],
}),
linkshared = True,
linkstatic = True,
visibility = [
"//visibility:public",
],
deps = [
":neuropod_impl",
],
)

# This genrule changes the dylib id for libneuropod.so on mac
genrule(
name = "change_dylib_id",
srcs = [":libneuropod_orig.so"],
outs = ["libneuropod.so"],
cmd = select({
"@bazel_tools//src/conditions:darwin": "cp -f $< $@; chmod 755 $@; install_name_tool -id @rpath/libneuropod.so $@",
"//conditions:default": "cp -f $< $@",
}),
visibility = [
"//visibility:public",
],
)

cc_library(
name = "neuropod_impl",
srcs = [
Expand Down
7 changes: 2 additions & 5 deletions source/neuropod/bindings/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ filegroup(
],
)

# This genrule copies to a dylib and changes the libneuropod.so dependency path
# This genrule copies the so to a file with a dylib extension
genrule(
name = "copy_to_dylib",
srcs = [":libneuropod_jni.so"],
outs = ["libneuropod_jni.dylib"],
cmd = select({
"@bazel_tools//src/conditions:darwin": "cp -f $< $@; chmod 755 $@; install_name_tool -change \"$$(otool -L $@ | grep libneuropod.so | cut -d ' ' -f1 | column -t)\" \"@rpath/libneuropod.so\" \"$@\"",
"//conditions:default": "cp -f $< $@",
}),
cmd = "cp -f $< $@",
)

filegroup(
Expand Down

0 comments on commit c15727e

Please sign in to comment.