rocr: rusto-rs 源码入库(上游 v0.2.5 基线 57609fc + 本地补丁)
- 源码 316 文件收编为 rusto-rs/ 文件夹,随本仓库管理 - 移除内部 .git(补丁已存档 docs/rusto-rs-metal-patch-20260912.patch,上游可随时 re-clone) - target/ 与 docs/.yarn 缓存不入库;本地改动:ROCR_* 环境变量调优 + Metal 链接修复 + 预处理测试脚本
This commit is contained in:
1 parent
98b9599ffd
commit
c303c315e5
316 files changed
+76049
-6
No files matched your search
+131
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env bash
|
||||
# Stage release-native artifacts after react-native-rusto.tgz installation.
|
||||
# Never publish staged binaries in npm; CI injects them into a disposable example.
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
cat >&2 <<'USAGE'
|
||||
Usage:
|
||||
patch-rn-example-artifacts.sh --platform android|ios --app DIR --core FILE --model FILE --version VERSION [--model-pod NAME]
|
||||
USAGE
|
||||
exit 2
|
||||
}
|
||||
platform= app= core= model= version= model_pod=
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--platform) shift; (($#)) || usage; platform=$1; shift ;;
|
||||
--app) shift; (($#)) || usage; app=$1; shift ;;
|
||||
--core) shift; (($#)) || usage; core=$1; shift ;;
|
||||
--model) shift; (($#)) || usage; model=$1; shift ;;
|
||||
--version) shift; (($#)) || usage; version=$1; shift ;;
|
||||
--model-pod) shift; (($#)) || usage; model_pod=$1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
[[ -n "$platform" && -n "$app" && -n "$core" && -n "$model" && -n "$version" ]] || usage
|
||||
[[ -d "$app/node_modules/react-native-rusto" ]] || { echo "react-native-rusto is not installed: $app" >&2; exit 1; }
|
||||
[[ -s "$core" && -s "$model" ]] || { echo "missing staged release artifact" >&2; exit 1; }
|
||||
|
||||
case "$platform" in
|
||||
android)
|
||||
[[ "$core" == *.aar && "$model" == *.aar ]] || { echo "Android requires .aar artifacts" >&2; exit 1; }
|
||||
libs="$app/node_modules/react-native-rusto/android/libs"
|
||||
rm -rf "$libs"
|
||||
mkdir -p "$libs"
|
||||
cp "$core" "$model" "$libs/"
|
||||
test "$(find "$libs" -maxdepth 1 -name '*.aar' | wc -l | tr -d ' ')" = 2
|
||||
# Artifact mode must win before bridge's JitPack fallback.
|
||||
grep -Fq 'else if (hasLocalAar)' "$app/node_modules/react-native-rusto/android/build.gradle"
|
||||
! grep -Fq "include ':rusto-android'" "$app/android/settings.gradle"
|
||||
;;
|
||||
ios)
|
||||
[[ "$core" == *.zip && "$model" == *.zip && -n "$model_pod" ]] || {
|
||||
echo "iOS requires core/model .zip plus --model-pod" >&2; exit 1;
|
||||
}
|
||||
core_pod="${RUSTO_IOS_CORE_POD_DIR:-packages/ios}"
|
||||
test -f "$core_pod/RustO.podspec"
|
||||
rm -rf "$core_pod/RustO.xcframework"
|
||||
unzip -q "$core" 'RustO.xcframework/*' -d "$core_pod"
|
||||
test -d "$core_pod/RustO.xcframework"
|
||||
# Fail before CocoaPods/Xcode if downloaded archive and checked-out Swift
|
||||
# bridge use different FFI generations. Inspect every static library slice.
|
||||
for archive in "$core_pod"/RustO.xcframework/*/libRustoCore.a; do
|
||||
test -f "$archive"
|
||||
# `nm` on Linux cannot parse Mach-O object members. `strings` is portable
|
||||
# and sufficient here: Rust's exported no_mangle FFI names are literal.
|
||||
symbols="$(strings "$archive")"
|
||||
for symbol in \
|
||||
rocr_initialize rocr_detect_text_file rocr_detect_text_data \
|
||||
rocr_detect_text_file_spatial rocr_detect_text_data_spatial \
|
||||
rocr_free_results rocr_free_string rocr_free rocr_version; do
|
||||
grep -Fxq "_$symbol" <<<"$symbols" || {
|
||||
echo "::error::Staged RustO XCFramework ABI mismatch: $archive lacks $symbol" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
done
|
||||
|
||||
model_dir="$app/ios/.rusto-artifacts/$model_pod"
|
||||
rm -rf "$model_dir"
|
||||
mkdir -p "$model_dir"
|
||||
model_dir="$(cd "$model_dir" && pwd)"
|
||||
unzip -q "$model" -d "$model_dir"
|
||||
cp "$core_pod/models/$model_pod.podspec" "$model_dir/$model_pod.podspec"
|
||||
python3 - "$version" "$core_pod/RustO.podspec" "$model_dir/$model_pod.podspec" <<'PY'
|
||||
import re, sys
|
||||
version, *paths = sys.argv[1:]
|
||||
# Podspec aligns fields with spaces (`s.version =`), so whitespace
|
||||
# must be accepted between `version` and `=`. Restrict replacement to first
|
||||
# assignment; source URLs using `s.version` stay unchanged.
|
||||
pattern = re.compile(r"(s\.version\s*=\s*)['\"][^'\"]+['\"]")
|
||||
for path in paths:
|
||||
text = open(path).read()
|
||||
changed, count = pattern.subn(rf"\g<1>'{version}'", text, count=1)
|
||||
if count != 1:
|
||||
raise SystemExit(f"no version declaration in {path}")
|
||||
open(path, 'w').write(changed)
|
||||
PY
|
||||
podfile="$app/ios/Podfile"
|
||||
marker="# RustO CI artifact model override"
|
||||
python3 - "$podfile" "$marker" "$model_pod" "$model_dir" <<'PY'
|
||||
import sys
|
||||
path, marker, pod, directory = sys.argv[1:]
|
||||
text = open(path).read()
|
||||
line = f" pod '{pod}', :path => '{directory}'"
|
||||
text = '\n'.join(x for x in text.split('\n') if marker not in x and not x.strip().startswith(f"pod '{pod}',"))
|
||||
needle = " # Stage RustO.xcframework from Build & Release before pod install.\n"
|
||||
if needle not in text:
|
||||
raise SystemExit('missing RustO local-pod marker in Podfile')
|
||||
text = text.replace(needle, needle + f" {marker}\n" + line + "\n", 1)
|
||||
open(path, 'w').write(text)
|
||||
PY
|
||||
grep -Fq "pod '$model_pod', :path => '$model_dir'" "$podfile"
|
||||
|
||||
# Old packed npm artifacts used `s.pod_target_xcconfig` as both writer and
|
||||
# reader. Current CocoaPods only exposes writer. Patch only disposable
|
||||
# node_modules copy used by release-artifact validation.
|
||||
bridge_podspec="$app/node_modules/react-native-rusto/react-native-rusto.podspec"
|
||||
if grep -Fq 's.pod_target_xcconfig ||' "$bridge_podspec"; then
|
||||
python3 - "$bridge_podspec" <<'PY'
|
||||
import re, sys
|
||||
path = sys.argv[1]
|
||||
text = open(path).read()
|
||||
old = " s.pod_target_xcconfig = {\n 'DEFINES_MODULE' => 'YES',\n 'SWIFT_COMPILATION_MODE' => 'wholemodule'\n }"
|
||||
new = " pod_target_xcconfig = {\n 'DEFINES_MODULE' => 'YES',\n 'SWIFT_COMPILATION_MODE' => 'wholemodule'\n }"
|
||||
if old not in text:
|
||||
raise SystemExit('legacy podspec base xcconfig block not found')
|
||||
text = text.replace(old, new, 1)
|
||||
text = text.replace('s.pod_target_xcconfig = (s.pod_target_xcconfig || {}).merge({', 'pod_target_xcconfig = pod_target_xcconfig.merge({', 1)
|
||||
needle = '\nend\n'
|
||||
if 's.pod_target_xcconfig = pod_target_xcconfig' not in text:
|
||||
if not text.endswith(needle):
|
||||
raise SystemExit('unexpected podspec terminator')
|
||||
text = text[:-len(needle)] + '\n s.pod_target_xcconfig = pod_target_xcconfig\nend\n'
|
||||
open(path, 'w').write(text)
|
||||
PY
|
||||
! grep -Fq 's.pod_target_xcconfig ||' "$bridge_podspec"
|
||||
grep -Fq 's.pod_target_xcconfig = pod_target_xcconfig' "$bridge_podspec"
|
||||
fi
|
||||
;;
|
||||
*) usage ;;
|
||||
esac
|
||||
Reference in new issue
Block a user