Skip to content

RFC: Native iOS code coverage support#83

Draft
mfazekas wants to merge 5 commits intocallstackincubator:mainfrom
mfazekas:feat/native-ios-coverage
Draft

RFC: Native iOS code coverage support#83
mfazekas wants to merge 5 commits intocallstackincubator:mainfrom
mfazekas:feat/native-ios-coverage

Conversation

@mfazekas
Copy link
Copy Markdown
Contributor

@mfazekas mfazekas commented Mar 25, 2026

Summary

Adds native iOS code coverage (LLVM profiling) for Swift/ObjC code exercised by harness tests. Users specify which pods to instrument in rn-harness.config.mjs — no Podfile changes required.

Tested end-to-end with rive-nitro-react-native (RNRive + RiveRuntime pods), producing valid lcov output covering 37 source files.

Changes

  • New @react-native-harness/coverage-ios package with auto-linked pod and CocoaPods post-install hook
  • Hook reads config directly (no dependency on config package schema version), injects coverage flags, patches app xcconfig with -force_load and -fprofile-instr-generate
  • coverage-collector.ts in platform-ios handles profraw merge and lcov export, including Xcode 16+ debug dylib binaries
  • Harness dispose flow collects native coverage before teardown

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 25, 2026

@mfazekas is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@mfazekas mfazekas force-pushed the feat/native-ios-coverage branch from 6a33bbf to 8cd29d8 Compare March 25, 2026 13:23
@mfazekas
Copy link
Copy Markdown
Contributor Author

@V3RON any feedback on this PR adding native code coverage?!

@V3RON
Copy link
Copy Markdown
Contributor

V3RON commented Mar 27, 2026

Hey @mfazekas 👋
I had to finish some other tasks first, but I'll try to go through it over the weekend and get back to you on Sunday.

Comment thread packages/coverage-ios/HarnessCoverage.podspec Outdated
Comment thread packages/coverage-ios/package.json
Comment on lines +17 to +30
def resolve_coverage_pods
project_dir = Dir.pwd
config_json = `node -e "
import('#{project_dir}/rn-harness.config.mjs')
.then(m => console.log(JSON.stringify(
m.default?.coverage?.native?.ios?.pods || []
)))
.catch(() => console.log('[]'))
"`.strip
JSON.parse(config_json)
rescue => e
Pod::UI.warn "[HarnessCoverage] Failed to read config: #{e.message}"
[]
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we can do something about this. It doesn't seem right to assume the structure of the config file. Maybe we should create a separate reac-config.ts file, include the types from the config package there, and run that instead of using this inlined script?

mfazekas added 2 commits May 7, 2026 15:43
Add LLVM source-based profiling for native Swift/ObjC code via a new
@react-native-harness/coverage-ios package. Users specify pods to
instrument in rn-harness.config.mjs and coverage flags are injected
automatically at pod install time via Module.prepend on Pod::Installer.
Fix repo URLs (margelo -> callstackincubator) and extract config
loading into a separate script using @react-native-harness/config.
@mfazekas mfazekas force-pushed the feat/native-ios-coverage branch from 8cd29d8 to 4035c23 Compare May 7, 2026 14:14
mfazekas added 3 commits May 8, 2026 07:16
- Guard podspec require_relative and install_modules_dependencies
- Add @objc name annotation to prevent Swift name mangling
- Defer +load class lookup to main queue for Xcode 16+ dylib compat
- Read config directly instead of through Zod-validated schema
- Patch app xcconfig with -force_load and -fprofile-instr-generate
The harness reinstalls the app between test files, wiping the app
container. Move profraw output to /tmp/harness-coverage/ which persists
across app reinstalls on the simulator. Clean the directory at test run
start and after collection.
The direct config reading was a workaround for testing with the old
published config package. Since this PR updates the config schema,
they'll be published together and getConfig() will work correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants