1
#!/usr/bin/env bash
# xtool build wrapper.
#
# Works around https://github.com/xtool-org/xtool/issues/351 : binaries built
# on Linux record the *deployment target* in the `sdk` field of LC_BUILD_VERSION
# instead of the real SDK version (still broken in xtool 2.0.0-beta.1).
# iOS uses that field for "linked-on-or-after"
# checks, so the app renders the pre-iOS-26 UI (no Liquid Glass). This script
# restamps the field after linking, before packaging.
#
# Usage: ./xtool.sh # build xtool/NexStore.app + xtool/NexStore.ipa
# ./xtool.sh --install # also install the ipa to a connected device
set -euo pipefail
cd "$(dirname "$0")"
xtool dev build
python3 - <<'PY'
import plistlib, struct, sys, os
APP = "xtool/NexStore.app"
BIN = os.path.join(APP, "NexStore")
SDK_CANDIDATES = [
# xtool 2.x layout
"~/.config/xtool/darwin.xtoolsdk/Xcode.app/Contents/Developer/Platforms/"
"iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/SDKSettings.plist",
# xtool 1.x layout
"~/.swiftpm/swift-sdks/darwin.artifactbundle/Xcode.app/Contents/Developer/"
"Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/SDKSettings.plist",
]
SDK_SETTINGS = next(
(os.path.expanduser(p) for p in SDK_CANDIDATES if os.path.exists(os.path.expanduser(p))),
None,
)
if SDK_SETTINGS is None:
raise SystemExit("Could not locate iPhoneOS SDKSettings.plist")
def pack_version(v: str) -> int:
parts = (v.split(".") + ["0", "0", "0"])[:3]
major, minor, patch = (int(p) for p in parts)
return (major << 16) | (minor << 8) | patch
with open(SDK_SETTINGS, "rb") as f:
sdk_version = plistlib.load(f)["Version"]
sdk_packed = pack_version(sdk_version)
print(f"SDK version: {sdk_version} (0x{sdk_packed:x})")
data = bytearray(open(BIN, "rb").read())
def patch_macho(buf, base):
magic = struct.unpack_from("<I", buf, base)[0]
if magic == 0xBEBAFECA: # fat, big-endian
nfat = struct.unpack_from(">I", buf, base + 4)[0]
for i in range(nfat):
off = struct.unpack_from(">I", buf, base + 8 + i * 20 + 8)[0]
patch_macho(buf, base + off)
return
if magic != 0xFEEDFACF:
raise SystemExit(f"{BIN}: not a Mach-O binary (magic {magic:#x})")
ncmds = struct.unpack_from("<I", buf, base + 16)[0]
pos = base + 32
patched = False
for _ in range(ncmds):
cmd, size = struct.unpack_from("<II", buf, pos)
if cmd == 0x32: # LC_BUILD_VERSION
platform, minos, sdk, ntools = struct.unpack_from("<IIII", buf, pos + 8)
print(f" arch@{base:#x}: minos={minos:#x} sdk={sdk:#x} -> sdk={sdk_packed:#x}")
struct.pack_into("<I", buf, pos + 16, sdk_packed)
patched = True
pos += size
if not patched:
raise SystemExit(f"{BIN}: no LC_BUILD_VERSION load command found")
patch_macho(data, 0)
open(BIN, "wb").write(data)
print("patched", BIN)
PY
# Repackage the .app into a proper .ipa (xtool's --ipa path repacks from the
# unpatched build products, so we zip Payload/ ourselves).
ROOT="$(pwd)"
rm -rf /tmp/nexstore-ipa
mkdir -p /tmp/nexstore-ipa/Payload
cp -R "xtool/NexStore.app" /tmp/nexstore-ipa/Payload/
rm -f xtool/NexStore.ipa
(cd /tmp/nexstore-ipa && zip -qry "$ROOT/xtool/NexStore.ipa" Payload)
echo "wrote xtool/NexStore.ipa"
if [ "${1:-}" = "--install" ]; then
xtool install xtool/NexStore.ipa
fi
For immediate assistance, please email our customer support: [email protected]