# Rebuild the native Xray component

The application builds 20 and 21 use the same native source inputs and archives.
This package contains changed source and patches, not a complete proprietary iOS
application project. Obtain unchanged source at the exact upstream commits in
`provenance.json`. The script performs the checkouts and applies all five patches.

Use macOS, a selected Xcode installation with iPhoneOS/iPhoneSimulator SDKs,
Git, Python 3, patch, shasum and **Go 1.27.1**. The original build used Xcode 26.6.
An Internet connection is needed for the pinned repositories and Go dependencies.
No Apple account, signing key, VPN account or server configuration is required to
build this unsigned static library. Archive hashes identify the existing packaged
binaries; a different SDK, build directory or toolchain can change output bytes.

## Download all public source files

In a new empty directory, run this Python 3 snippet. It checks the HTTPS certificate
and checks every downloaded file against this publication's SHA-256 inventory.
The checksum inventory is supplied over the same HTTPS origin, not a signature.

```python
import hashlib, pathlib, re, urllib.request
base = "https://tivravpn.com/open-source/2026-11-09-build20-21/"
manifest = urllib.request.urlopen(base + "SHA256SUMS", timeout=30).read()
for line in manifest.decode("ascii").splitlines():
    digest, relative = line.split("  ", 1)
    path = pathlib.PurePosixPath(relative)
    assert re.fullmatch(r"[0-9a-f]{64}", digest)
    assert not path.is_absolute() and ".." not in path.parts
    data = urllib.request.urlopen(base + relative, timeout=30).read()
    assert hashlib.sha256(data).hexdigest() == digest, relative
    target = pathlib.Path(relative)
    assert not target.exists(), relative
    target.parent.mkdir(parents=True, exist_ok=True)
    target.write_bytes(data)
pathlib.Path("SHA256SUMS").write_bytes(manifest)
```

Then verify `shasum -a 256 -c SHA256SUMS`.

## Build

Keep `Scripts/build-xray.sh` and `Patches/` at their published relative paths.
Select the desired Xcode with the normal Xcode developer-directory mechanism and
replace the two example absolute paths below. XRAY_WORK must be an empty scratch
directory; keep it outside this downloaded source directory. The script never
edits the system Go installation and refuses a compiler other than Go 1.27.1.

```sh
XRAY_WORK=/absolute/path/to/empty-xray-build \
XRAY_GO_BIN=/absolute/path/to/go1.27.1/bin \
PYTHON_BIN=python3 \
sh Scripts/build-xray.sh
```

The exact integration script clones libXray at its pinned commit, validates and
applies the two wrapper patches, obtains the pinned Go core module, validates and
applies the three core patches, runs affected-core and full-wrapper Go tests,
then invokes upstream `build/main.py apple go local`. The official builder uses a
temporary local module replacement and restores the wrapper's go.mod/go.sum.
The final `LibXray.xcframework` contains iOS arm64 and simulator arm64/x86_64 slices.
It does not include the unrelated macOS/tvOS outputs built by upstream.

`LibXraySource/` contains the exact modified wrapper source plus the unchanged
upstream go.mod/go.sum and MIT license. `Patches/Source/` contains every modified
or added MPL-covered core file and its license. Both sets were independently
reconstructed from the pinned upstream sources and all patches without fuzz.
No raw device logs, environment files, keys or binary archives are published.
