Skip to content

Commit

Permalink
Merge pull request #5 from birros/fix/macos-xcframewoks
Browse files Browse the repository at this point in the history
fix macOS .framework layout
  • Loading branch information
birros authored Apr 5, 2023
2 parents 9f10798 + b507c62 commit d5cc06b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 23 deletions.
17 changes: 11 additions & 6 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ tasks:
NAME=libmpv-xcframeworks-{{.VERSION}}-{{.OS}}-{{.ARCH}}
mkdir -p "{{.PACKAGES_DIR}}/$NAME"
cp -r "{{.XCFRAMEWORKS_DIR}}"/*.xcframework "{{.PACKAGES_DIR}}"/$NAME/
cp -R "{{.XCFRAMEWORKS_DIR}}"/*.xcframework "{{.PACKAGES_DIR}}"/$NAME/
cd "{{.PACKAGES_DIR}}"
tar -czvf $NAME.tar.gz $NAME
Expand All @@ -296,7 +296,7 @@ tasks:
NAME=libmpv-{{.VERSION}}-{{.OS}}-{{.ARCH}}
mkdir -p "{{.PACKAGES_DIR}}/$NAME"
cp -r "{{.LIBS_DIR}}"/*.dylib "{{.PACKAGES_DIR}}"/$NAME/
cp -R "{{.LIBS_DIR}}"/*.dylib "{{.PACKAGES_DIR}}"/$NAME/
cd "{{.PACKAGES_DIR}}"
tar -czvf $NAME.tar.gz $NAME
Expand Down Expand Up @@ -422,10 +422,15 @@ tasks:
export PATH={{.PATH}}
export TERM={{.TERM}}
sh "{{.PROJECT_DIR}}/scripts/frameworks/create_frameworks.sh" \
"{{.OS}}" \
"{{.LIBS_DIR}}" \
"{{.FRAMEWORKS_DIR}}"
if [ "{{.OS}}" == "macos" ]; then \
sh "{{.PROJECT_DIR}}/scripts/frameworks/macos/create_frameworks.sh" \
"{{.LIBS_DIR}}" \
"{{.FRAMEWORKS_DIR}}"; \
elif [ "{{.OS}}" == "ios" ] || [ "{{.OS}}" == "iossimulator" ]; then \
sh "{{.PROJECT_DIR}}/scripts/frameworks/ios/create_frameworks.sh" \
"{{.LIBS_DIR}}" \
"{{.FRAMEWORKS_DIR}}"; \
fi
libs-macos-universal:
internal: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/bin/sh

OS="$1"
LIBS_DIR="$2"
FRAMEWORKS_DIR="$3"
# see: MobileVLCKit cocoapods

if [ "$OS" == "iossimulator" ]; then
OS=ios
fi
LIBS_DIR="$1"
FRAMEWORKS_DIR="$2"

find "${LIBS_DIR}" -name "*.dylib" -type f | while read DYLIB; do
echo "${DYLIB}"

# create framework dylib name: libavcodec.59.dylib -> Avcodec
DYLIB_NAME=$(basename $DYLIB .dylib | sed 's/\.[0-9]*$//' | sed 's/^lib//')
DYLIB_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${DYLIB_NAME:0:1})${DYLIB_NAME:1}"
# create framework name: libavcodec.59.dylib -> Avcodec
FRAMEWORK_NAME=$(basename $DYLIB .dylib | sed 's/\.[0-9]*$//' | sed 's/^lib//')
FRAMEWORK_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${FRAMEWORK_NAME:0:1})${FRAMEWORK_NAME:1}"

# framework dir
FRAMEWORK_DIR="${FRAMEWORKS_DIR}/${FRAMEWORK_NAME}.framework"

# we get the min supported version from the arm64 version, because it is the
# highest
MIN_OS_VERSION=$(xcrun vtool -arch arm64 -show "${DYLIB}" | grep minos | cut -d ' ' -f6)

# copy dylib
mkdir -p "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework"
cp "${DYLIB}" "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/${DYLIB_NAME}"
mkdir -p "${FRAMEWORK_DIR}"
cp "${DYLIB}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"

# replace DYLIB var
DYLIB="${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/${DYLIB_NAME}"
DYLIB="${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"

codesign --force -s - "${DYLIB}"

# update dylib id
NEW_ID="@rpath/${DYLIB_NAME}.framework/${DYLIB_NAME}"
NEW_ID="@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
install_name_tool \
-id "${NEW_ID}" "${DYLIB}" \
2> /dev/null
Expand All @@ -55,8 +55,8 @@ find "${LIBS_DIR}" -name "*.dylib" -type f | while read DYLIB; do
codesign --remove "${DYLIB}"

# add Info.plist
cp ./scripts/frameworks/${OS}/Info.plist "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/"
sed -i '' 's/${FRAMEWORK_NAME}/'${DYLIB_NAME}'/g' "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/Info.plist"
sed -i '' 's/${MIN_OS_VERSION}/'${MIN_OS_VERSION}'/g' "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/Info.plist"
plutil -convert binary1 "${FRAMEWORKS_DIR}/${DYLIB_NAME}.framework/Info.plist"
cp ./scripts/frameworks/ios/Info.plist "${FRAMEWORK_DIR}/"
sed -i '' 's/${FRAMEWORK_NAME}/'${FRAMEWORK_NAME}'/g' "${FRAMEWORK_DIR}/Info.plist"
sed -i '' 's/${MIN_OS_VERSION}/'${MIN_OS_VERSION}'/g' "${FRAMEWORK_DIR}/Info.plist"
plutil -convert binary1 "${FRAMEWORK_DIR}/Info.plist"
done
69 changes: 69 additions & 0 deletions scripts/frameworks/macos/create_frameworks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

# see: VLCKit cocoapods
# see: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html

LIBS_DIR="$1"
FRAMEWORKS_DIR="$2"

find "${LIBS_DIR}" -name "*.dylib" -type f | while read DYLIB; do
echo "${DYLIB}"

# create framework name: libavcodec.59.dylib -> Avcodec
FRAMEWORK_NAME=$(basename $DYLIB .dylib | sed 's/\.[0-9]*$//' | sed 's/^lib//')
FRAMEWORK_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${FRAMEWORK_NAME:0:1})${FRAMEWORK_NAME:1}"

# framework dir
FRAMEWORK_DIR="${FRAMEWORKS_DIR}/${FRAMEWORK_NAME}.framework"

# we get the min supported version from the arm64 version, because it is the
# highest
MIN_OS_VERSION=$(xcrun vtool -arch arm64 -show "${DYLIB}" | grep minos | cut -d ' ' -f6)

# copy dylib
mkdir -p "${FRAMEWORK_DIR}/Versions/A"
cp "${DYLIB}" "${FRAMEWORK_DIR}/Versions/A/${FRAMEWORK_NAME}"

# replace DYLIB var
DYLIB="${FRAMEWORK_DIR}/Versions/A/${FRAMEWORK_NAME}"

codesign --force -s - "${DYLIB}"

# update dylib id
NEW_ID="@rpath/${FRAMEWORK_NAME}.framework/Versions/A/${FRAMEWORK_NAME}"
install_name_tool \
-id "${NEW_ID}" "${DYLIB}" \
2> /dev/null

# update dylib dep paths
otool -l "${DYLIB}" |
grep " name " |
cut -d " " -f11 |
tail -n +2 |
grep "@rpath" |
while read DEP; do
DEP_NAME=$(basename $DEP .dylib | sed 's/\.[0-9]*$//' | sed 's/^lib//')
DEP_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${DEP_NAME:0:1})${DEP_NAME:1}"

NEW_DEP="@rpath/${DEP_NAME}.framework/Versions/A/${DEP_NAME}"

install_name_tool \
-change "${DEP}" "${NEW_DEP}" \
"${DYLIB}" \
2>/dev/null
done

codesign --remove "${DYLIB}"

# add Info.plist
mkdir -p "${FRAMEWORK_DIR}/Versions/A/Resources"
cp ./scripts/frameworks/macos/Info.plist "${FRAMEWORK_DIR}/Versions/A/Resources/"
sed -i '' 's/${FRAMEWORK_NAME}/'${FRAMEWORK_NAME}'/g' "${FRAMEWORK_DIR}/Versions/A/Resources/Info.plist"
sed -i '' 's/${MIN_OS_VERSION}/'${MIN_OS_VERSION}'/g' "${FRAMEWORK_DIR}/Versions/A/Resources/Info.plist"
plutil -convert binary1 "${FRAMEWORK_DIR}/Versions/A/Resources/Info.plist"

# create sym links
ln -s A "${FRAMEWORK_DIR}/Versions/Current"
ln -s Versions/Current/${FRAMEWORK_NAME} "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
ln -s Versions/Current/Resources "${FRAMEWORK_DIR}/Resources"
done

0 comments on commit d5cc06b

Please sign in to comment.