| 1 | #!/bin/sh |
| 2 | # Builds libtwidget_litehtml.a (litehtml + gumbo + the renderer core + the |
| 3 | # CoreGraphics backend and C ABI, merged into one archive) for the platform and |
| 4 | # architectures of the current Xcode build (PLATFORM_NAME, ARCHS — set by Xcode |
| 5 | # when this runs as the pre-build script phase of the iOS / macOS demo; |
| 6 | # defaults to macOS arm64 from a shell) and puts the (fat) library in |
| 7 | # target/apple/<PLATFORM_NAME>/, where the demos' LIBRARY_SEARCH_PATHS points. |
| 8 | # The twin of renderer-blitz/build-apple.sh; needs cmake and ninja (Homebrew). |
| 9 | # The library targets iOS 16.3 / macOS 13.3 (std::to_chars for doubles in |
| 10 | # twidget/json.h needs those libc++ versions); the demos target 16.0 / 13.0, so |
| 11 | # the linker warns about the newer object and links anyway. |
| 12 | set -eu |
| 13 | cd "$(dirname "$0")" |
| 14 | export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" |
| 15 | platform="${PLATFORM_NAME:-macosx}" |
| 16 | archs="${ARCHS:-arm64}" |
| 17 | case "$platform" in |
| 18 | iphoneos) system="iOS"; sysroot="iphoneos"; target="16.3" ;; |
| 19 | iphonesimulator) system="iOS"; sysroot="iphonesimulator"; target="16.3" ;; |
| 20 | macosx) system="Darwin"; sysroot="macosx"; target="13.3" ;; |
| 21 | *) echo "build-apple.sh: unsupported PLATFORM_NAME '$platform'" >&2; exit 1 ;; |
| 22 | esac |
| 23 | # Xcode's environment describes the app's target; CMake gets the same facts explicitly and must not inherit the rest. |
| 24 | unset SDKROOT IPHONEOS_DEPLOYMENT_TARGET MACOSX_DEPLOYMENT_TARGET CC CXX LD CPLUSPLUS CPP |
| 25 | libs="" |
| 26 | for arch in $archs; do |
| 27 | case "$arch" in |
| 28 | arm64|x86_64) ;; |
| 29 | *) continue ;; |
| 30 | esac |
| 31 | build="target/apple/build-$platform-$arch" |
| 32 | cmake -S . -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release \ |
| 33 | -DCMAKE_SYSTEM_NAME="$system" -DCMAKE_OSX_SYSROOT="$sysroot" -DCMAKE_OSX_ARCHITECTURES="$arch" \ |
| 34 | -DCMAKE_OSX_DEPLOYMENT_TARGET="$target" >/dev/null |
| 35 | cmake --build "$build" --target twidget_litehtml |
| 36 | # one archive for the linker: the core, litehtml and gumbo |
| 37 | libtool -static -o "$build/libtwidget_litehtml_all.a" \ |
| 38 | "$build/libtwidget_litehtml.a" "$build/libtwidget_litehtml_core.a" \ |
| 39 | "$build/third_party/litehtml/liblitehtml.a" "$build/third_party/litehtml/src/gumbo/libgumbo.a" 2>/dev/null |
| 40 | libs="$libs $build/libtwidget_litehtml_all.a" |
| 41 | done |
| 42 | [ -n "$libs" ] || { echo "build-apple.sh: no supported arch in ARCHS='$archs'" >&2; exit 1; } |
| 43 | out="target/apple/$platform" |
| 44 | mkdir -p "$out" |
| 45 | # shellcheck disable=SC2086 |
| 46 | lipo -create $libs -output "$out/libtwidget_litehtml.a" |
| 47 | echo "build-apple.sh: $out/libtwidget_litehtml.a ($archs)" |
| 48 |