#!/bin/sh
# Reproduces Frameworks/Libbox.xcframework exactly as shipped in Tuno Connect.
# Requires macOS with Xcode, and Go 1.24+.
set -eu

ENGINE=1.13.12
TAGS="with_gvisor,with_utls,with_clash_api,badlinkname,tfogo_checklinkname0,grpcnotrace"

go install github.com/sagernet/gomobile/cmd/gomobile@latest
go install github.com/sagernet/gomobile/cmd/gobind@latest

git clone --depth 1 --branch "v$ENGINE" https://github.com/SagerNet/sing-box
cd sing-box

# Upstream's own default tags additionally enable Tailscale, Cronet/naive,
# WireGuard, QUIC and DHCP. None of them are used by this app, so they are left
# out — that is the only difference from an upstream build.
"$(go env GOPATH)/bin/gomobile" bind -v \
  -target ios,iossimulator \
  -libname=box \
  -trimpath -buildvcs=false \
  -ldflags "-X github.com/sagernet/sing-box/constant.Version=$ENGINE \
            -X internal/godebug.defaultGODEBUG=multipathtcp=0 \
            -s -w -buildid= -checklinkname=0" \
  -tags "$TAGS" \
  ./experimental/libbox
