├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── control ├── ent.xml ├── layout └── DEBIAN │ └── postinst └── prepare-toolchain /.gitignore: -------------------------------------------------------------------------------- 1 | .theos 2 | packages 3 | toolchains 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Kabir Oberai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NULL_NAME := swift-toolchain 2 | SWIFT_VERSION := $(shell cat toolchains/.version 2>/dev/null) 3 | BUILD := 1 4 | 5 | override PACKAGE_VERSION := $(SWIFT_VERSION)-$(BUILD) 6 | 7 | include $(THEOS)/makefiles/common.mk 8 | include $(THEOS_MAKE_PATH)/null.mk 9 | 10 | _THEOS_CONTROL_FILE = $(_THEOS_ESCAPED_STAGING_DIR)/DEBIAN/control 11 | SWIFT_VERSION_DEPENDS = com.modmyi.libswift4 (>= $(SWIFT_VERSION)) 12 | 13 | ifeq ($(SWIFT_VERSION),) 14 | before-all:: 15 | @$(PRINT_FORMAT_ERROR)"No Swift toolchain found. Please build one using ./prepare-toolchain" >&2; \ 16 | exit 1; 17 | endif 18 | 19 | stage:: 20 | $(ECHO_NOTHING)rsync -a toolchains/usr-$(SWIFT_VERSION)/ $(THEOS_STAGING_DIR)/usr $(_THEOS_RSYNC_EXCLUDE_COMMANDLINE)$(ECHO_END) 21 | 22 | clean:: 23 | $(ECHO_NOTHING)rm -rf toolchains/swift-source/build$(ECHO_END) 24 | 25 | before-package:: 26 | $(ECHO_NOTHING)sed -i '' -e 's/\$${SWIFT_VERSION}/$(SWIFT_VERSION_DEPENDS)/g' "$(_THEOS_CONTROL_FILE)"$(ECHO_END) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swift-toolchain 2 | 3 | Swift toolchain for iOS 4 | 5 | ## Installation 6 | 7 | 1. Install any requirements listed in `https://github.com/apple/swift/blob/swift--RELEASE/README.md#macos` 8 | 2. Clone this repository somewhere on your computer 9 | 3. Run `./prepare-toolchain ` 10 | 11 | ### Packaging as a .deb 12 | 13 | make package 14 | 15 | ### Installing 16 | 17 | make install THEOS_DEVICE_IP= 18 | -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.kabiroberai.swift-toolchain 2 | Name: swift-toolchain 3 | Section: Development 4 | Architecture: iphoneos-arm 5 | Description: Swift toolchain cross-compiled for iOS 6 | Author: Kabir Oberai 7 | Maintainer: Kabir Oberai 8 | Depends: firmware (>= 7.0), cy+cpu.arm64, ${SWIFT_VERSION} 9 | -------------------------------------------------------------------------------- /ent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | platform-application 6 | 7 | com.apple.private.skip-library-validation 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /layout/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ -x /usr/libexec/cydia/move.sh ]]; then 3 | bash /usr/libexec/cydia/move.sh /usr/share/swift_stash 4 | else 5 | : 6 | fi 7 | -------------------------------------------------------------------------------- /prepare-toolchain: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | shopt -s extglob 4 | cd "$(dirname "$0")" 5 | 6 | if [[ $# -ne 2 ]]; then 7 | echo "Usage: $0 " 8 | exit 1 9 | fi 10 | 11 | export DEVELOPER_DIR="$2/Contents/Developer/" 12 | 13 | info() { echo "[info] $1"; } 14 | 15 | version="$1" 16 | file_name="swift-${version}-RELEASE-osx" 17 | package="${file_name}-package.pkg" 18 | 19 | mkdir -p toolchains 20 | cd toolchains 21 | info "Downloading macOS toolchain" 22 | if [[ ! -f "toolchain-${version}.pkg" ]]; then 23 | curl -#o "toolchain-${version}.pkg" "https://swift.org/builds/swift-${version}-release/xcode/swift-${version}-RELEASE/${file_name}.pkg" 24 | fi 25 | 26 | info "Unpacking toolchain" 27 | # remove any pre-existing usr dir first 28 | rm -rf usr 29 | xar -xf "toolchain-${version}.pkg" "${package}/Payload" 30 | tar -xzf "${package}/Payload" "usr" 31 | rm -rf "${package}" 32 | 33 | info "Modifying macOS toolchain" 34 | cd usr 35 | rm -rf bin lib/libclang.dylib lib/sourcekitd.framework lib/libswiftDemangle.dylib lib/swift/!(clang|iphoneos|shims|migrator) lib/swift_static/!(iphoneos) libexec local 36 | cd lib/swift/iphoneos 37 | for file in libswift*.dylib; do 38 | # symlink to the libswift package 39 | ln -fs "/usr/lib/libswift/${version}/${file}" "${file}" 40 | done 41 | cd ../../../.. 42 | 43 | info "Installing dependencies" 44 | type brew &>/dev/null || ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 45 | type cmake &>/dev/null || brew install cmake 46 | type ninja &>/dev/null || brew install ninja 47 | 48 | info "Checking out Swift repo" 49 | 50 | if [[ -d swift-source ]]; then 51 | rm -rf swift-source 52 | fi 53 | 54 | mkdir swift-source 55 | cd swift-source 56 | git clone https://github.com/apple/swift.git 57 | swift/utils/update-checkout --clone --tag "swift-${version}-RELEASE" 58 | 59 | # patch clang 60 | sed -i '' -e 's;__has_include();__has_include();g' clang/lib/DirectoryWatcher/DirectoryWatcher.cpp 61 | 62 | # compile swift 63 | info "Compiling Swift" 64 | swift/utils/build-script \ 65 | --build-subdir=LLVMClangSwift_iphoneos \ 66 | --release \ 67 | -- \ 68 | --install-swift \ 69 | --install-destdir=output \ 70 | --swift-install-components="compiler;clang-builtin-headers;editor-integration;tools;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers;" \ 71 | --install-prefix=/usr \ 72 | --cross-compile-hosts=iphoneos-arm64 \ 73 | --compiler-vendor=apple \ 74 | --swift-primary-variant-sdk=IOS \ 75 | --swift-primary-variant-arch=arm64 \ 76 | --build-toolchain-only=1 \ 77 | --build-swift-static-stdlib=0 \ 78 | --build-swift-dynamic-stdlib=0 \ 79 | --build-swift-static-sdk-overlay=0 \ 80 | --build-swift-dynamic-sdk-overlay=0 \ 81 | --build-runtime-with-host-compiler=0 \ 82 | --skip-local-host-install \ 83 | --skip-build-benchmarks \ 84 | --skip-test-sourcekit \ 85 | --skip-test-swift \ 86 | --llvm-include-tests=0 \ 87 | --llvm-enable-modules=0 \ 88 | --build-swift-examples=0 \ 89 | --swift-include-tests=0 \ 90 | --darwin-deployment-version-ios=10.0 \ 91 | --darwin-crash-reporter-client=1 \ 92 | --reconfigure 93 | cd .. 94 | 95 | info "Merging toolchains" 96 | cp -a "swift-source/output/merged-hosts/usr/bin" usr/ 97 | cp "swift-source/output/merged-hosts/usr/lib/libswiftDemangle.dylib" usr/lib/ 98 | cd usr/ 99 | # Codesign any Mach-O files, also adding the correct entitlements 100 | find . \( -type f \( -name '*.dylib' -or \( -path './bin/*' -not -name '*.py' \) \) -or \( -path '*.framework/*' -not -name '*.*' \) -not -name '.DS_Store' \) -print0 | xargs -0 -I{} sh -c "ldid -S../../ent.xml {} || :" 101 | 102 | function copy_file() { 103 | mkdir -p share/swift_stash/"$(dirname "$1")" 104 | mv "$1" share/swift_stash/"$(dirname "$1")" 105 | ln -fs /usr/share/swift_stash/"$1" "$1" 106 | } 107 | 108 | export -f copy_file 109 | 110 | find . -type f -print0 | xargs -0 -I{} sh -c 'copy_file {}' 111 | 112 | cd .. 113 | mv usr "usr-${version}" 114 | 115 | echo "${version}" > .version 116 | --------------------------------------------------------------------------------