diff --git a/.github/upstream-sync-state.json b/.github/upstream-sync-state.json index 7f99e8ae..7a30ddcd 100644 --- a/.github/upstream-sync-state.json +++ b/.github/upstream-sync-state.json @@ -2,8 +2,47 @@ "upstream_repo": "x86sim/x86sim", "upstream_branch": "main", "upstream_sha": "a3de699718c87d5d4dfd566b34b7de32f3f148cd", - "maintained_branch": "main", + "maintained_branch": "verify/upstream-sync-e2e", + "maintained_base_sha": "5a4f4f8291d19dda0237228fb43e996ffa8794c3", + "commits_merged": 2, "latest_upstream_release": "v0.11.0", - "synced_at_utc": "2026-12-05T07:48:00Z", - "status": "initialized" + "recent_upstream_releases": [ + { + "tag": "v0.11.0", + "name": "x86Sim v0.11.0", + "prerelease": false, + "published_at": "2026-12-04T08:43:11Z", + "url": "https://github.com/x86sim/x86sim/releases/tag/v0.11.0" + }, + { + "tag": "v0.10.2", + "name": "x86Sim v0.10.2", + "prerelease": false, + "published_at": "2026-12-03T19:44:02Z", + "url": "https://github.com/x86sim/x86sim/releases/tag/v0.10.2" + }, + { + "tag": "v0.10.1", + "name": "x86Sim v0.10.1", + "prerelease": false, + "published_at": "2026-12-03T00:36:49Z", + "url": "https://github.com/x86sim/x86sim/releases/tag/v0.10.1" + }, + { + "tag": "v0.10.0", + "name": "x86Sim v0.10.0", + "prerelease": false, + "published_at": "2026-12-02T20:30:46Z", + "url": "https://github.com/x86sim/x86sim/releases/tag/v0.10.0" + }, + { + "tag": "v0.9.0", + "name": "x86Sim v0.9.0", + "prerelease": false, + "published_at": "2026-12-02T08:10:21Z", + "url": "https://github.com/x86sim/x86sim/releases/tag/v0.9.0" + } + ], + "synced_at_utc": "2026-12-05T08:08:12.836047+00:00", + "status": "pending_review" } diff --git a/tests/dev/rust_e2e.py b/tests/dev/rust_e2e.py index 82b16a5b..65b3fd49 100755 --- a/tests/dev/rust_e2e.py +++ b/tests/dev/rust_e2e.py @@ -8,8 +8,9 @@ "Tap me" turns "Taps: 0" into "Taps: 1". tauri tauri-hello: Tauri 2 (tao + WKWebView, Tauri's Swift half built with Linux Swift). The page's heading is in the snapshot; tapping "Greet" calls the Rust command, whose answer appears on the page. - dioxus dioxus-hello: Dioxus mobile (tao + WKWebView, no dx). "Dioxus on x86Sim" in the snapshot; a - tap on "Count" turns "Count: 0" into "Count: 1". + dioxus dioxus-hello: Dioxus mobile (tao 0.34 + WKWebView, the scene adapter, no dx). "Dioxus on x86Sim" in the + snapshot; a tap on "Count" turns "Count: 0" into "Count: 1". + Both: the web view fills the screen (a window sized before it had a scene left it a strip). bevy bevy-hello: Bevy 0.20 (winit 0.30 + wgpu on Metal, the scene adapter). No accessibility: the snapshot reads "Bevy on x86Sim" by OCR; a tap on "Taps: 0" (found by OCR) turns it into "Taps: 1". @@ -30,12 +31,12 @@ SAMPLES_DIR = os.path.join(ROOT, "tests/dev/samples") -# name: (sample dir, text that shows the UI is up, what to tap, the text the tap brings, use OCR) +# name: (sample dir, text that shows the UI is up, what to tap, the text the tap brings, use OCR, its UI is a web view) SAMPLES = { - "hello": ("rust/hello-uikit", "Hello from Rust", "Tap me", "Taps: 1", False), - "tauri": ("rust/tauri-hello", "Tauri on x86Sim", "Greet", "Hello from Rust, x86Sim!", False), - "dioxus": ("rust/dioxus-hello", "Dioxus on x86Sim", "Count", "Count: 1", False), - "bevy": ("rust/bevy-hello", "Bevy on x86Sim", "Taps: 0", "Taps: 1", True), + "hello": ("rust/hello-uikit", "Hello from Rust", "Tap me", "Taps: 1", False, False), + "tauri": ("rust/tauri-hello", "Tauri on x86Sim", "Greet", "Hello from Rust, x86Sim!", False, True), + "dioxus": ("rust/dioxus-hello", "Dioxus on x86Sim", "Count", "Count: 1", False, True), + "bevy": ("rust/bevy-hello", "Bevy on x86Sim", "Taps: 0", "Taps: 1", True, False), } @@ -56,28 +57,34 @@ def phone_state(self): return None def labels(self, ocr): + """(the snapshot's text, each element's label and value, the snapshot)""" text, st, err, _ = self.m.call("snapshot", json=True, ocr=ocr) if err: - return text, [] - return text, [(e.get("label") or "") + " " + (e.get("value") or "") for e in (st or {}).get("elements", [])] + return text, [], {} + return text, [(e.get("label") or "") + " " + (e.get("value") or "") for e in (st or {}).get("elements", [])], st or {} def sample(self, name): - rel, up, tap, after, ocr = SAMPLES[name] + rel, up, tap, after, ocr, web = SAMPLES[name] proj = os.path.join(SAMPLES_DIR, rel) t0 = time.monotonic() text, st, err, dt = self.m.call("dev_run", project=proj) if not self.check(f"{name}: built on Linux, installed and launched", not err, "%.0f s: %s" % (dt, text[-600:].replace("\n", " | "))): return self.m.call("wait_for", target=up, timeout=120) - snap, lab = self.labels(ocr) + snap, lab, st = self.labels(ocr) # OCR may get the case of a letter wrong ("Bevy On x86Sim") seen = (lambda l: up.lower() in l.lower()) if ocr else (lambda l: up in l) self.check(f"{name}: the snapshot shows its UI", any(seen(l) for l in lab), "%r in %s" % (up, [l for l in lab if l.strip()][:12])) + if web: + views = [e["frame"] for e in st.get("elements", []) if e.get("role") == "webview"] + full = [0, 0] + list(st.get("screen") or []) + fills = len(full) == 4 and any(all(abs(a - b) <= 1 for a, b in zip(f, full)) for f in views) + self.check(f"{name}: the web view fills the screen", fills, "web view %s, screen %s" % (views, full[2:])) text, _, err, _ = self.m.call("tap", target=tap) self.check(f"{name}: tap {tap!r}", not err, text[:200].replace("\n", " | ")) text, _, err, _ = self.m.call("wait_for", target=after, timeout=30) if err: - _, lab = self.labels(ocr) + _, lab, _ = self.labels(ocr) err = not any(after in l for l in lab) self.check(f"{name}: the tap changed the app ({after!r})", not err, "%.0f s total" % (time.monotonic() - t0)) diff --git a/tools/dev/rust/scene-adapter.m b/tools/dev/rust/scene-adapter.m index 0758c47f..05c3ea19 100644 --- a/tools/dev/rust/scene-adapter.m +++ b/tools/dev/rust/scene-adapter.m @@ -3,20 +3,48 @@ // when it adopts scenes, and a window that belongs to no scene is never shown. // // x86sim dev's Rust build (core dev/build/rust.rs) links this object into such an app and names RustSceneAdapter as the scene delegate in the Info.plist. -// Windows made before the scene connects are attached to it when it does; windows made later join it at once. -// The library's own lifecycle keeps working: UIKit still posts the UIApplication notifications (did become active, ...) -// that winit observes, and the scene's activation callbacks are passed on to the app delegate's +// +// These libraries make their windows when the app has finished launching, which under scenes is before the first +// scene connects. A window without a scene has no place on a screen: UIKit converts its bounds to the screen's +// coordinates as an empty rect, and both tao and winit size their root view from that conversion when they make the +// window (tao 0.34 left a web view 0x0, which its autoresizing mask then grew back into a strip a third of the screen +// wide). So the library's launch handling is held until the first scene connects, as tao 0.37 does itself: the app +// delegate's application:didFinishLaunchingWithOptions: (tao) and the app's own block observers of +// UIApplicationDidFinishLaunchingNotification (winit). Its windows then join the scene as they are made. +// A window made earlier still (before UIApplicationMain) waits and is attached when the scene connects. +// The rest of the library's lifecycle keeps working: UIKit still posts the UIApplication notifications (did become +// active, ...) that winit observes, and the scene's activation callbacks are passed on to the app delegate's // applicationDidBecomeActive: & co., which UIKit no longer calls under scenes (tao before 0.37 waits for those). #import +#import #import static NSHashTable *rsa_waiting; static __weak UIWindowScene *rsa_scene; +static NSMutableArray *rsa_held; // the launch handling to run when the first scene connects; nil after @interface RustSceneAdapter : UIResponder @property (strong, nonatomic) UIWindow *window; @end +static void rsa_attach(UIWindow *w, UIWindowScene *scene) { + w.windowScene = scene; + RustSceneAdapter *d = (RustSceneAdapter *)scene.delegate; + if ([d isKindOfClass:[RustSceneAdapter class]] && !d.window) { + d.window = w; + } +} + +// Keeps `launch` to run when the first scene connects; NO (not kept) once one has +static BOOL rsa_hold(void (^launch)(void)) { + [rsa_held addObject:[launch copy]]; + return rsa_held != nil; +} + +static void rsa_exchange(Class c, SEL original, SEL adapter) { + method_exchangeImplementations(class_getInstanceMethod(c, original), class_getInstanceMethod(c, adapter)); +} + @interface UIWindow (RustSceneAdapter) - (instancetype)rsa_initWithFrame:(CGRect)frame; @end @@ -27,7 +55,7 @@ - (instancetype)rsa_initWithFrame:(CGRect)frame { if (w && !w.windowScene) { UIWindowScene *scene = rsa_scene; if (scene) { - w.windowScene = scene; + rsa_attach(w, scene); } else { [rsa_waiting addObject:w]; } @@ -36,13 +64,68 @@ - (instancetype)rsa_initWithFrame:(CGRect)frame { } @end +// the app delegate's own application:didFinishLaunchingWithOptions:, kept under this name +@interface NSObject (RustSceneAdapter) +- (BOOL)rsa_application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options; +@end + +static BOOL rsa_didFinishLaunching(id self, SEL _cmd, UIApplication *app, NSDictionary *options) { + if (rsa_hold(^{ [self rsa_application:app didFinishLaunchingWithOptions:options]; })) { + return YES; + } + return [self rsa_application:app didFinishLaunchingWithOptions:options]; +} + +@interface UIApplication (RustSceneAdapter) +- (void)rsa_setDelegate:(id)delegate; +@end + +@implementation UIApplication (RustSceneAdapter) +- (void)rsa_setDelegate:(id)delegate { + Class c = [delegate class]; + SEL launch = @selector(application:didFinishLaunchingWithOptions:), kept = @selector(rsa_application:didFinishLaunchingWithOptions:); + Method m = class_getInstanceMethod(c, launch); + if (m && !class_getInstanceMethod(c, kept)) { + class_addMethod(c, kept, method_getImplementation(m), method_getTypeEncoding(m)); + class_replaceMethod(c, launch, (IMP)rsa_didFinishLaunching, method_getTypeEncoding(m)); + } + [self rsa_setDelegate:delegate]; // the original -setDelegate: +} +@end + +// Whether a block's code is in the app's executable (where this adapter and the Rust library are linked), not in a system framework +static BOOL rsa_in_app(id block) { + struct { void *isa; int flags, reserved; void *invoke; } *b = (__bridge void *)block; + Dl_info code, me; + return dladdr(b->invoke, &code) && dladdr((void *)rsa_in_app, &me) && code.dli_fbase == me.dli_fbase; +} + +@interface NSNotificationCenter (RustSceneAdapter) +- (id)rsa_addObserverForName:(NSNotificationName)name object:(id)object queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block; +@end + +@implementation NSNotificationCenter (RustSceneAdapter) +- (id)rsa_addObserverForName:(NSNotificationName)name object:(id)object queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block { + if (rsa_held && block && [name isEqualToString:UIApplicationDidFinishLaunchingNotification] && rsa_in_app(block)) { + void (^observer)(NSNotification *) = block; + block = ^(NSNotification *note) { + if (!rsa_hold(^{ observer(note); })) { + observer(note); + } + }; + } + return [self rsa_addObserverForName:name object:object queue:queue usingBlock:block]; // the original +} +@end + @implementation RustSceneAdapter + (void)load { rsa_waiting = [NSHashTable weakObjectsHashTable]; - Method original = class_getInstanceMethod([UIWindow class], @selector(initWithFrame:)); - Method adapter = class_getInstanceMethod([UIWindow class], @selector(rsa_initWithFrame:)); - method_exchangeImplementations(original, adapter); + rsa_held = [NSMutableArray array]; + rsa_exchange([UIWindow class], @selector(initWithFrame:), @selector(rsa_initWithFrame:)); + rsa_exchange([UIApplication class], @selector(setDelegate:), @selector(rsa_setDelegate:)); + rsa_exchange([NSNotificationCenter class], @selector(addObserverForName:object:queue:usingBlock:), @selector(rsa_addObserverForName:object:queue:usingBlock:)); } - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)options { @@ -52,13 +135,15 @@ - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session op UIWindowScene *ws = (UIWindowScene *)scene; rsa_scene = ws; for (UIWindow *w in rsa_waiting.allObjects) { - w.windowScene = ws; - if (!self.window) { - self.window = w; - } + rsa_attach(w, ws); [w makeKeyAndVisible]; } [rsa_waiting removeAllObjects]; + NSArray *held = rsa_held; + rsa_held = nil; + for (void (^launch)(void) in held) { + launch(); + } } static void rsa_forward(SEL sel) { diff --git a/tools/launcher/core/src/dev/build/rust.rs b/tools/launcher/core/src/dev/build/rust.rs index acb435b4..152f8dcf 100644 --- a/tools/launcher/core/src/dev/build/rust.rs +++ b/tools/launcher/core/src/dev/build/rust.rs @@ -9,7 +9,8 @@ //! //! iOS 27 launches apps built with its SDK only with the scene life cycle: an app names its scene delegate in //! info-plist; tao 0.37+ (Tauri 2.12) has TaoSceneDelegate to name; older tao (Dioxus 0.7) and winit before 0.31 (Bevy) -//! make windows the old way, so RustSceneAdapter (tools/dev/rust/scene-adapter.m) attaches them to the scene. +//! make windows the old way, so RustSceneAdapter (tools/dev/rust/scene-adapter.m) attaches them to the scene, and +//! holds the library's launch handling until the scene connects (a window sized without a scene is sized 0x0). //! //! Tauri 2 apps (what `tauri ios build` and its Xcode project do): the crate's staticlib linked with a main() that //! calls start_app, tauri's Swift half (mobile/ios-api) built with Linux Swift for the iOS triple, the frontend built