diff --git a/cozo-lib-c/Cargo.toml b/cozo-lib-c/Cargo.toml index 8bbf35d6..7d76d6bf 100644 --- a/cozo-lib-c/Cargo.toml +++ b/cozo-lib-c/Cargo.toml @@ -16,6 +16,8 @@ crate-type = ["cdylib", "staticlib"] ## Enables the `minimal`, `requests` and `graph-algo` features compact = ["minimal", "requests", "graph-algo", "rayon"] +## Enables the `storage-sqlite` and `graph-algo` features +mobile = ["storage-sqlite", "graph-algo", "rayon"] ## Enables the `minimal`, `requests` and `graph-algo` features in single threaded mode compact-single-threaded = ["minimal", "requests", "graph-algo"] ## Enables the `storage-sqlite` feature diff --git a/cozo-lib-c/README.md b/cozo-lib-c/README.md index fc71a721..26e9987f 100644 --- a/cozo-lib-c/README.md +++ b/cozo-lib-c/README.md @@ -12,3 +12,29 @@ To build and run the example: ```bash gcc -L../target/release/ -lcozo_c example.c -o example && ./example ``` + +## Building for iOS + +See [this guide](https://blog.mozilla.org/data/2022/01/31/this-week-in-glean-building-and-deploying-a-rust-library-on-ios/) +for detailed instructions on compilation for iOS. + +All scripts are run from this directory. + +For iOS devices: + +```bash +ARCHS=arm64 ./comiple-ios.sh cozo_c release +``` + +For simulator on Apple ARM: +```bash +IS_SIMULATOR=1 ARCHS=arm64 ./comiple-ios.sh cozo_c release +``` + +For simulator on x86-64: +```bash +IS_SIMULATOR=1 ARCHS=x86_64 ./comiple-ios.sh cozo_c release +``` + +The libraries are then found in `../target` subdirectories. The static libraries can then be linked into +your iOS applications. \ No newline at end of file diff --git a/cozo-lib-c/comiple-ios.sh b/cozo-lib-c/comiple-ios.sh new file mode 100755 index 00000000..8588bc8f --- /dev/null +++ b/cozo-lib-c/comiple-ios.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +if [ "$#" -ne 2 ] +then + echo "Usage (note: only call inside xcode!):" + echo "compile-library.sh " + exit 1 +fi + +# what to pass to cargo build -p, e.g. your_lib_ffi +FFI_TARGET=$1 +# buildvariant from our xcconfigs +BUILDVARIANT=$2 + +RELFLAG= +if [[ "$BUILDVARIANT" != "debug" ]]; then + RELFLAG=--release +fi + +set -euvx + +if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then + # Assume we're in Xcode, which means we're probably cross-compiling. + # In this case, we need to add an extra library search path for build scripts and proc-macros, + # which run on the host instead of the target. + # (macOS Big Sur does not have linkable libraries in /usr/lib/.) + export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}" +fi + +IS_SIMULATOR=${IS_SIMULATOR:=0} +if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then + IS_SIMULATOR=1 +fi + +for arch in $ARCHS; do + case "$arch" in + x86_64) + if [ $IS_SIMULATOR -eq 0 ]; then + echo "Building for x86_64, but not a simulator build. What's going on?" >&2 + exit 2 + fi + + # Intel iOS simulator + export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" + $HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target x86_64-apple-ios -F mobile + ;; + + arm64) + if [ $IS_SIMULATOR -eq 0 ]; then + # Hardware iOS targets + $HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios -F mobile + else + $HOME/.cargo/bin/cargo build -p $FFI_TARGET --lib $RELFLAG --target aarch64-apple-ios-sim -F mobile + fi + esac +done \ No newline at end of file