Skip to content

[General] Add a C++ ABI layout check for stable-API headers - #60298

Draft
chrfalch wants to merge 1 commit into
mainfrom
abi-break-detection
Draft

chrfalch wants to merge 1 commit into
mainfrom
abi-break-detection

Conversation

@chrfalch

Copy link
Copy Markdown
Collaborator

Summary:

React Native has no check for ABI breaks. An ABI break is a change in the size or memory layout of a public C++ type that breaks code compiled against an earlier release, such as a library built for 0.88.0 running with 0.88.1. The existing API snapshots record names and signatures, not sizes or field offsets.

Between 0.87 and 0.88, facebook::yoga::Style shrank from 280 to 160 bytes. This changed the layout of YogaStylableProps and BaseViewProps, and no existing check caught it.

This PR adds scripts/abi-check, a local tool that catches this kind of break. It does not run in CI yet; a follow-up PR adds the workflow.

What it does:

  1. It selects the stable-API headers: the ones that include UmbrellaGuard.h or FrameworksGuard.h, with the exclude patterns from scripts/cxx-api/config.yml.
  2. It compiles them with clang and dumps each record layout (size, field offsets), each vtable (virtual method order), and each enum's values, in the facebook::react, facebook::yoga and facebook::jsi namespaces.
  3. It compares two versions and reports types that changed or were removed. Added types are counted, not reported as breaks.
  4. It runs separately for each platform (iOS, Android) and build type (Debug, Release), because each one has its own layout.
  5. The baseline comes from the published Maven artifacts: the iOS headers and core packages, and the Android react-android AAR plus fbjni. Downloads are cached and checked against their Maven SHA-1. The other side is a published version or a source checkout. For a checkout, the iOS header layout is built with the existing scripts/ios-prebuild code, and the Android layout comes from the prefab rules in ReactAndroid/build.gradle.kts.
  6. Some published headers do not compile by themselves. On iOS 0.87.1 to 0.88.1, 17 headers fail because the prebuilt package flattens subfolders ([iOS] Keep subfolders and fix missing includes in the prebuilt headers package #60295 fixes the packaging). Such headers are skipped only through a reviewed list, skipped-headers.js. Each entry gives a reason and, optionally, the releases it applies to. Any other compile failure stops the run.

Usage:

node scripts/abi-check/cli.js --platform ios|android --build-type debug|release \
  --base <version> --current <version>|<checkout folder> [--cache-dir <dir>] [--json]

Exit code 0 means no breaks, 1 means breaks were found, and 2 means bad arguments or a tool error.

Changelog:

[INTERNAL] [ADDED] - Add scripts/abi-check, a local C++ ABI layout check for stable-API headers

Test Plan:

Unit tests (offline; tests that run clang use the host clang):

yarn jest --no-cache -i scripts/abi-check

Result: 10 suites, 91 tests passed. yarn flow-check, ESLint and Prettier are clean on scripts/abi-check.

Real comparisons, each run on iOS and Android, Debug and Release (iOS needs Xcode; Android needs NDK 28.2.13676358):

Comparison Expected Result
v0.88.1 source checkout vs published 0.88.1 0 differences 0 on all 4 (iOS 237 headers, 1159–1166 types; Android 184 headers, 980–987 types)
published 0.88.0 vs published 0.88.1 0 breaks 0 on all 4
published 0.87.1 vs published 0.88.1 the Yoga break yoga::Style, YogaStylableProps, BaseViewProps reported changed on all 4

Example:

node scripts/abi-check/cli.js --platform android --build-type release --base 0.87.1 --current 0.88.1

This exits with 1 and lists L facebook::yoga::Style among the breaks.

Not run: CI integration (a follow-up PR), and the exported-symbol and Java/Kotlin checks (also a follow-up PR).

React Native has no check for ABI breaks: changes in the size or memory
layout of public C++ types that break code compiled against an earlier
release. Between 0.87 and 0.88, facebook::yoga::Style shrank from 280 to
160 bytes, which changed YogaStylableProps and BaseViewProps, and no
existing check caught it.

scripts/abi-check compiles the stable-API headers with clang, dumps the
record, vtable and enum layouts, and compares two versions per platform
(iOS, Android) and build type (Debug, Release). The baseline comes from
the published Maven artifacts; the other side is a published version or a
source checkout. Headers that do not compile in a published layout are
skipped only through a reviewed list.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant