Skip to content

Commit

Permalink
build(darwin): symlinks for FRAMEWORK_SEARCH_PATHS
Browse files Browse the repository at this point in the history
Using symbolic links for `FRAMEWORK_SEARCH_PATHS` allows to not depend
on variable count of architectures included in `media_kit_libs_***`.
Example: `macos-arm64_x86_64` or `macos_arm64`.
  • Loading branch information
birros committed Aug 5, 2023
1 parent 863a4d3 commit 007987a
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 10 deletions.
7 changes: 6 additions & 1 deletion libs/ios/media_kit_libs_ios_audio/ios/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: Frameworks/*.xcframework
all: Frameworks/*.xcframework Frameworks/.symlinks

MPV_XCFRAMEWORKS_VERSION=v0.5.1
MPV_XCFRAMEWORKS_SHA256SUM=3160b4e747f928c90fc9efd3208225a2bbebe2afe21d460165eb2f29fb0596f7
Expand All @@ -23,6 +23,11 @@ Frameworks/*.xcframework: .cache/xcframeworks/libmpv-xcframeworks-ios-universal.
tar -xvf .cache/xcframeworks/libmpv-xcframeworks-ios-universal.tar.gz --strip-components 1 -C Frameworks
touch Frameworks/*.xcframework

Frameworks/.symlinks: Frameworks/*.xcframework
rm -rf Frameworks/.symlinks
mkdir -p Frameworks/.symlinks/mpv
sh create_framework_symlinks.sh Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv

.PHONY: clean
clean:
rm -rf .cache
Expand Down
72 changes: 72 additions & 0 deletions libs/ios/media_kit_libs_ios_audio/ios/create_framework_symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

# `create_framework_symlinks.sh` is duplicated across:
# - `media_kit_libs_ios_audio`
# - `media_kit_libs_ios_video`
# - `media_kit_libs_macos_audio`
# - `media_kit_libs_macos_video`

set -e
set -u

SRC_DIR="$1"
SYMLINKS_DIR="$2"

# Computes the relative path between two given paths
#
# Example:
# ```
# relpath Frameworks/Mpv.xcframework/ios-arm64 Frameworks/.symlinks/mpv
# ../../Mpv.xcframework/ios-arm64
# ```
#
# Source: https://stackoverflow.com/a/14914070
relpath() {
[ $# -ge 1 ] && [ $# -le 2 ] || return 1
current="${2:+"$1"}"
target="${2:-"$1"}"
[ "$target" != . ] || target=/
target="/${target##/}"
[ "$current" != . ] || current=/
current="${current:="/"}"
current="/${current##/}"
appendix="${target##/}"
relative=''
while appendix="${target#"$current"/}"
[ "$current" != '/' ] && [ "$appendix" = "$target" ]; do
if [ "$current" = "$appendix" ]; then
relative="${relative:-.}"
echo "${relative#/}"
return 0
fi
current="${current%/*}"
relative="$relative${relative:+/}.."
done
relative="$relative${relative:+${appendix:+/}}${appendix#/}"
echo "$relative"
}

# Create symbolic links from a given source directory to a destination directory
# for a specific framework
#
# Example:
# ```
# create_framework_symlinks Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv
# Frameworks/.symlinks/mpv/ios -> ../../Mpv.xcframework/ios-arm64
# Frameworks/.symlinks/mpv/ios-simulator -> ../../Mpv.xcframework/ios-arm64_x86_64-simulator
# ```
create_framework_symlinks() {
SRC_DIR="$1"
SYMLINKS_DIR="$2"

find "${SRC_DIR}" -depth 1 -type d | while read SRC; do
SLUG="$(basename "${SRC}")"
NAME="$(echo "${SLUG}" | cut -d '-' -f 1 -f 3)"

SRC_RELATIVE="$(relpath "${SYMLINKS_DIR}" "${SRC}")"

ln -s "${SRC_RELATIVE}" "${SYMLINKS_DIR}/${NAME}"
done
}

create_framework_symlinks "${SRC_DIR}" "${SYMLINKS_DIR}"
7 changes: 6 additions & 1 deletion libs/ios/media_kit_libs_ios_video/ios/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: Frameworks/*.xcframework
all: Frameworks/*.xcframework Frameworks/.symlinks

MPV_XCFRAMEWORKS_VERSION=v0.5.1
MPV_XCFRAMEWORKS_SHA256SUM=a6c7cd6aec15c29ffef8f70ef0eedabaa10d9691832ec9bdccac1277ab23736f
Expand All @@ -23,6 +23,11 @@ Frameworks/*.xcframework: .cache/xcframeworks/libmpv-xcframeworks-ios-universal.
tar -xvf .cache/xcframeworks/libmpv-xcframeworks-ios-universal.tar.gz --strip-components 1 -C Frameworks
touch Frameworks/*.xcframework

Frameworks/.symlinks: Frameworks/*.xcframework
rm -rf Frameworks/.symlinks
mkdir -p Frameworks/.symlinks/mpv
sh create_framework_symlinks.sh Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv

.PHONY: clean
clean:
rm -rf .cache
Expand Down
72 changes: 72 additions & 0 deletions libs/ios/media_kit_libs_ios_video/ios/create_framework_symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

# `create_framework_symlinks.sh` is duplicated across:
# - `media_kit_libs_ios_audio`
# - `media_kit_libs_ios_video`
# - `media_kit_libs_macos_audio`
# - `media_kit_libs_macos_video`

set -e
set -u

SRC_DIR="$1"
SYMLINKS_DIR="$2"

# Computes the relative path between two given paths
#
# Example:
# ```
# relpath Frameworks/Mpv.xcframework/ios-arm64 Frameworks/.symlinks/mpv
# ../../Mpv.xcframework/ios-arm64
# ```
#
# Source: https://stackoverflow.com/a/14914070
relpath() {
[ $# -ge 1 ] && [ $# -le 2 ] || return 1
current="${2:+"$1"}"
target="${2:-"$1"}"
[ "$target" != . ] || target=/
target="/${target##/}"
[ "$current" != . ] || current=/
current="${current:="/"}"
current="/${current##/}"
appendix="${target##/}"
relative=''
while appendix="${target#"$current"/}"
[ "$current" != '/' ] && [ "$appendix" = "$target" ]; do
if [ "$current" = "$appendix" ]; then
relative="${relative:-.}"
echo "${relative#/}"
return 0
fi
current="${current%/*}"
relative="$relative${relative:+/}.."
done
relative="$relative${relative:+${appendix:+/}}${appendix#/}"
echo "$relative"
}

# Create symbolic links from a given source directory to a destination directory
# for a specific framework
#
# Example:
# ```
# create_framework_symlinks Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv
# Frameworks/.symlinks/mpv/ios -> ../../Mpv.xcframework/ios-arm64
# Frameworks/.symlinks/mpv/ios-simulator -> ../../Mpv.xcframework/ios-arm64_x86_64-simulator
# ```
create_framework_symlinks() {
SRC_DIR="$1"
SYMLINKS_DIR="$2"

find "${SRC_DIR}" -depth 1 -type d | while read SRC; do
SLUG="$(basename "${SRC}")"
NAME="$(echo "${SLUG}" | cut -d '-' -f 1 -f 3)"

SRC_RELATIVE="$(relpath "${SYMLINKS_DIR}" "${SRC}")"

ln -s "${SRC_RELATIVE}" "${SYMLINKS_DIR}/${NAME}"
done
}

create_framework_symlinks "${SRC_DIR}" "${SYMLINKS_DIR}"
7 changes: 6 additions & 1 deletion libs/macos/media_kit_libs_macos_audio/macos/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: Frameworks/*.xcframework
all: Frameworks/*.xcframework Frameworks/.symlinks

MPV_XCFRAMEWORKS_VERSION=v0.5.1
MPV_XCFRAMEWORKS_SHA256SUM=2dd65f4afc5031e22794a5b583cf56f8e6b4e901d2d811cf5c8a0dd1d083c08f
Expand All @@ -23,6 +23,11 @@ Frameworks/*.xcframework: .cache/xcframeworks/libmpv-xcframeworks-macos-universa
tar -xvf .cache/xcframeworks/libmpv-xcframeworks-macos-universal.tar.gz --strip-components 1 -C Frameworks
touch Frameworks/*.xcframework

Frameworks/.symlinks: Frameworks/*.xcframework
rm -rf Frameworks/.symlinks
mkdir -p Frameworks/.symlinks/mpv
sh create_framework_symlinks.sh Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv

.PHONY: clean
clean:
rm -rf .cache
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

# `create_framework_symlinks.sh` is duplicated across:
# - `media_kit_libs_ios_audio`
# - `media_kit_libs_ios_video`
# - `media_kit_libs_macos_audio`
# - `media_kit_libs_macos_video`

set -e
set -u

SRC_DIR="$1"
SYMLINKS_DIR="$2"

# Computes the relative path between two given paths
#
# Example:
# ```
# relpath Frameworks/Mpv.xcframework/ios-arm64 Frameworks/.symlinks/mpv
# ../../Mpv.xcframework/ios-arm64
# ```
#
# Source: https://stackoverflow.com/a/14914070
relpath() {
[ $# -ge 1 ] && [ $# -le 2 ] || return 1
current="${2:+"$1"}"
target="${2:-"$1"}"
[ "$target" != . ] || target=/
target="/${target##/}"
[ "$current" != . ] || current=/
current="${current:="/"}"
current="/${current##/}"
appendix="${target##/}"
relative=''
while appendix="${target#"$current"/}"
[ "$current" != '/' ] && [ "$appendix" = "$target" ]; do
if [ "$current" = "$appendix" ]; then
relative="${relative:-.}"
echo "${relative#/}"
return 0
fi
current="${current%/*}"
relative="$relative${relative:+/}.."
done
relative="$relative${relative:+${appendix:+/}}${appendix#/}"
echo "$relative"
}

# Create symbolic links from a given source directory to a destination directory
# for a specific framework
#
# Example:
# ```
# create_framework_symlinks Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv
# Frameworks/.symlinks/mpv/ios -> ../../Mpv.xcframework/ios-arm64
# Frameworks/.symlinks/mpv/ios-simulator -> ../../Mpv.xcframework/ios-arm64_x86_64-simulator
# ```
create_framework_symlinks() {
SRC_DIR="$1"
SYMLINKS_DIR="$2"

find "${SRC_DIR}" -depth 1 -type d | while read SRC; do
SLUG="$(basename "${SRC}")"
NAME="$(echo "${SLUG}" | cut -d '-' -f 1 -f 3)"

SRC_RELATIVE="$(relpath "${SYMLINKS_DIR}" "${SRC}")"

ln -s "${SRC_RELATIVE}" "${SYMLINKS_DIR}/${NAME}"
done
}

create_framework_symlinks "${SRC_DIR}" "${SYMLINKS_DIR}"
7 changes: 6 additions & 1 deletion libs/macos/media_kit_libs_macos_video/macos/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: Frameworks/*.xcframework
all: Frameworks/*.xcframework Frameworks/.symlinks

MPV_XCFRAMEWORKS_VERSION=v0.5.1
MPV_XCFRAMEWORKS_SHA256SUM=c36cced892588399d9268d3e514e0bca871ef09f0e04cef8078e9f172a8caadb
Expand All @@ -23,6 +23,11 @@ Frameworks/*.xcframework: .cache/xcframeworks/libmpv-xcframeworks-macos-universa
tar -xvf .cache/xcframeworks/libmpv-xcframeworks-macos-universal.tar.gz --strip-components 1 -C Frameworks
touch Frameworks/*.xcframework

Frameworks/.symlinks: Frameworks/*.xcframework
rm -rf Frameworks/.symlinks
mkdir -p Frameworks/.symlinks/mpv
sh create_framework_symlinks.sh Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv

.PHONY: clean
clean:
rm -rf .cache
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

# `create_framework_symlinks.sh` is duplicated across:
# - `media_kit_libs_ios_audio`
# - `media_kit_libs_ios_video`
# - `media_kit_libs_macos_audio`
# - `media_kit_libs_macos_video`

set -e
set -u

SRC_DIR="$1"
SYMLINKS_DIR="$2"

# Computes the relative path between two given paths
#
# Example:
# ```
# relpath Frameworks/Mpv.xcframework/ios-arm64 Frameworks/.symlinks/mpv
# ../../Mpv.xcframework/ios-arm64
# ```
#
# Source: https://stackoverflow.com/a/14914070
relpath() {
[ $# -ge 1 ] && [ $# -le 2 ] || return 1
current="${2:+"$1"}"
target="${2:-"$1"}"
[ "$target" != . ] || target=/
target="/${target##/}"
[ "$current" != . ] || current=/
current="${current:="/"}"
current="/${current##/}"
appendix="${target##/}"
relative=''
while appendix="${target#"$current"/}"
[ "$current" != '/' ] && [ "$appendix" = "$target" ]; do
if [ "$current" = "$appendix" ]; then
relative="${relative:-.}"
echo "${relative#/}"
return 0
fi
current="${current%/*}"
relative="$relative${relative:+/}.."
done
relative="$relative${relative:+${appendix:+/}}${appendix#/}"
echo "$relative"
}

# Create symbolic links from a given source directory to a destination directory
# for a specific framework
#
# Example:
# ```
# create_framework_symlinks Frameworks/Mpv.xcframework Frameworks/.symlinks/mpv
# Frameworks/.symlinks/mpv/ios -> ../../Mpv.xcframework/ios-arm64
# Frameworks/.symlinks/mpv/ios-simulator -> ../../Mpv.xcframework/ios-arm64_x86_64-simulator
# ```
create_framework_symlinks() {
SRC_DIR="$1"
SYMLINKS_DIR="$2"

find "${SRC_DIR}" -depth 1 -type d | while read SRC; do
SLUG="$(basename "${SRC}")"
NAME="$(echo "${SLUG}" | cut -d '-' -f 1 -f 3)"

SRC_RELATIVE="$(relpath "${SYMLINKS_DIR}" "${SRC}")"

ln -s "${SRC_RELATIVE}" "${SYMLINKS_DIR}/${NAME}"
done
}

create_framework_symlinks "${SRC_DIR}" "${SYMLINKS_DIR}"
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Pod::Spec.new do |s|

if mku.libs_found
# Define paths to frameworks dir
framework_search_paths_iphoneos = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/Mpv.xcframework/ios-arm64', mku.libs_package)
framework_search_paths_iphonesimulator = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/Mpv.xcframework/ios-arm64_x86_64-simulator', mku.libs_package)
framework_search_paths_iphoneos = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/.symlinks/mpv/ios', mku.libs_package)
framework_search_paths_iphonesimulator = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/.symlinks/mpv/ios-simulator', mku.libs_package)

s.source_files = 'Classes/**/*'
s.platform = :ios, '9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Pod::Spec.new do |s|

