#!/usr/bin/env bash # iOS/macOS cannot run `nim` from inside Xcode's sandbox, and App Store builds # want a static archive. So Nim's C output is generated ahead of time and # checked in; CocoaPods then compiles it like any other C source. # # Unlike a single-file C emitter, Nim writes one .c per module plus nimbase.h, # so the whole set is copied in and the stale ones cleared out first. # # Re-run this whenever src/nimflutter.nim changes. set -euo pipefail cd "$(dirname "$0")/.." nim_bin="${NIM:-nim}" command -v "$nim_bin" >/dev/null || { echo "Nim compiler not on PATH (set NIM=/path/to/nim)"; exit 1; } nim_lib="$(dirname "$(dirname "$(command -v "$nim_bin")")")/lib" cache=build/nimcache_ios rm -rf "$cache" "$nim_bin" c --compileOnly --nimcache:"$cache" --mm:arc -d:danger \ --threads:on --noMain src/nimflutter.nim for dir in ios/Classes macos/Classes; do rm -f "$dir"/*.c "$dir"/*.h mkdir -p "$dir" # Nim's filenames encode module paths with @ and @s; harmless for the # compiler, but CocoaPods globs are happier with flat names. i=0 for c in "$cache"/*.c; do cp "$c" "$dir/nimflutter_$(printf '%02d' "$i").c" i=$((i + 1)) done cp "$nim_lib/nimbase.h" "$dir/nimbase.h" cp src/nimflutter.h "$dir/nimflutter.h" done echo "regenerated ios/ + macos/ sources ($(ls ios/Classes/*.c | wc -l) C files)"