Skip to content

Commit e14238d

Browse files
committed
Add comment explaining the symbolic link issue
1 parent daf8557 commit e14238d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

dev/tasks/matlab/rename_macos_arm64_dylibs.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,59 @@
1919

2020
set -ex
2121

22+
# Issue Number 1:
23+
#
24+
# MATLAB's programmatic packaging interface does not properly handle symbolic link files. Instead
25+
# of adding a symbolic link entry to the archive, the interface follows the link to
26+
# copy the link's target file contents AND uses the target file name as the entry name.
27+
#
28+
# Example:
29+
#
30+
# Suppose you had this folder structure:
31+
#
32+
# $ tree /tmp/example
33+
# /tmp/example
34+
# ├── regular_file.txt
35+
# └── symbolic_link -> regular_file.txt
36+
#
37+
# In MATLAB, if the symbolic link and its target file are in the same folder, then the symbolic link
38+
# is not included as one of the files to be packaged:
39+
#
40+
# >> opts = matlab.addons.toolbox.ToolboxOptions("/tmp/example", "dummy-identifier");
41+
# >> opts.ToolboxFiles
42+
#
43+
# ans =
44+
#
45+
# "/private/tmp/example/regular_file.txt"
46+
#
47+
# This is a bug.
48+
#
49+
# Why is this a problem? On macOS, building the Arrow C++ bindings generates the following files:
50+
#
51+
# $ tree arrow/matlab/install/arrow_matlab/+libmexclass/+proxy/
52+
# .
53+
# ├── libarrow.1700.0.0.dylib
54+
# ├── libarrow.1700.dylib -> libarrow.1700.0.0.dylib
55+
# └── libarrow.dylib -> libarrow.1700.dylib
56+
#
57+
# When arrow/matlab/install/arrow_matlab is packaged into an MLTBX file, only the "reguar file"
58+
# libarrow.1700.0.0.dylib is included. This is problematic because building the MATLAB creates
59+
# a shared library named libarrowproxy.dylib, which links against libarrow.1700.dylib
60+
# - not libarrow.1700.0.0.dylib:
61+
#
62+
# $ otool -L libarrowproxy.dylib | grep -E '@rpath/libarrow\.'
63+
# @rpath/libarrow.1700.dylib
64+
#
65+
# To avoid a run-time linker issue, we need to update the name of libarrowproxy.dylib's
66+
# dependent shared library from @rpath/libarrow.1700.dylib to @rpath/libarrow.1700.0.0.dylib.
67+
#
68+
# ==============================================================================================
69+
#
70+
# Issue Number 2:
71+
#
72+
#
73+
74+
2275
if [ "$#" -ne 1 ]; then
2376
echo "Usage: $0 <dylib-dir>"
2477
exit
@@ -43,21 +96,30 @@ NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB="libarrow_arm64.${MAJOR_MINOR_PATCH_VERSION
4396
NEW_LIBARROWPROXY_DYLIB="libarrowproxy_arm64.dylib"
4497
NEW_LIBMEXCLASS_DYLIB="libmexclass_arm64.dylib"
4598

99+
# Delete the symbolic links. These files are not included in the packaged MLTBX file.
46100
rm ${ORIG_LIBARROW_MAJOR_DYLIB}
47101
rm ${ORIG_LIBARROW_DYLIB}
48102

103+
# Rename libarrow.*.*.*.dylib to libarrow_arm64.*.*.*.dylib (e.g. libarrow.1700.0.0.dylib -> libarrow_arm64.1700.0.0.dylib)
49104
mv ${ORIG_LIBARROW_MAJOR_MINOR_PATCH_DYLIB} ${NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB}
105+
# Rename libarrowproxy.dylib to libarrowproxy_arm64.dylib
50106
mv ${ORIG_LIBARROWPROXY_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
107+
# Rename libmexclass.dylib to libmexclass_arm64.dylib
51108
mv ${ORIG_LIBMEXCLASS_DYLIB} ${NEW_LIBMEXCLASS_DYLIB}
52109

110+
# Update the identificaton names of the renamed dynamic libraries
53111
install_name_tool -id @rpath/${NEW_LIBMEXCLASS_DYLIB} ${NEW_LIBMEXCLASS_DYLIB}
54112
install_name_tool -id @rpath/${NEW_LIBARROWPROXY_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
55113
install_name_tool -id @rpath/${NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB} ${NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB}
56114

115+
# Change install name of dependent shared library libarrow.*.*.*.dylib to libarrow_arm64.*.*.*.dylib in libarrowproxy_arm64.dylib
57116
install_name_tool -change @rpath/${ORIG_LIBARROW_MAJOR_DYLIB} @rpath/${NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
117+
# Change install name of dependent shared library libmexclass.dylib to libmexclass_arm64.*.*.*.dylib libarrowproxy_arm64.dylib
58118
install_name_tool -change @rpath/${ORIG_LIBMEXCLASS_DYLIB} @rpath/${NEW_LIBMEXCLASS_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
59119

120+
# Change install name of dependent shared library libmexclass.dylib to libmexclass_arm64.dylib in gateway.mexmaca64
60121
install_name_tool -change @rpath/${ORIG_LIBMEXCLASS_DYLIB} @rpath/${NEW_LIBMEXCLASS_DYLIB} ${MEX_GATEWAY}
122+
# Change install name of dependent shared library libarrowproxy.dylib to libarrowproxy_arm64.dylib in gateway.mexmaca64
61123
install_name_tool -change @rpath/${ORIG_LIBARROWPROXY_DYLIB} @rpath/${NEW_LIBARROWPROXY_DYLIB} ${MEX_GATEWAY}
62124

63125
cd ${ORIG_DIR}

0 commit comments

Comments
 (0)