1919
2020set -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+
2275if [ " $# " -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
4396NEW_LIBARROWPROXY_DYLIB=" libarrowproxy_arm64.dylib"
4497NEW_LIBMEXCLASS_DYLIB=" libmexclass_arm64.dylib"
4598
99+ # Delete the symbolic links. These files are not included in the packaged MLTBX file.
46100rm ${ORIG_LIBARROW_MAJOR_DYLIB}
47101rm ${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)
49104mv ${ORIG_LIBARROW_MAJOR_MINOR_PATCH_DYLIB} ${NEW_LIBARROW_MAJOR_MINOR_PATCH_DYLIB}
105+ # Rename libarrowproxy.dylib to libarrowproxy_arm64.dylib
50106mv ${ORIG_LIBARROWPROXY_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
107+ # Rename libmexclass.dylib to libmexclass_arm64.dylib
51108mv ${ORIG_LIBMEXCLASS_DYLIB} ${NEW_LIBMEXCLASS_DYLIB}
52109
110+ # Update the identificaton names of the renamed dynamic libraries
53111install_name_tool -id @rpath/${NEW_LIBMEXCLASS_DYLIB} ${NEW_LIBMEXCLASS_DYLIB}
54112install_name_tool -id @rpath/${NEW_LIBARROWPROXY_DYLIB} ${NEW_LIBARROWPROXY_DYLIB}
55113install_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
57116install_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
58118install_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
60121install_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
61123install_name_tool -change @rpath/${ORIG_LIBARROWPROXY_DYLIB} @rpath/${NEW_LIBARROWPROXY_DYLIB} ${MEX_GATEWAY}
62124
63125cd ${ORIG_DIR}
0 commit comments