[build] align mobile Xmake repository selection with desktop

This commit is contained in:
dijunkun
2026-10-27 12:35:11 +08:00
parent 9e7848b9dd
commit b4acf0b597
11 changed files with 41 additions and 86 deletions
+2 -2
View File
@@ -72,7 +72,7 @@ Release 构建使用 `./gradlew :app:assembleRelease`,默认输出未签名 AP
首次构建会下载并从源码编译依赖,耗时取决于网络。后续编译复用缓存。Android 直接编译 `deps/submodules/minirtc` 中的源码;构建产物和依赖缓存位于 `.native/`,Xmake 工程配置位于 `native/.xmake/`,与桌面和 iOS 分开保存:
- Gradle 9.3.1、AGP 9.1.0、NDK r28c 固定在工程中。
- Xmake 包仓库固定到 `eda39de3fb99b420c168f1ab9ab2d1791e11b662`。
- Xmake 依赖仓库沿用 PC 端策略:使用默认仓库或调用环境指定的仓库,不固定或校验仓库提交。Android 编译产物和安装包缓存仍独立保存。
- `scripts/build_native.py` 调用独立的 `native/xmake.lua`,直接包含 MiniRTC 子模块的构建定义。构建过程不复制 MiniRTC 源码,也不应用补丁。
- MiniRTC 源码内的 Android 分支启用 OpenH264、SVT-AV1 和 dav1d 软件编解码及依赖配方,兼容 OpenFEC 的 Android 头文件,并关闭 UPnP。SVT-AV1 使用内置 ARM CPU 能力检测;当前应用作为控制端只接收视频,库同时提供 AV1 编码能力。TLS 校验位于 MiniRTC 内部。STUN、TURN UDP/TCP 与直接连接仍由 MiniRTC 提供。
- MiniRTC 的 `thirdparty/openssl/xmake.lua` 统一维护 iOS 和 Android 配方;Android 显式使用 NDK 的归档索引工具,避免 macOS `ranlib` 损坏 ELF 静态库。
@@ -98,7 +98,7 @@ git push origin android-v1.6.1-20261010
已有 Release 需要补传服务器或刷新下载信息时,可手动运行 `Update version.json from Release` 并填写已有 `source_tag`,无需重新构建。
工作流使用 Ubuntu 24.04、JDK 17、Python 3.13、SDK 36、Build Tools 36.0.0、NDK r28c,并使用最低支持的 Xmake 3.1.1 验证构建;本地允许使用更新的 Xmake。Gradle 使用工程内的 Wrapper,原生构建器固定 Xmake 包仓库版本。SDK/NDK 使用独立目录缓存,按宿主系统、架构和工具链版本区分;命中缓存时跳过 SDK 安装,未命中时在安装完成后立即保存,即使后续 APK 构建失败,下次也可复用。Xmake 可执行环境、固定版本的包仓库和 pip 下载也有各自的缓存;Ubuntu 系统工具只安装缺失项。
工作流使用 Ubuntu 24.04、JDK 17、Python 3.13、SDK 36、Build Tools 36.0.0、NDK r28c,并使用最低支持的 Xmake 3.1.1 验证构建;本地允许使用更新的 Xmake。Gradle 使用工程内的 Wrapper,原生构建器沿用 PC 端的 Xmake 仓库选择方式。SDK/NDK 使用独立目录缓存,按宿主系统、架构和工具链版本区分;命中缓存时跳过 SDK 安装,未命中时在安装完成后立即保存,即使后续 APK 构建失败,下次也可复用。Xmake 可执行环境和 pip 下载也有各自的缓存;Ubuntu 系统工具只安装缺失项。
Gradle 缓存与 Android 原生依赖缓存分别管理;原生缓存按宿主架构、构建脚本及 MiniRTC 配方区分,不复用桌面或 iOS 的配置和目标文件。GitHub 托管 runner 每次启动仍是新环境;第一次运行或缓存失效时需要安装。不同分支和标签可读取默认分支的缓存,因此建议先在默认分支运行一次 `Build Android` 预热,再创建发布标签。
+2 -9
View File
@@ -11,7 +11,6 @@ ANDROID = Path(__file__).resolve().parents[1]
ROOT = ANDROID.parents[1]
SOURCE = ROOT / 'deps/submodules/minirtc'
CACHE = ANDROID / '.native'
PACKAGE_REVISION = 'eda39de3fb99b420c168f1ab9ab2d1791e11b662'
XMAKE_MIN_VERSION = (3, 1, 1)
@@ -38,18 +37,12 @@ def main():
raise SystemExit('Initialize the MiniRTC submodule before building.')
env = os.environ.copy()
env['XMAKE_PKG_INSTALLDIR'] = str(CACHE / 'packages')
env['XMAKE_GLOBALDIR'] = str(CACHE / 'global')
env['ANDROID_NDK_HOME'] = str(ndk)
env['ANDROID_NDK_ROOT'] = str(ndk)
env['NO_COLOR'] = '1'
work = ANDROID / 'native'
repository = CACHE / 'global/.xmake/repositories/xmake-repo'
if not (repository / '.git').is_dir():
subprocess.run([xmake, 'repo', '--update'], cwd=work, env=env, check=True)
revision = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repository, text=True).strip()
if revision != PACKAGE_REVISION:
subprocess.run(['git', 'fetch', 'origin', PACKAGE_REVISION], cwd=repository, check=True)
subprocess.run(['git', 'checkout', '--detach', PACKAGE_REVISION], cwd=repository, check=True)
# Use the desktop repository policy; Xmake manages recipe initialization
# and updates. Only installed Android packages/build products are isolated.
subprocess.run([xmake, 'f', '-P', str(work), '-y', '-p', 'android', '-a', 'arm64-v8a',
'-m', 'release', '--ndk=' + str(ndk), '--ndk_sdkver=26',
'--runtimes=c++_static', '--policies=package.precompiled:n',
+2
View File
@@ -13,6 +13,8 @@
## 构建
依赖仓库沿用 Windows/macOS/Linux 的 Xmake 策略:使用默认仓库或调用环境指定的 `XMAKE_GLOBALDIR` / `XMAKE_MAIN_REPO`,不固定或校验仓库提交。鸿蒙 PC 与移动端共用此规则,SDK、编译产物和依赖安装缓存仍按平台隔离。
在仓库根目录执行,当前构建脚本面向 macOS:
```bash
+3 -17
View File
@@ -14,7 +14,6 @@ import sys
APP = Path(__file__).resolve().parents[1]
ROOT = APP.parents[1]
CACHE = APP / '.native'
PACKAGE_REVISION = '2eedd731d1e7e377bc0eea970b9f0c120ca5f00d'
def run(args, *, cwd=APP, env=None):
@@ -37,8 +36,7 @@ def environment():
env = os.environ.copy()
env.update(NODE_HOME=str(studio / 'tools/node'), DEVECO_SDK_HOME=str(sdk),
JAVA_HOME=str(studio / 'jbr/Contents/Home'),
XMAKE_PKG_INSTALLDIR=str(CACHE / 'packages'),
XMAKE_GLOBALDIR=str(CACHE / 'global'), NO_COLOR='1')
XMAKE_PKG_INSTALLDIR=str(CACHE / 'packages'), NO_COLOR='1')
env['PATH'] = os.pathsep.join([str(CACHE / 'venv/bin'), str(studio / 'tools/node/bin'),
str(studio / 'tools/ohpm/bin'),
str(native / 'build-tools/cmake/bin'), env.get('PATH', '')])
@@ -55,20 +53,8 @@ def bootstrap(env):
run([venv / 'bin/python', '-m', 'pip', 'install', 'setuptools==80.9.0',
'wheel==0.45.1', 'meson==1.12.1'], env=env)
(venv / '.crossdesk-tools-v1').touch()
repository = CACHE / 'global/.xmake/repositories/xmake-repo'
if not (repository / '.git').exists():
repository.parent.mkdir(parents=True, exist_ok=True)
seed = Path.home() / '.xmake/repositories/xmake-repo'
source = seed if (seed / '.git').exists() else 'https://github.com/xmake-io/xmake-repo.git'
run(['git', 'clone', '--no-hardlinks', source, repository], env=env)
run(['git', 'remote', 'set-url', 'origin', 'https://github.com/xmake-io/xmake-repo.git'], cwd=repository, env=env)
revision = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repository, text=True).strip()
if revision != PACKAGE_REVISION:
run(['git', 'fetch', 'origin', PACKAGE_REVISION], cwd=repository, env=env)
run(['git', 'checkout', '--detach', PACKAGE_REVISION], cwd=repository, env=env)
# Mark this pinned checkout as ready so Xmake's first-run repository update
# cannot replace it with a mirror or advance it beyond PACKAGE_REVISION.
(repository / 'updated').touch()
# Repository selection/updates follow Xmake, as on Windows/macOS/Linux.
# The SDK, installed packages and build products remain platform-specific.
def mobile_project():
@@ -277,7 +277,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/zsh;
shellScript = "set -e\npython3 \"${PROJECT_DIR}/scripts/prepare_source_metadata.py\" --output \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SourceMetadata.json\"\n\"${PROJECT_DIR}/scripts/build_minirtc_ios.sh\"\npython3 \"${PROJECT_DIR}/scripts/verify_native_build.py\" --inputs \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/libCrossDeskMiniRTC.a.inputs.sha256\" --xmake-version \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/xmake-version.txt\" --xmake-repository \"$(cat \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/xmake-repository.txt\")\"\npython3 \"${PROJECT_DIR}/scripts/package_openssl_ios.py\" --inputs \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/libCrossDeskMiniRTC.a.inputs.sha256\" --output \"${BUILT_PRODUCTS_DIR}/OpenSSL.framework\" --platform \"${PLATFORM_NAME}\"\n";
shellScript = "set -e\npython3 \"${PROJECT_DIR}/scripts/prepare_source_metadata.py\" --output \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/SourceMetadata.json\"\n\"${PROJECT_DIR}/scripts/build_minirtc_ios.sh\"\npython3 \"${PROJECT_DIR}/scripts/verify_native_build.py\" --inputs \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/libCrossDeskMiniRTC.a.inputs.sha256\" --xmake-version \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/xmake-version.txt\"\npython3 \"${PROJECT_DIR}/scripts/package_openssl_ios.py\" --inputs \"${PROJECT_DIR}/Vendor/${PLATFORM_NAME}/${CONFIGURATION}/libCrossDeskMiniRTC.a.inputs.sha256\" --output \"${BUILT_PRODUCTS_DIR}/OpenSSL.framework\" --platform \"${PLATFORM_NAME}\"\n";
};
/* End PBXShellScriptBuildPhase section */
+11 -16
View File
@@ -72,22 +72,17 @@ tag's numeric version. Use the source tag or commit recorded in the app to
identify its exact source.
Install [Xmake](https://xmake.io/guide/quick-start.html) 3.1.1 or newer,
CMake, and a current Python 3 with setuptools/wheel. Pin the package repository
in a separate Xmake global directory before building:
CMake, and a current Python 3 with setuptools/wheel. Repository selection follows
the Windows/macOS/Linux desktop build: Xmake uses its default package repository,
or an explicit `XMAKE_GLOBALDIR` / `XMAKE_MAIN_REPO` supplied by the caller.
No repository commit is pinned, checked out, or required to have a clean worktree.
You can build directly from Xcode without preparing a separate recipe checkout.
```sh
export XMAKE_GLOBALDIR="$HOME/.cache/crossdesk/xmake-ios"
xmake repo --update
git -C "$XMAKE_GLOBALDIR/.xmake/repositories/xmake-repo" fetch origin 121109352da272cd1a3d4ed52f2dcda34f839955
git -C "$XMAKE_GLOBALDIR/.xmake/repositories/xmake-repo" checkout --detach 121109352da272cd1a3d4ed52f2dcda34f839955
```
Keep `XMAKE_GLOBALDIR` set for command-line Xcode builds. For builds launched
from the Xcode app, set it as a user-defined build setting on the target, or
pin the default `~/.xmake/repositories/xmake-repo` instead. The build checks
the minimum Xmake version, package repository commit and reviewed recipe hashes.
Application dependencies are built from source, with Xmake precompiled
package downloads disabled.
Installed iOS packages and device/simulator build products still have separate
caches to avoid mixing target architectures and deployment settings. The build
retains the minimum Xmake version check, Xmake's source-download verification,
and native archive input checks. Application dependencies are built from source,
with Xmake precompiled package downloads disabled.
1. Open `apps/ios/CrossDeskMobile.xcodeproj` and select the `CrossDeskMobile`
target and scheme.
@@ -391,7 +386,7 @@ the resource when the notices need to change; regeneration does not select a
new dependency version.
`scripts/verify_native_build.py` independently checks the native archive input
hashes and pinned Xmake toolchain after compilation. These checks do not read
hashes and the minimum supported Xmake version after compilation. These checks do not read
the license catalog. Downloaded source archives retain their SHA-256 checks
when manually regenerating notices.
+8 -3
View File
@@ -67,10 +67,15 @@ fi
XMAKE_DEVELOPER_DIR="${DEVELOPER_DIR:-$(xcode-select -p)}"
XMAKE_TOOLCHAIN_BIN="${XMAKE_DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin"
run_xmake() {
# Match desktop repository selection: use Xmake defaults unless explicitly
# overridden by the caller. Only compiled iOS packages use a separate cache.
local xmake_env=()
if [[ -n "${XMAKE_GLOBALDIR:-}" ]]; then
xmake_env+=("XMAKE_GLOBALDIR=${XMAKE_GLOBALDIR}")
fi
if [[ -n "${XMAKE_MAIN_REPO:-}" ]]; then
xmake_env+=("XMAKE_MAIN_REPO=${XMAKE_MAIN_REPO}")
fi
/usr/bin/env -i \
HOME="${HOME}" \
PATH="${XMAKE_TOOLCHAIN_BIN}:${PATH}" \
@@ -89,10 +94,10 @@ run_xmake() {
OUTPUT_DIR="${IOS_DIR}/Vendor/${SDK_NAME}/${CONFIG_NAME}"
OUTPUT_LIBRARY="${OUTPUT_DIR}/libCrossDeskMiniRTC.a"
XMAKE_REPOSITORY_DIR="$(run_xmake lua -c 'import("core.base.global"); print(path.join(global.directory(), "repositories", "xmake-repo"))')"
mkdir -p "${OUTPUT_DIR}"
print -r -- "${XMAKE_REPOSITORY_DIR}" > "${OUTPUT_DIR}/xmake-repository.txt"
run_xmake --version > "${OUTPUT_DIR}/xmake-version.txt"
python3 -B "${SCRIPT_DIR}/verify_native_build.py" \
--xmake-version "${OUTPUT_DIR}/xmake-version.txt"
MINIRTC_BUILD_DIR="${IOS_DIR}/.xmake/minirtc-build${CACHE_SUFFIX}"
MINIRTC_LIBRARY="${MINIRTC_BUILD_DIR}/iphoneos/arm64/${MODE}/libminirtc.a"
WIRE_BUILD_DIR="${IOS_DIR}/.xmake/wire-build${CACHE_SUFFIX}"
@@ -109,7 +114,7 @@ fi
# Still configure on every invocation: Xmake must see manifest edits and restore
# the iOS configuration if MiniRTC was built standalone for another platform.
CONFIG_SIGNATURE="$(print -r -- "${XMAKE_BIN}" "${XMAKE_DEVELOPER_DIR}" \
"${MODE}" "${ARCH_NAME}" "${SDK_NAME}" "${APPLE_DEVICE}" "16.0" "${XMAKE_PKG_INSTALLDIR}" "${MINIRTC_ENABLE_AOM}"
"${MODE}" "${ARCH_NAME}" "${SDK_NAME}" "${APPLE_DEVICE}" "16.0" "${XMAKE_PKG_INSTALLDIR}" "${MINIRTC_ENABLE_AOM}" "${XMAKE_GLOBALDIR:-}" "${XMAKE_MAIN_REPO:-}"
run_xmake --version | sed -n '1p'
DEVELOPER_DIR="${XMAKE_DEVELOPER_DIR}" xcodebuild -version
DEVELOPER_DIR="${XMAKE_DEVELOPER_DIR}" xcrun --sdk "${SDK_NAME}" --show-sdk-path
+5 -18
View File
@@ -5,28 +5,16 @@ import argparse
import hashlib
from pathlib import Path
import re
import subprocess
import sys
XMAKE_MIN_VERSION = "3.1.1"
XMAKE_REPOSITORY_REVISION = "121109352da272cd1a3d4ed52f2dcda34f839955"
def verify(inputs=None, xmake_repository=None, xmake_version=None):
def verify(inputs=None, xmake_version=None):
if xmake_version is not None:
version = re.search(r"xmake v(\d+)\.(\d+)\.(\d+)(?:\+|[,\s]|$)", xmake_version.read_text())
if not version or tuple(map(int, version.groups())) < tuple(map(int, XMAKE_MIN_VERSION.split("."))):
raise ValueError(f"Xmake {XMAKE_MIN_VERSION} or newer is required; see apps/ios/README.md")
if xmake_repository is not None:
revision = subprocess.check_output(
["git", "-C", str(xmake_repository), "rev-parse", "HEAD"], text=True).strip()
if revision != XMAKE_REPOSITORY_REVISION:
raise ValueError("Xmake package repository differs from the pinned iOS toolchain")
changes = subprocess.check_output(
["git", "-C", str(xmake_repository), "status", "--porcelain", "--untracked-files=normal"],
text=True).strip()
if changes:
raise ValueError("Xmake package repository has local changes; use the unmodified pinned revision")
if inputs is not None:
for line in inputs.read_text().splitlines():
sha, name = line.split(maxsplit=1)
@@ -37,18 +25,17 @@ def verify(inputs=None, xmake_repository=None, xmake_version=None):
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--inputs", type=Path, help="native archive .inputs.sha256 manifest")
parser.add_argument("--xmake-repository", type=Path, help="active pinned Xmake package repository")
parser.add_argument("--xmake-version", type=Path, help="Xmake version output recorded by the native build")
args = parser.parse_args()
if not any((args.inputs, args.xmake_repository, args.xmake_version)):
parser.error("provide --inputs, --xmake-repository or --xmake-version")
verify(args.inputs, args.xmake_repository, args.xmake_version)
if not any((args.inputs, args.xmake_version)):
parser.error("provide --inputs or --xmake-version")
verify(args.inputs, args.xmake_version)
print("Verified iOS native build inputs and toolchain")
if __name__ == "__main__":
try:
main()
except (OSError, ValueError, subprocess.CalledProcessError) as error:
except (OSError, ValueError) as error:
print(f"iOS native build: {error}", file=sys.stderr)
sys.exit(1)
+3
View File
@@ -22,6 +22,9 @@ class NativeBuildTest(unittest.TestCase):
source = Path(__file__).resolve().parents[1] / "scripts/build_minirtc_ios.sh"
self.script = scripts / source.name
shutil.copy2(source, self.script)
# This fixture exercises archive/configuration behavior with fake Xmake.
# Keep the version-check dependency inside the same temporary sandbox.
(scripts / "verify_native_build.py").write_text("# Toolchain validation is outside this fixture's scope.\n")
(self.root / "xmake.lua").write_text('-- fixture\n')
(self.root / "deps/submodules/minirtc").mkdir(parents=True)
self.bin = self.root / "bin"