Skip to content

Commit

Permalink
Merge pull request #124 from spacedriveapp/ios-framework
Browse files Browse the repository at this point in the history
Add custom create framework logic for iOS
  • Loading branch information
HeavenVolkoff committed Aug 28, 2024
2 parents 55bf275 + db17572 commit 2434207
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 125 deletions.
4 changes: 0 additions & 4 deletions .dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
112 changes: 1 addition & 111 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ root = true
[*]
charset = utf-8
end_of_line = lf
max_line_length = 100
insert_final_newline = true
trim_trailing_whitespace = true

Expand All @@ -27,147 +28,36 @@ trim_trailing_whitespace = true
indent_size = 4
indent_style = space

# Clojure: https://clojure.org/
# https://guide.clojure.style/
[*.{clj,cljs}]
indent_size = 2
indent_style = space

# CSS
# https://google.github.io/styleguide/htmlcssguide.xml#General_Formatting_Rules
# http://cssguidelin.es/#syntax-and-formatting
[*.css]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

# GNU make
# https://www.gnu.org/software/make/manual/html_node/Recipe-Syntax.html
[Makefile]
indent_style = tab

# Go
# https://golang.org/cmd/gofmt/
[{go.mod,*.go}]
indent_style = tab

# GraphQL
# https://graphql.org/learn/
# https://prettier.io
[*.graphql]
indent_size = 2
indent_style = space

