Skip to content

Commit

Permalink
Merge branch 'main' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin authored Nov 17, 2023
2 parents b195baa + c3e3aa4 commit 89f4b7c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 60 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- main

jobs:
build:
strategy:
Expand Down
112 changes: 53 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
# Kiwix for iOS & macOS
# Kiwix for Apple iOS & macOS

This is the home for Kiwix apps on iOS and macOS.
This is the home for Kiwix apps for Apple iOS and macOS.

[![CodeFactor](https://www.codefactor.io/repository/github/kiwix/apple/badge)](https://www.codefactor.io/repository/github/kiwix/apple)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
<img src="https://img.shields.io/badge/Swift-5.2-orange.svg" alt="Drawing="/>

### Mobile app for iPads & iPhones ###
- Download the iOS mobile app on the [App Store](https://ios.kiwix.org)
## Download

### Kiwix Desktop for macOS ###
- Download Kiwix Desktop on the [Mac App Store](https://macos.kiwix.org)
- Download Kiwix Desktop [DMG file](https://download.kiwix.org/release/kiwix-desktop-macos/kiwix-desktop-macos.dmg)
Kiwix apps are made available primarily via the [App Store](https://ios.kiwix.org) and [Mac App Store](https://macos.kiwix.org). macOS version can also be [downloaded directly](https://download.kiwix.org/release/kiwix-desktop-macos/kiwix-desktop-macos.dmg).

## Developers
Most recent versions of Kiwix support the three latest major versions of the
OSes (either iOS or macOS). Older versions of Kiwix being still
downloadable for older versions of macOS and iOS on the Mac App Store.

## Develop

Kiwix developers usually work with latest macOS and Xcode. Check our [Continuous Integration Workflow](https://github.com/kiwix/apple/blob/main/.github/workflows/ci.yml) to find out which XCode version we use on Github Actions.

### CPU Architectures

Kiwix compiles on both macOS architectures x86_64 and arm64 (Apple silicon).

Kiwix for iOS and macOS can run, in both cases, on x86_64 or arm64.

### Dependencies

To compile Kiwix you rely on the following compilation tools:

* An [Apple Developer account](https://developer.apple.com) (doesn't require membership)
* Latest Apple Developers Tools ([Xcode](https://developer.apple.com/xcode/))
* Its command-line utilities (`xcode-select --install`)
* `CoreKiwix.xcframework` ([libkiwix](https://github.com/kiwix/libkiwix))
* `CoreKiwix.xcframework` ([libkiwix](https://github.com/kiwix/libkiwix) and [libzim](https://github.com/openzim/libzim))

### Steps

### Creating `CoreKiwix.xcframework`
To compile Kiwix, follow these steps:

Instructions to build libkiwix at [on the kiwix-build repo](https://github.com/kiwix/kiwix-build).
* Put `CoreKiwix/xcframework` at the root of this folder
* Open project with Xcode `open Kiwix.xcodeproj/project.xcworkspace/`
* Change the Bundle Identifier (in *Signing & Capabilities*)
* Select appropriate Signing Certificate/Profile.

### Getting `CoreKiwix.xcframework`

The xcframework is a bundle of a library for multiple architectures and/or platforms. The `CoreKiwix.xcframework` will contain libkiwix library for macOS archs and for iOS. You don't have to follow steps for other platform/arch if you don't need them.
`CoreKiwix.xcframework` is published with all supported platforms and CPU architectures:

Following steps are done from kiwix-build root and assume your apple repository is at `../apple`.
- [latest release](https://download.kiwix.org/release/libkiwix/libkiwix_xcframework.tar.gz)
- [latest nightly](https://download.kiwix.org/nightly/libkiwix_xcframework.tar.gz): using `main` branch of both `libkiwix` and `libzim`.

#### Build libkiwix
#### Compiling `CoreKiwix.xcframework`

Make sure to preinstall kiwix-build prerequisites (ninja and meson).
You may want to compile it yourself, to use different branches of said projects for instance.

If you use homebrew, run the following
The xcframework is a bundle of all libkiwix dependencies for multiple architectures
and platforms. The `CoreKiwix.xcframework` will contain libkiwix
library for macOS archs and for iOS. It is built off [kiwix-build
repo](https://github.com/kiwix/kiwix-build).

Make sure to preinstall kiwix-build prerequisites (ninja and meson). If you use homebrew, run the following

```sh
brew install ninja meson
```

Make sure xcode command tools are installed. Make sure to download an iOS SDK if you want to build for iOS.
Make sure Xcode command tools are installed. Make sure to download an
iOS SDK if you want to build for iOS.

```sh
xcode-select --install
Expand All @@ -51,50 +76,19 @@ Then you can build `libkiwix`
```sh
git clone https://github.com/kiwix/kiwix-build.git
cd kiwix-build
# [iOS] build libkiwix
kiwix-build --target-platform iOS_arm64 libkiwix
kiwix-build --target-platform iOS_x86_64 libkiwix # iOS simulator in Xcode
# [macOS] build libkiwix
kiwix-build --target-platform macOS_x86_64 libkiwix
kiwix-build --target-platform macOS_arm64_static libkiwix
```

#### Create fat archive with all dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

This creates a single `.a` archive named `merged.a` (for each platform) which contains libkiwix and all it's dependencies.
Skip those you don't want to support.

```sh
libtool -static -o BUILD_macOS_x86_64/INSTALL/lib/merged.a BUILD_macOS_x86_64/INSTALL/lib/*.a
libtool -static -o BUILD_macOS_arm64_static/INSTALL/lib/merged.a BUILD_macOS_arm64_static/INSTALL/lib/*.a
libtool -static -o BUILD_iOS_x86_64/INSTALL/lib/merged.a BUILD_iOS_x86_64/INSTALL/lib/*.a
libtool -static -o BUILD_iOS_arm64/INSTALL/lib/merged.a BUILD_iOS_arm64/INSTALL/lib/*.a
```

If you built macOS support for both archs (that's what you want unless you know what you're doing), you need to merge both files into a single one

```sh
mkdir -p macOS_fat
lipo -create -output macOS_fat/merged.a \
-arch x86_64 BUILD_macOS_x86_64/INSTALL/lib/merged.a \
-arch arm64 BUILD_macOS_arm64_static/INSTALL/lib/merged.a
```

#### Add fat archive to xcframework

```sh
xcodebuild -create-xcframework \
-library macOS_fat/merged.a -headers BUILD_macOS_x86_64/INSTALL/include \
-library BUILD_iOS_x86_64/INSTALL/lib/merged.a -headers BUILD_iOS_x86_64/INSTALL/include \
-library BUILD_iOS_arm64/INSTALL/lib/merged.a -headers BUILD_iOS_arm64/INSTALL/include \
-output ../apple/CoreKiwix.xcframework
kiwix-build --target-platform apple_all_static libkiwix
# assuming your kiwix-build and apple folder at at same level
cp -r BUILD_apple_all_static/INSTALL/lib/CoreKiwix.xcframework ../apple/
```

You can now launch the build from Xcode and use the iOS simulator or your macOS target. At this point the xcframework is not signed.

You can now launch the build from Xcode and use the iOS simulator or
your macOS target. At this point the xcframework is not signed.

### Building Kiwix iOS or Kiwix macOS
## License

* Open project with Xcode `open Kiwix.xcodeproj/project.xcworkspace/`
* Change the Bundle Identifier (in *Signing & Capabilities*)
* Select appropriate Signing Certificate/Profile.
[GPLv3](https://www.gnu.org/licenses/gpl-3.0) or later, see
[LICENSE](LICENSE) for more details.

0 comments on commit 89f4b7c

Please sign in to comment.