Skip to content

Commit

Permalink
Update build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga authored Sep 3, 2024
1 parent 71066da commit ae18024
Showing 1 changed file with 1 addition and 48 deletions.
49 changes: 1 addition & 48 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,4 @@ brew tap --verbose metacall/brew-pkg
brew install --verbose --HEAD metacall/brew-pkg/brew-pkg
brew pkg --with-deps --compress metacall
mv metacall-${METACALL_VERSION}.pkg release/metacall-tarball-macos-${METACALL_ARCH}.pkg

# Extract the .tgz file
tar -xzvf metacall-${METACALL_VERSION}.tgz
mkdir distributable

INSTALL_DIR=""
# Specify install directory
if [ "$METACALL_ARCH" = "arm64" ]; then
INSTALL_DIR="opt/homebrew"
else
INSTALL_DIR="usr/local"
fi

# Copy MetaCall core
cp -R Cellar/metacall/[0-9]*.[0-9]*.[0-9]* distributable/metacall-core
# Copy Ruby
cp -R Cellar/ruby/[0-9]*.[0-9]* distributable/ruby
# Copy Python
cp -R Cellar/python@[0-9]*.[0-9]* distributable/python
# Copy MetaCall binary
cp bin/metacall distributable/

# Change path of shared libraries
change_library_path() {
loader=$1
lib_regex=$INSTALL_DIR
metacall_lib=distributable/metacall-core/lib/lib${loader}_loader.so

old_lib=$(otool -L "$metacall_lib" | grep -E "$lib_regex" | awk '{print $1}')
old_lib_regex=$(echo $old_lib | awk -F'/' '{print $(NF-2)"/"$(NF-1)"/"$NF}') # Get the path suffix
new_lib=$(cd distributable && find . -type f -regex ".*/$old_lib_regex")

if [ -n "$old_lib" ] && [ -n "$new_lib" ]; then
install_name_tool -change "$old_lib" "@loader_path/../.$new_lib" "$metacall_lib"
echo "Updated $loader loader: $old_lib -> $new_lib"
else
echo "Failed to update $loader loader: Could not find the old or new library path."
fi
}

# Update Python loader
change_library_path "py"

# Update Ruby loader
change_library_path "rb"

tar -czf metacall-tarball-macos-${METACALL_ARCH}.tgz distributable
mv metacall-tarball-macos-${METACALL_ARCH}.tgz release/
mv metacall-${METACALL_VERSION}.tgz release/metacall-tarball-macos-${METACALL_ARCH}.tgz

0 comments on commit ae18024

Please sign in to comment.