# HTML
# https://google.github.io/styleguide/htmlcssguide.xml#General_Formatting_Rules
[*.{htm,html}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

# Java
# https://google.github.io/styleguide/javaguide.html#s4.2-block-indentation
[*.java]
indent_size = 2
indent_style = space

# JavaScript, JSON, JSX, JavaScript Modules, TypeScript
# https://github.com/feross/standard
# https://prettier.io
[*.{cjs,js,json,jsx,mjs,ts,tsx}]
indent_size = 2
indent_style = space

# Just
# https://github.com/casey/just/master/justfile
[{justfile,Justfile}]
insert_final_newline = true
indent_style = space
indent_size = 2

# Kotlin
# https://android.github.io/kotlin-guides/style.html#indentation
[*.{kt,kts}]
indent_size = 4
indent_style = space

# LESS
# https://github.com/less/less-docs#less-standards
[*.less]
indent_size = 2
indent_style = space

# Lua
# http://lua-users.org/wiki/LuaStyleGuide
[*.{lua,luacheckrc}]
indent_size = 2
indent_style = space

# Nushell ( https://www.nushell.sh/ )
# copying Rust for now, see: https://github.com/nushell/nushell/issues/3938
[*.nu]
indent_size = 4
indent_style = space
insert_final_newline = false
trim_trailing_whitespace = true

# PHP
# http://www.php-fig.org/psr/psr-2/
[*.php]
indent_size = 4
indent_style = space

# Python
# https://www.python.org/dev/peps/pep-0008/#code-lay-out
[*.py]
indent_size = 4
indent_style = space

# Ruby
# http://www.caliban.org/ruby/rubyguide.shtml#indentation
[*.rb]
indent_size = 2
indent_style = space

# Rust
# https://github.com/rust-lang/rust/blob/master/src/doc/style/style/whitespace.md
[*.rs]
indent_size = 4
indent_style = space
insert_final_newline = false
trim_trailing_whitespace = true

# SASS
# https://sass-guidelin.es/#syntax--formatting
[*.{sass,scss}]
indent_size = 2
indent_style = space

# Shell
# https://google.github.io/styleguide/shell.xml#Indentation
[*.{bash,sh,zsh}]
indent_size = 2
indent_style = space

# Svelte
# https://github.com/sveltejs/svelte/blob/master/.editorconfig
[*.svelte]
indent_size = 2
indent_style = tab

# TOML
# https://github.com/toml-lang/toml/tree/master/examples
[*.toml]
indent_size = 2
indent_style = space

# Vue.js
# https://eslint.vuejs.org/rules/html-indent.html
# https://eslint.vuejs.org/rules/script-indent.html
[*.vue]
indent_size = 2
indent_style = space

# YAML
# http://yaml.org/spec/1.2/2009-07-21/spec.html#id2576668
[*.{yaml,yml}]
Expand Down
23 changes: 22 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,26 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/99-onnx.sh,target=/srv/stage.sh `
/srv/build.sh

# Create iOS Frameworks from specific lib
ARG VERSION
ENV VERSION="${VERSION:-0.0.0}"
RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/create-ios-framework.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-50 AS layer-99-ffmpeg

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/99-ffmpeg.sh,target=/srv/stage.sh `
/srv/build.sh

# Create iOS Frameworks from specific lib
ARG VERSION
ENV VERSION="${VERSION:-0.0.0}"
RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/create-ios-framework.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-45 AS layer-99-heif

COPY --from=layer-99-ffmpeg "${OUT}/." "$PREFIX"
Expand All @@ -472,6 +486,13 @@ RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/99-heif.sh,target=/srv/stage.sh `
/srv/build.sh

# Create iOS Frameworks from specific lib
ARG VERSION
ENV VERSION="${VERSION:-0.0.0}"
RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/create-ios-framework.sh,target=/srv/stage.sh `
/srv/build.sh

FROM layer-00 AS layer-99

COPY --from=layer-99-heif "${OUT}/." "$OUT"
Expand Down Expand Up @@ -528,7 +549,7 @@ RUN find "${OUT}" -type f -exec chmod u+rw,g+r,g-w,o+r,o-w {} +
ARG VERSION
ENV VERSION="${VERSION:-0.0.0}"
RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=scripts/create-framework.sh,target=/srv/stage.sh `
--mount=type=bind,source=scripts/create-macos-framework.sh,target=/srv/stage.sh `
/srv/build.sh

# Compress source code backup of the built libraries
Expand Down
11 changes: 7 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ cd /srv

set -x

# Make sure license directory exists
mkdir -p "${PREFIX}/licenses/"

# shellcheck disable=SC1091
. /srv/stage.sh
)
Expand All @@ -198,15 +201,15 @@ rm -rf "${PREFIX:?}"/{bin,etc,man,lib/*.{.la,.so*,.dll.a},share}
# Copy licenses
while IFS= read -r _license; do
case "${_license}" in
# Ignore license for tests, examples, contrib, ..., as we are not compiling, running or distributing those
# Ignore license for tests, examples, contrib, ..., as we are not compiling, running or distributing those files
# Ignore GPLv2 licenses, because we opt for GPLv3 for all libraries
*.sh | *.cfg | *.build | */test/* | */tests/* | */demos/* | */build/* | \
*/utils/* | */contrib/* | */examples/* | */3rdparty/* | */third_party/*)
*/utils/* | */contrib/* | */examples/* | */3rdparty/* | */third_party/* | \
*GPL2* | *GPLv2* | *gpl2* | *gplv2*)
continue
;;
esac

mkdir -p "${PREFIX}/licenses/"

# Rename license files to include the package name
cp "$_license" "${PREFIX}/licenses/$(dirname "${_license#/srv/}" | tr '/' '-').$(basename "$_license" .txt)"
done < <(find /srv -type f \( -iname 'license*' -o -iname 'copying*' \) -not -wholename "${PREFIX}/**")
104 changes: 104 additions & 0 deletions scripts/create-ios-framework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

set -xeuo pipefail

case "$TARGET" in
*darwin*)
if [ "$OS_IPHONE" -eq 0 ]; then
echo "macOS target uses another framework structure" >&2
exit 0
fi
;;
*)
echo "Framework creation is only for iOS" >&2
exit 0
;;
esac

if [ -z "${VERSION:-}" ]; then
VERSION="0.0.0"
fi

while IFS= read -r _lib; do
_lib_name="$(basename "$_lib" | awk -F'.' '{print $1}' | sed -e 's/^lib//')"
_framework="${OUT}/${_lib_name}.framework"

mkdir -p "${_framework}"

# Create universal single-arch library
lipo -create "$_lib" -output "${_framework}/lib${_lib_name}"

# Loop through each of the library's dependencies
for _dep in $(otool -L "${_framework}/lib${_lib_name}" | tail -n+3 | awk '{print $1}'); do
case "$_dep" in
"${OUT}/lib/"*) # One of our built libraries
# Change the dependency linker path so it loads it from the same directory as the library
_dep_name="$(basename "$_dep" | awk -F'.' '{print $1}' | sed -e 's/^lib//')"
install_name_tool -change "$_dep" "@rpath/${_dep_name}.framework/lib${_dep_name}" "${_framework}/lib${_lib_name}"
;;
*) # Ignore system libraries
continue
;;
esac
done

# Update the library's own id
if ! install_name_tool -id "@rpath/${_lib_name}.framework/lib${_lib_name}" "${_framework}/lib${_lib_name}"; then
# Some libraries have a header pad too small, so use a relative path instead
install_name_tool -id "./lib${_lib_name}" "$_lib"
fi

# Copy library headers to Framework
if [ -d "${OUT}/include/${_lib_name}" ]; then
cp -r "${OUT}/include/${_lib_name}" "${_framework}/Headers"
elif [ -d "${OUT}/include/lib${_lib_name}" ]; then
cp -r "${OUT}/include/lib${_lib_name}" "${_framework}/Headers"
fi

# Create Info.plist
cat <<EOF >"${_framework}/Info.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>lib${_lib_name}</string>
<key>CFBundleIdentifier</key>
<string>com.spacedrive.Lib${_lib_name}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>lib${_lib_name}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>MinimumOSVersion</key>
<string>14.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>NSPrincipalClass</key>
<string></string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (c) 2021-present Spacedrive Technology Inc.</string>
</dict>
</plist>
EOF

touch "${_framework}/LICENSE"
for _file in "${PREFIX}/licenses/"*; do
{
echo "License for $(basename "$_file" | sed -e 's/\.[^.]*$//')"
cat "$_file"
printf "======================\n\n"
} >>"${_framework}/LICENSE"
done
done < <(find "${OUT}/lib" -type f -name '*.dylib')
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
set -xeuo pipefail

case "$TARGET" in
*darwin*) ;;
*darwin*)
if [ "$OS_IPHONE" -ne 0 ]; then
echo "iOS target uses another framework structure" >&2
exit 0
fi
;;
*)
echo "Framework creation is only for macOS" >&2
exit 0
Expand Down
16 changes: 12 additions & 4 deletions stages/99-pdfium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,25 @@ case "$TARGET" in
_name='linux-musl-arm64'
;;
x86_64-darwin*)
if [ "$OS_IPHONE" -ge 1 ]; then
if [ "$OS_IPHONE" -eq 0 ]; then
_name='mac-x64'
elif [ "$OS_IPHONE" -eq 1 ]; then
_name='ios-x64'
else
_name='mac-x64'
echo "There is no libpdfium pre-built for iOS simulator" >&2
export UNSUPPORTED=1
exit 1
fi
;;
aarch64-darwin*)
if [ "$OS_IPHONE" -ge 1 ]; then
if [ "$OS_IPHONE" -eq 0 ]; then
_name='mac-arm64'
elif [ "$OS_IPHONE" -eq 1 ]; then
_name='ios-arm64'
else
_name='mac-arm64'
echo "There is no libpdfium pre-built for iOS simulator" >&2
export UNSUPPORTED=1
exit 1
fi
;;
esac
Expand Down

0 comments on commit 2434207

Please sign in to comment.