English · Русский
A C / Objective-C / C++ compiler for iOS that runs on iOS inside an app: LLVM 22 (clang + lld, AArch64 only)
is built as static libraries for arm64-apple-ios, and a thin wrapper, ioscc, calls the clang driver and
lld::macho in-process, with no fork/exec (iOS has neither). The output is a regular ad-hoc signed Mach-O,
ready to be packed into an .ipa.
Used by Forge (an IDE for iPhone). Built on Linux together with ipab, which provides the iOS SDK.
# requires an installed ipab (./setup.sh in it) — path in IPAB_HOME, default ~/ios-compiler-for-linux
./build-llvm.sh > build.log 2>&1 # LLVM: ~40 min native tools + ~1–2 h cross build (J=4 jobs)
make # out/libioscc.a — the wrapper
make toolchain # out/toolchain — clang headers + trimmed SDK (~160 MB, ~25 MB inside an .ipa)build-llvm.sh can be interrupted: running it again continues where it stopped.
Link out/libioscc.a, all of llvm-ios-build/lib/*.a and -lc++; put out/toolchain into the app bundle.
#include "ioscc.h"
// compile: like clang, but -c only (ioscc_ld does the linking)
const char *cc[] = { "<bundle>/toolchain/bin/clang", "-target", "arm64-apple-ios16.0",
"-isysroot", "<bundle>/toolchain/sdk", "-fobjc-arc", "-c", "main.m", "-o", "main.o" };
ioscc_cc(10, cc);
// link: like ld64.lld
const char *ld[] = { "ld", "-arch", "arm64", "-platform_version", "ios", "16.0", "26.5",
"-syslibroot", "<bundle>/toolchain/sdk", "-adhoc_codesign", "-o", "App",
"main.o", "availability.o", "-framework", "UIKit", "-framework", "Foundation",
"-lSystem", "-lobjc" };
ioscc_ld(20, ld);argv[0]ofioscc_ccis the path "to clang" inside the toolchain: clang finds its headers relative to it (../lib/clang/22/include).- Diagnostics go to stderr. Call one at a time, on a thread with at least an 8 MB stack.
- A crash in cc1 or lld is caught by
CrashRecoveryContextand returned as an error. After an lld crash it cannot be called again until the process restarts (ioscc_ldreturns 125). - Compile and link
toolchain/rt/availability.cif the code uses@available.
Editor and JIT helpers (all in ioscc.h):
ioscc_check— clang diagnostics for unsaved text (path:line:col: error: …),ioscc_complete— code completion at a line/column (tab-separated: kind, name, insertion with<#placeholders#>, signature, result type),ioscc_format— clang-format with a.clang-formatYAML or the default style (tabs).ioscc_jit_load/ioscc_jit_lookup/ioscc_jit_main/ioscc_jit_call— link object files into the current process with ORC JITLink and run them;exit/abort/crashes return to the caller instead of killing the app. Objective-C selectors and classes are registered (no categories, no+load), static constructors run. Needs JIT (ioscc_jit_enabledchecksCS_DEBUGGED); symbols are resolved from the host process.
- C, Objective-C, C++ (and mixes) only. Swift is not compiled on the phone.
- No assembler for
.sfiles (the integrated assembler for inline asm in C works). - No
actool/ibtool: no.xcassets,.storyboard,.xib.
build-llvm.sh |
downloads LLVM 22.1.8, builds native tblgen, cross-builds clang/lld for iOS |
ioscc.h, ioscc.cpp |
C API: ioscc_cc, ioscc_ld, ioscc_version, editor helpers (ioscc_check, ioscc_complete, ioscc_format), JIT (ioscc_jit_*) |
make-toolchain.sh |
out/toolchain: clang headers, the SDK without Swift and extras, availability.c from ipab |
Makefile |
out/libioscc.a and make toolchain |
ios-compiler is licensed under the GNU General Public License v3.0 — see LICENSE. LLVM itself is Apache License 2.0 with LLVM Exceptions. The iOS SDK is not part of this repository: it comes from the installed ipab and only ends up inside the built app.