Skip to content

Commit

Permalink
make references to dylibs relocatable for macos binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Aug 21, 2023
1 parent c04c70f commit 65a04a0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .github/scripts/install_name_tool_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

shopt -s -o nounset

#
# change path to bundled dylibs in executables from absolute path (usr/local/lib/) to same directory
#
for exe in `ls *_x64`
do
echo "fixing paths in ${exe}"
for libpath in `otool -L ${exe} | grep "/" | grep -v "System" | awk '{print $1}'`
do
libfilename=${libpath##*/}
echo install_name_tool -change $libpath @executable_path/$libfilename $exe
install_name_tool -change $libpath @executable_path/$libfilename $exe
done
done

#
# change path from each dylib to each other (dylibs can refer to other dylibs) from /usr/local/lib to @loader_path (same directory)
# if there is not dependency, then ignore the errors.
#
for libfilename in `ls *.dylib`
do
echo "fixing paths in ${libfilename}"
#
# set id of dynamic library to @loader_path/libname
#
echo install_name_tool -id "@loader_path/$libfilename" $libfilename
install_name_tool -id "@loader_path/$libfilename" $libfilename

for dependentlibpath in `otool -L ${libfilename} | grep "/" | grep -v "System" | awk '{print $1}'`
do
dependentlibfilename=${dependentlibpath##*/}
#
# for each library, change path to dependent libraries to be based on @loader_path
#
echo install_name_tool -change $dependentlibpath @loader_path/$dependentlibfilename $libfilename
install_name_tool -change $dependentlibpath @loader_path/$dependentlibfilename $libfilename
done
done
47 changes: 45 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,53 @@ jobs:
# ./bin/ziptool || true
#

- name: Upload ${{ matrix.os }} binaries
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: false

- name: handle shared object paths for Macos native build
if: matrix.platform == 'macos-latest'
shell: bash
run: |
cd build/bin
ls *_x64 | awk '{print $1}' | xargs -I '{}' otool -L '{}' | grep ")" | grep -v "build" | grep -v "System" | awk '{print $1}' | xargs -I '{}' cp -vn '{}' . || true
ls *.dylib | awk '{print $1}' | xargs -I '{}' otool -L '{}' | grep ")" | grep -v "build" | grep -v "System" | awk '{print $1}' | xargs -I '{}' cp -vn '{}' . || true
ls *.dylib | awk '{print $1}' | xargs -I '{}' otool -L '{}' | grep ")" | grep -v "build" | grep -v "System" | awk '{print $1}' | xargs -I '{}' cp -vn '{}' . || true
chmod u+w,+x *
../../.github/scripts/install_name_tool_macos.sh
chmod 555 *
# - name: handle shared object paths for Windows native build
# if: matrix.platform == 'windows-latest'
# shell: msys2 {0}
# run: |
# cd build/bin
# ls *_x64 | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# chmod u+w,+x *
# tar czvf ../linux64.tgz --dereference .
# cd ../..
# fi
#
# - name: handle shared object paths for Linux native build
# if: matrix.platform == 'ubuntu-18.04'
# shell: bash
# run: |
# cd build/bin
# ls *_x64 | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# ls *.so | awk '{print $1}' | xargs -I '{}' ldd '{}' | grep "=> /" | grep -v "build" | awk '{print $3}' | xargs -I '{}' cp -vn '{}' . || true
# chmod u+w,+x *
# tar czvf ../linux64.tgz --dereference .
# cd ../..
# fi
#
- name: Upload ${{ matrix.platform }} binaries
uses: actions/upload-artifact@v3
with:
name: solvers-${{ matrix.os }}
name: solvers-${{ matrix.platform }}
path: build/bin*

- name: Setup tmate session
Expand Down

0 comments on commit 65a04a0

Please sign in to comment.