if mku.libs_found
# Define paths to frameworks dir
framework_search_paths_macosx = sprintf('$(PROJECT_DIR)/../Flutter/ephemeral/.symlinks/plugins/%s/macos/Frameworks/Mpv.xcframework/macos-arm64_x86_64', mku.libs_package)
framework_search_paths_macosx = sprintf('$(PROJECT_DIR)/../Flutter/ephemeral/.symlinks/plugins/%s/macos/Frameworks/.symlinks/mpv/macos', mku.libs_package)

s.source_files = 'Classes/**/*'
s.platform = :osx, '10.9'
Expand Down
4 changes: 2 additions & 2 deletions media_kit_video/ios/media_kit_video.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Pod::Spec.new do |s|

if mku.libs_found
# Define paths to frameworks dir
framework_search_paths_iphoneos = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/Mpv.xcframework/ios-arm64', mku.libs_package)
framework_search_paths_iphonesimulator = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/Mpv.xcframework/ios-arm64_x86_64-simulator', mku.libs_package)
framework_search_paths_iphoneos = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/.symlinks/mpv/ios', mku.libs_package)
framework_search_paths_iphonesimulator = sprintf('$(PROJECT_DIR)/../.symlinks/plugins/%s/ios/Frameworks/.symlinks/mpv/ios-simulator', mku.libs_package)

s.source_files = 'Classes/plugin/**/*.swift', 'Headers/**/*.h'
s.pod_target_xcconfig = {
Expand Down
Loading

0 comments on commit 007987a

Please sign in to comment.