diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c12cba13..ae6b1fa3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,11 +5,77 @@ on: push: branches: - main - - ci + +env: + LIBKIWIX_VERSION: "13.0.0" jobs: - test: - runs-on: ubuntu-22.04 + build: + strategy: + fail-fast: false + matrix: + destination: + - platform: macOS + name: Any Mac + - platform: iOS + name: Any iOS Device + runs-on: macos-13 + env: + XC_WORKSPACE: Kiwix.xcodeproj/project.xcworkspace/ + XC_SCHEME: Kiwix + XC_CONFIG: Release + XC_DESTINATION: platform=${{ matrix.destination.platform }},name=${{ matrix.destination.name }} + CERTIFICATE: /tmp/apple-development.p12 + SIGNING_IDENTITY: ${{ secrets.APPLE_DEVELOPMENT_SIGNING_IDENTITY }} + KEYCHAIN: /Users/runner/build.keychain-db + KEYCHAIN_PASSWORD: mysecretpassword + KEYCHAIN_PROFILE: build-profile steps: - - name: Hello - run: echo "hello world" + - name: install Apple certificate + shell: bash + run: | + echo "${{ secrets.APPLE_DEVELOPMENT_SIGNING_CERTIFICATE }}" | base64 --decode -o $CERTIFICATE + security create-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN + security default-keychain -s $KEYCHAIN + security set-keychain-settings $KEYCHAIN + security unlock-keychain -p $KEYCHAIN_PASSWORD $KEYCHAIN + security import $CERTIFICATE -k $KEYCHAIN -P "${{ secrets.APPLE_DEVELOPMENT_SIGNING_P12_PASSWORD }}" -A -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild + rm $CERTIFICATE + security set-key-partition-list -S apple-tool:,apple: -s -k $KEYCHAIN_PASSWORD $KEYCHAIN + security find-identity -v $KEYCHAIN + xcrun notarytool store-credentials \ + --apple-id "${{ secrets.APPLE_SIGNING_ALTOOL_USERNAME }}" \ + --password "${{ secrets.APPLE_SIGNING_ALTOOL_PASSWORD }}" \ + --team-id "${{ secrets.APPLE_SIGNING_TEAM }}" \ + --validate \ + --keychain $KEYCHAIN \ + $KEYCHAIN_PROFILE + # not necessary on github runner but serves as documentation for local setup + - name: Update Apple Intermediate Certificate + run: | + curl -L -o ~/Downloads/AppleWWDRCAG3.cer https://www.apple.com/certificateauthority/AppleWWDRCAG3.cer + sudo security import ~/Downloads/AppleWWDRCAG3.cer \ + -k /Library/Keychains/System.keychain \ + -T /usr/bin/codesign \ + -T /usr/bin/security \ + -T /usr/bin/productbuild || true + - name: Set Xcode version (15.0.1) + # https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode + run: sudo xcode-select -s /Applications/Xcode_15.0.1.app + - name: Checkout code + uses: actions/checkout@v3 + - name: Download CoreKiwix.xcframework + env: + XCF_URL: https://download.kiwix.org/release/libkiwix/libkiwix_xcframework-${{ env.LIBKIWIX_VERSION }}.tar.gz + run: curl -L -o - $XCF_URL | tar -x --strip-components 2 + - name: Prepare Xcode + run: xcrun xcodebuild -checkFirstLaunchStatus || xcrun xcodebuild -runFirstLaunch + - name: Dump build settings + run: xcrun xcodebuild -workspace $XC_WORKSPACE -scheme $XC_SCHEME -showBuildSettings + # build is launched up to twice as it's common the build fails, looking for CoreKiwix module + - name: Install retry command + run: brew install kadwanev/brew/retry + - name: Build for ${{ matrix.destination.platform }}/${{ matrix.destination.name }} + env: + FRAMEWORK_SEARCH_PATHS: /Users/runner/work/apple/apple/ + run: retry -t 2 -- xcrun xcodebuild -workspace $XC_WORKSPACE -scheme $XC_SCHEME -destination "$XC_DESTINATION" -configuration $XC_CONFIG -onlyUsePackageVersionsFromResolvedFile -derivedDataPath $PWD/build -allowProvisioningUpdates -verbose build diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index 1c98f136..004dc2e5 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -226,7 +226,7 @@ 97DA90D72975B0C100738365 /* LibraryRefreshViewModelTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryRefreshViewModelTest.swift; sourceTree = ""; }; 97DE2BA1283A8E5C00C63D9B /* LibraryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryViewModel.swift; sourceTree = ""; }; 97DE2BA4283A944100C63D9B /* GridCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridCommon.swift; sourceTree = ""; }; - 97E88F4C2AE407320037F0E5 /* CoreKiwix.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = CoreKiwix.xcframework; sourceTree = ""; }; + 97E88F4C2AE407320037F0E5 /* CoreKiwix.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = CoreKiwix.xcframework; sourceTree = SOURCE_ROOT; }; 97E94B1D271EF250005B0295 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97E94B22271EF250005B0295 /* Kiwix.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Kiwix.entitlements; sourceTree = ""; }; 97F3332E28AFC1A2007FF53C /* SearchResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResults.swift; sourceTree = ""; }; diff --git a/Model/OPDSParser/OPDSParser.mm b/Model/OPDSParser/OPDSParser.mm index 5d309824..6dd3fd73 100644 --- a/Model/OPDSParser/OPDSParser.mm +++ b/Model/OPDSParser/OPDSParser.mm @@ -18,7 +18,7 @@ @interface OPDSParser () -@property kiwix::Library *library; +@property kiwix::LibraryPtr library; @end @@ -27,15 +27,11 @@ - (instancetype _Nonnull)init { self = [super init]; if (self) { - self.library = new kiwix::Library(); + self.library = kiwix::Library::create(); } return self; } -- (void)dealloc { - delete self.library; -} - - (BOOL)parseData:(nonnull NSData *)data { try { NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; diff --git a/README.md b/README.md index 1a765465..0cfdb29a 100644 --- a/README.md +++ b/README.md @@ -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) 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)) -### Creating `CoreKiwix.xcframework` +### Steps -Instructions to build libkiwix at [on the kiwix-build repo](https://github.com/kiwix/kiwix-build). +To compile Kiwix, follow these steps: -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. +* 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. -Following steps are done from kiwix-build root and assume your apple repository is at `../apple`. +### Getting `CoreKiwix.xcframework` -#### Build libkiwix +`CoreKiwix.xcframework` is published with all supported platforms and CPU architectures: -Make sure to preinstall kiwix-build prerequisites (ninja and meson). +- [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`. -If you use homebrew, run the following +#### Compiling `CoreKiwix.xcframework` + +You may want to compile it yourself, to use different branches of said projects for instance. + +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 @@ -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 +python3 -m venv .venv +source .venv/bin/activate +pip install -e . + +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/ ``` -#### Create fat archive with all dependencies +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. -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. +## License -```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 -``` - -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 - -* 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. \ No newline at end of file