-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embedding third-party dependencies #379
Changes from 9 commits
b46e396
39ce8b8
0678f33
5e16004
e019067
e056143
1ebe09b
6d61b52
1d9d51e
01e3528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MAKEFLAGS += --silent | ||
|
||
update_dependencies: | ||
echo "👉 Updating Nuke" | ||
make update_nuke version=11.3.1 | ||
echo "👉 Updating SwiftyGif" | ||
make update_swiftygif version=5.4.2 | ||
|
||
update_nuke: check_version_parameter | ||
./Scripts/updateDependency.sh $(version) Dependencies/Nuke Sources/StreamChatSwiftUI/StreamNuke Sources | ||
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamNuke | ||
|
||
update_swiftygif: check_version_parameter | ||
./Scripts/updateDependency.sh $(version) Dependencies/SwiftyGif Sources/StreamChatSwiftUI/StreamSwiftyGif SwiftyGif | ||
./Scripts/removePublicDeclarations.sh Sources/StreamChatSwiftUI/StreamSwiftyGif | ||
|
||
check_version_parameter: | ||
@if [ "$(version)" = "" ]; then\ | ||
echo "❌ Missing version parameter"; \ | ||
exit 1;\ | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,12 @@ let package = Package( | |
) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.39.0"), | ||
.package(url: "https://github.com/kean/Nuke.git", .exact("11.3.1")) | ||
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.39.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "StreamChatSwiftUI", | ||
dependencies: [.product(name: "StreamChat", package: "stream-chat-swift"), "Nuke", .product(name: "NukeUI", package: "Nuke")], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still see Difference, Swifter and the tools. Can we also get rid of those? (not in this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those come from StreamChat. They will be gone as soon as #376 is merged |
||
dependencies: [.product(name: "StreamChat", package: "stream-chat-swift")], | ||
exclude: ["README.md", "Info.plist", "Generated/L10n_template.stencil"], | ||
resources: [.process("Resources")] | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: ./removePublicDeclarations.sh Sources/StreamNuke | ||
# | ||
# This script would iterate over the files on a particular directory, and perform basic replacement operations. | ||
# It heavily relies on 'sed': | ||
# sed -i '<backup-file-extension>' -e 's/<original-string>/<replacement>/g' <file> | ||
# ^ | ||
# Passing empty string prevents the creation of backup files | ||
|
||
args=("$@") | ||
directory=$1 | ||
|
||
replaceDeclaration() { | ||
original=$1 | ||
replacement=$2 | ||
file=$3 | ||
`sed -i '' -e "s/$original/$replacement/g" $file` | ||
} | ||
|
||
files=`find $directory -name "*.swift"` | ||
for f in $files | ||
do | ||
replaceDeclaration 'public internal(set) ' '' $f | ||
replaceDeclaration 'open ' '' $f | ||
replaceDeclaration 'public ' '' $f | ||
|
||
# Nuke | ||
if [[ $directory == *"Nuke"* ]]; then | ||
replaceDeclaration 'var log' 'var nukeLog' $f | ||
replaceDeclaration 'log =' 'nukeLog =' $f | ||
replaceDeclaration 'log: log' 'log: nukeLog' $f | ||
replaceDeclaration 'signpost(log' 'signpost(nukeLog' $f | ||
replaceDeclaration ' Cache(' ' NukeCache(' $f | ||
replaceDeclaration ' Cache<' ' NukeCache<' $f | ||
replaceDeclaration ' Image?' ' NukeImage?' $f | ||
replaceDeclaration ' Image(' ' NukeImage(' $f | ||
replaceDeclaration 'struct Image:' 'struct NukeImage:' $f | ||
replaceDeclaration 'extension Image {' 'extension NukeImage {' $f | ||
replaceDeclaration 'Content == Image' 'Content == NukeImage' $f | ||
replaceDeclaration ' VideoPlayerView' ' NukeVideoPlayerView' $f | ||
replaceDeclaration 'typealias Color' 'typealias NukeColor' $f | ||
replaceDeclaration 'extension Color' 'extension NukeColor' $f | ||
replaceDeclaration 'AssetType' 'NukeAssetType' $f | ||
replaceDeclaration 'typealias ImageRequest = Nuke.ImageRequest' '' $f | ||
replaceDeclaration 'typealias ImageResponse = Nuke.ImageResponse' '' $f | ||
replaceDeclaration 'typealias ImagePipeline = Nuke.ImagePipeline' '' $f | ||
replaceDeclaration 'typealias ImageContainer = Nuke.ImageContainer' '' $f | ||
replaceDeclaration 'open class ' '' $f | ||
replaceDeclaration 'import Nuke' '' $f | ||
|
||
# Remove Cancellable interface duplicate | ||
if [[ $f == *"DataLoader"* && `head -10 $f` == *"protocol Cancellable"* ]]; then | ||
`sed -i '' -e '7,11d' $f` | ||
fi | ||
|
||
# Rename files | ||
if [[ $f == *"Caching/Cache.swift" ]]; then | ||
new_f="${f/Cache.swift/NukeCache.swift}" | ||
mv "$f" "$new_f" | ||
elif [[ $f == *"NukeUI/VideoPlayerView.swift" ]]; then | ||
new_f="${f/VideoPlayerView.swift/NukeVideoPlayerView.swift}" | ||
mv "$f" "$new_f" | ||
fi | ||
fi | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: ./removeUnneededSymbols.sh StreamChatSwiftUI ./Products | ||
# | ||
# Creating an xcframework for StreamChatSwiftUI generates a .bcsymbolmap file for itself, and one for | ||
# each of its dependencies too (eg. StreamChat). That means that we will end up having something like: | ||
# | ||
# -> StreamChatSwiftUI/BCSymbolMaps/ | ||
# <UUID-StreamChatSwiftUI>.bcsymbolmap | ||
# <UUID-StreamChat>.bcsymbolmap | ||
# | ||
# When adding both StreamChat and StreamChatSwiftUI to an app, it will throw an error when trying to compile | ||
# saying that there are multiple executions producing the same file (<UUID-StreamChat>.bcsymbolmap). | ||
# | ||
# This script will remove duplicated .bcsymbolmap in the generated xcframeworks. | ||
# If we countinue with the same example, it will leave it as follows: | ||
# | ||
# -> StreamChatSwiftUI/BCSymbolMaps/ | ||
# <UUID-StreamChatSwiftUI>.bcsymbolmap | ||
# | ||
# Each xcframework only contains its symbols now. | ||
|
||
args=("$@") | ||
library=$1 | ||
output_directory=$2 | ||
|
||
function removeUnneededSymbols() { | ||
arch=$1 | ||
path="$output_directory/$library.xcframework/$arch/BCSymbolMaps" | ||
cd $path | ||
|
||
# Looking for [...]/DerivedSources/[LIBRARY-NAME]_vers.c | ||
regex="(\/DerivedSources\/)([a-zA-Z_]*)(_vers.c)" | ||
files="*.bcsymbolmap" | ||
for f in $files | ||
do | ||
text=`head -10 $f` | ||
[[ $text =~ $regex ]] | ||
library_match="${BASH_REMATCH[2]}" | ||
if [[ $library_match != $library ]] | ||
then | ||
echo "→ Removing uneeded 'bcsymbolmap' from $library-$arch: $library_match - $f" | ||
rm $f | ||
fi | ||
done | ||
|
||
cd - >/dev/null | ||
} | ||
|
||
removeUnneededSymbols "ios-arm64" | ||
removeUnneededSymbols "ios-arm64_x86_64-simulator" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: ./updateDependency.sh 10.3.3 Dependencies/Nuke Sources/StreamNuke Sources | ||
# | ||
# This script gets the source code of a dependency of a given library, and copies it to our codebase | ||
|
||
ensure_clean_git () { | ||
if !(git diff-index --quiet HEAD) | ||
then | ||
echo "→ Seems like git is not clean in $dependency_directory. Please make sure it is clean, and run it again" | ||
exit 1 | ||
fi | ||
} | ||
|
||
args=("$@") | ||
version=$1 | ||
dependency_directory=$2 | ||
output_directory=$3 | ||
sources_directory=$4 | ||
|
||
dependency_url="" | ||
|
||
if [[ $dependency_directory == *"Nuke"* ]]; then | ||
dependency_url="[email protected]:kean/Nuke.git" | ||
elif [[ $dependency_directory == *"SwiftyGif"* ]]; then | ||
dependency_url="[email protected]:kirualex/SwiftyGif.git" | ||
else | ||
echo "→ Unknown dependency at $dependency_directory" | ||
exit 1 | ||
fi | ||
|
||
if ! [[ -d "$dependency_directory" ]]; then | ||
echo "→ $dependency_directory does not exist in your filesystem. Cloning the repo" | ||
git clone $dependency_url $dependency_directory | ||
fi | ||
|
||
cd $dependency_directory | ||
|
||
ensure_clean_git | ||
|
||
git fetch --tags | ||
git checkout $version | ||
|
||
ensure_clean_git | ||
|
||
cd - | ||
|
||
echo "→ Copying source files" | ||
rm -rf $output_directory | ||
mkdir $output_directory | ||
cp -r "$dependency_directory/$sources_directory/." $output_directory | ||
|
||
|
||
for f in `find $output_directory -type f \( -iname \*.h -o -iname \*.plist \)` | ||
do | ||
echo "→ Removing $f" | ||
rm $f | ||
done | ||
|
||
rm -rf $dependency_directory |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
// | ||
|
||
import AVKit | ||
import Nuke | ||
import NukeUI | ||
import StreamChat | ||
import SwiftUI | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add that they should "Reset package caches" after integrating? I had issues until I did that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