Repository navigation
Objective-C app targets: React Native headers by bare name, C++ standard - #35
Merged
Merged
Conversation
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective-C app targets: React Native headers by bare name
Follow-up to #33 and #34. With its headers copied, a bare React Native 0.85 app with an Objective-C app target failed at the first line of its
AppDelegate.h,#import <RCTAppDelegate.h>, with'RCTAppDelegate.h' file not found; itsAppDelegate.mmalso does#import <AppAuth/AppAuth.h>, as react-native-app-auth's README asks. With CocoaPods both spellings work because the app target'sHEADER_SEARCH_PATHSlists every pod's public header directory. rn-xtool's App target saw only the root of the React Native headers farm (<React/RCTAppDelegate.h>resolved,<RCTAppDelegate.h>did not) and nothing of the scaffold'srn-spm-pod-headersforwards. Not a release: the notes stay under[Unreleased].What users get
include/forwards and itsHEADER_SEARCH_PATHS, the App target's clang flags and the bridging header's-Xccflags getReactHeadersTarget/include/Reactand the per-module folders ofReactNativeHeaders.xcframework(read from the device slice'smodule.modulemap, in its order: CoreModules, RCTAnimation, RCTBlob, RCTDeprecation, RCTImage, RCTSettings, RCTSwiftUIWrapper, RCTText, RCTVibration, ReactCommon, React_RCTAppDelegate, reactperflogger, yoga on 0.86 and 0.88). On 0.85 and 0.86RCTAppDelegate.hexists only underReact_RCTAppDelegate/, so the per-module folders are what makes<RCTAppDelegate.h>resolve there. An app header with the same name still wins.forwardHeadersspellings reach the app. Each autolinked library'srn-spm-pod-headersfolder is on the same path, so#import <AppAuth/AppAuth.h>resolves fromAppDelegate.mmas it does inside react-native-app-auth.cxxLanguageStandardto a mixed-language target, so anAppDelegate.mmthat imports<RCTAppDelegate.h>(which pulls in Fabric's C++ headers on 0.85) compiled with clang's default (gnu++17) and failed inreact/utils/hash_combine.hwithunknown type name 'Hashable'. The App target'scxxSettings(notcSettings) now carry-std=fromCLANG_CXX_LANGUAGE_STANDARD, mapped the same way as the package-levelcxxLanguageStandard(gnu++20→-std=gnu++20,c++2a→-std=c++20, unset or unknown →-std=c++20), as the scaffolder already does for mixed libraries. Reference apps never hit it because their only Objective-C file was a.m.rn-spm-pod-headers/AppAuth/AppAuth.hheld@import AppAuthCore;and@import AppAuth;. Swift Build compiles.mmfiles with-fmodules -fno-cxx-modules, as Xcode does by default, so onceAppDelegate.mmreached the forwarder it stopped withuse of '@import' when modules are disabled; it had only worked because react-native-app-auth's ownRNAppAuth.mis Objective-C. The forwarder now#imports the pod's public headers, by their paths under the public header directories of its SwiftPM targets, which every importer has on its include path. In a.mfile such an#importstill loads the module.pods.<pod>.forwardHeaderschanges format to match: a forwarded header maps to a list of headers, and a module name (the old form) is refused with a message that names the entry and says to list the pod's public headers. rn-xtool's AppAuth entry lists what AppAuth-iOS 3.0.0's umbrellaSources/AppAuth.hincludes: 26 headers fromSources/AppAuthCore, then the 5 of itsTARGET_OS_IOS || TARGET_OS_MACCATALYSTbranch, asiOS/OIDAuthState+IOS.hand so on. Those 5 headers already wrap themselves in that same condition, so the forwarder lists them without its own#if. The scaffold revision goes to 5, so a scaffold copy innode_modulesfrom 0.1.0-alpha.6 is regenerated by itself, and a persisted scaffold patch gets the existing "older rn-xtool scaffolder (revision 4, now 5)" warning.node_modules/<lib>/android/build(and.cxx), so those outputs went into the scaffold patch and the binary-file guard refused it at every build. The scaffold result now lists the files it wrote under the library (Package.swift,Package@swift-6.5.swift, the prefix header, theinclude/stubs, the module map,rn-spm-swift/,rn-spm-react-headers/,rn-spm-pod-headers/, andpackage.jsonwhen it recordsswiftpmConfig.name), the driver passes the list through its results file, and rn-xtool runs patch-package with--includeset to those paths plus every path the library's existing patches hold (each anchored and escaped), so a hand fix in a user's patch stays and nothing else enters it;--excludeis unchanged. Past 200 paths, the directories the scaffolder owns whole collapse to a prefix. When an existing patch'sdiff --githeaders cannot be read, the result lists no files, or the list would not fit in one argument, it diffs the whole package as before and says so in oneℹline. The binary guard stays as the last check. What a scaffold writes is unchanged, so the scaffold revision stays 5; both 0.88 patches carry the scaffolder change. Docs:docs/how-it-works.md, the persist guard entry indocs/troubleshooting.md, and a CHANGELOG line under### Fixed.source_filesfromsource_files_exts = new_arch_enabled ? '…' : '…',source_files = ["ios/**/*.#{source_files_exts}"], a conditional.pushand anif/elsearoundexclude_files; the reader left#{source_files_exts}in the glob, so the scaffoldedRNScreenstarget held only thecommonsubspec's C++ and no Objective-C class, and the app crashed at start. The regex reader's constants pass becomes a side-effect-free evaluator (scaffolder fix 28) that runs the podspec's statements in order: locals (=,+=,||=), strings with#{…}, arrays and%w[],ENV['…']/ENV.fetch(RCT_NEW_ARCH_ENABLEDandRCT_HERMES_V1_ENABLEDare1, every other variable unset, the shell never read),==,!=,!,&&,||, ternaries,+,join,if/elsif/else/unlessblocks and modifiers, andpush/<</concaton a local array. A branch its condition rules out is blanked; both branches of a condition it cannot evaluate (respond_to?(…), vision-camera'senableFrameProcessors) stay visible, as before. Asource_files/exclude_filesvalue that uses an unknown identifier or a method call fails that library's scaffold (Scaffolding <lib> failed: <podspec>: `s.source_files = <expr>` cannot be evaluated: …), so a future podspec idiom stops the build instead of crashing the app; name resolution and header search paths read the model as before. screens 4.24.0 now scaffolds 195 sources (147 underios/),ios/gammaexcluded andios/stubskept, as one clang-only target (all its Swift is underios/gamma), withios/bridging/Swift-Bridging.hleft out of its module map. Output changes elsewhere: react-native-svg 15.16.0 no longer excludesapple/Utils/RNSVGFabricConversions.h(only its old-architectureelsedid), so that header joins its sources and its module map is no longer written; dead-elsedependencies (React-Core,React-jsc) drop out of models. Any otherENV[...]now reads as unset instead of not at all (fix 19's test changes accordingly). The reader also models the library's ownpackage.json(JSON.parse(File.read(File.join(__dir__, "package.json"))), alsoFile.dirname(__FILE__), any key), hashes and symbols, keeps a string with an interpolation it cannot compute as a partial string with that#{…}as written (so fix 8 still givesREACT_NATIVE_MINOR_VERSION=#{…}the installed React Native's minor), and keeps a local set under an unevaluable condition for the rest of that branch.name,module_nameandversionstay literal-only (evaluatings.name = package['name']would rename react-native-app-auth's and react-native-webview's targets). Besides the globs, an unevaluablecompiler_flags,header_dir,header_mappings_dir,frameworksorlibrariesvalue fails the scaffold the same way; an unevaluable part of an xcconfig value the scaffolder reads (OTHER_CFLAGS,GCC_PREPROCESSOR_DEFINITIONS,HEADER_SEARCH_PATHS,SWIFT_ACTIVE_COMPILATION_CONDITIONS) is left out with a warning naming it (Left out of s.pod_target_xcconfig OTHER_CFLAGS: `#{feature_flags}`, …) rather than refused, because worklets, reanimated, vision-camera and gesture-handler put configuration-driven flags there that only CocoaPods computes, and they built and ran with them left out. The scaffold revision goes to 7, so scaffolds persisted with this branch's revisions 5 and 6 (the partial screens one, a worklets one without its defines) get the older-scaffolder warning. Both 0.88 patches are regenerated, andrn-xtool-edits.patch's read-podspec hunk header moved with the file.xtool-build(after the binary-pod checks), and ininstall/runon the app xtool builds before it installs (xtool builds first, as for binary pods, only when the providers name classes), everyNSClassFromString(@"…")(or[X class]) ofios/build/generated/ios/ReactCodegen/RCTThirdPartyComponentsProvider.mmand every provider class ofRCTModuleProviders.mmmust be an_OBJC_CLASS_$_symbol of the App binary or of a framework underApp.app/Frameworks(Module.Classnames map to Swift's_TtC…runtime name). A missing one removes the app and its.ipaand stops withReact Native's codegen names classes the packed app does not define, so rn-xtool removed it and does not install it:, one line per class with its component or module and its library (the provider line's comment, else the library'scodegenConfig.ios, else "a library"), the crash it would cause (+[RCTThirdPartyComponentsProvider thirdPartyFabricComponents]throwsNSInvalidArgumentException), or for a module that React Native would log it missing, and what to check (the library'sPackage.swift, a scaffold persisted by an older rn-xtool). A binary set with no ObjC class symbol at all is not refused: oneℹline says nothing could be checked.docs/bare-react-native.md, a troubleshooting entry keyed by'RCTAppDelegate.h' file not found(with'AppAuth/AppAuth.h' file not foundas a sibling symptom), and a CHANGELOG line under[Unreleased]→### Fixed. For the forwarders: theforwardHeadersdescription in "Libraries that depend on CocoaPods pods", a troubleshooting entry keyed byuse of '@import' when modules are disabled, the revision 5 warning entry,docs/how-it-works.md, fix 13 indocs/upstream/react-native-scaffolder.md, and CHANGELOG entries under### Upgrading from 0.1.0-alpha.6,### Changedand### Fixed.Verified
Layout per slot, on disk and in the code:
stageReactHeadersTargetcopiesReact.framework/Headersto a flatReactHeadersTarget/include/React; on 0.88.1React/RCTAppDelegate.his a one-line forward to<React_RCTAppDelegate/RCTAppDelegate.h>; on 0.85.0 and 0.86.3 (VFS templates and the adapted 0.86 tree)React/has noRCTAppDelegate.hat all.Unit tests, written failing first: a bare mixed app's
cSettings/cxxSettingsand bridging-header flags carry React Native's bare-name folders after the app's own, then the libraries'rn-spm-pod-headersfolders; an Expo app's manifest is byte-identical.Imports of the real app resolved as files against the generated 0.88 trees with the new paths:
<RCTAppDelegate.h>,<AppAuth/AppAuth.h>(missing before, found after);<React/RCTBundleURLProvider.h>,<ReactAppDependencyProvider/RCTAppDependencyProvider.h>,<RNAppAuth.h>,<React/RCTLinkingManager.h>,<React/RCTBridgeModule.h>(found before and after). A local clang with-fmodulescompiles a header imported both by bare name and by module name, in either order, on stand-in headers.Real build: the app's build with Objective-C app targets: every header the project references #34 stopped at
'RCTAppDelegate.h' file not found, which this addresses. A build with the bare-name paths got past every header and stopped on C++ errors inAppDelegate.mm(hash_combine.h,unknown type name 'Hashable'): its clang command line carried no-std=, which the C++ standard change addresses. No build with that change yet.Real build, forwarders: the build with the C++ standard change compiled
AppDelegate.mmup to#import <AppAuth/AppAuth.h>and stopped in the forwarder withuse of '@import' when modules are disabled, which the textual forwarder addresses. The app's compile line carries-Ifor both AppAuth-iOS public header directories (Sources/AppAuthCoreandSources/AppAuth), which is where the forwarder's paths resolve. No build with this change yet.Forwarders, unit tests written failing first: the written forwarder holds the banner and one
#import <…>per listed header and no@import; a module name in the list is refused with its message, in the scaffolder and in the config check; malformed headers (.., absolute, a space, a>that would end the#import) are refused. Both 0.88 patches were regenerated from the vendored scaffolder and the byte-identity, upstream dry-run and "carry the patch" tests pass, none skipped. The header list was checked against AppAuth-iOS 3.0.0's tarball: every entry exists underSources/AppAuthCoreorSources/AppAuth, thepublicHeadersPath: ""of theAppAuthCoreandAppAuthtargets in itsPackage.swift.C++ standard, unit tests written failing first: a mixed App with
gnu++20gets-std=gnu++20incxxSettingsonly (cSettingsunchanged, one-std=in the manifest); unset andc++2agive-std=c++20; a Swift-only bare app and an Expo app render no C-family settings and no-std=. Rendered manifests before and after: Expo and Swift-only bare byte-identical, mixed bare differs by the onecxxSettingsline.Persisting, the real build: a bare React Native 0.85 app that had also been built for Android printed
⚠ Did not persist react-native-linear-gradient's scaffold: the patch would contain a binary file (node_modules/react-native-linear-gradient/android/build/…/BuildConfig.dex)and scaffolded the library again at every build. No build with this change yet.Persisting, unit tests written failing first: the include argument anchors and escapes each path (
include/Foo+Bar/Foo+Bar.h) and lists the existing patch's paths; with a fake patch-package that keeps what--include/--excludeselect, a library whoseandroid/build/…/BuildConfig.dexandandroid/.cxxdiffer is persisted and its patch holds noandroidpath; an existing patch'sios/Foo.mstays in; an unreadable existing patch, a result without files and an over-long list each fall back to the whole package with theirℹline. The scaffolder's results list exactly the files each scaffold created or changed, on the vendored copy and on React Native 0.88.1 with the bundled patch. Both 0.88 patches were regenerated from the pristine 0.88.0 tarball (identical, as the test requires) and apply to 0.88.1 with-F0.Podspec reader, the real app: the bare React Native 0.85 app built and installed, then crashed at JS start with
NSInvalidArgumentExceptionin+[RCTThirdPartyComponentsProvider thirdPartyFabricComponents](-[__NSPlaceholderDictionary initWithObjects:forKeys:count:], a nil class). The 20 react-native-screens 4.24.0 Fabric classes the provider expects (RNSScreenView,RNSScreenStackView,RNSFullWindowOverlay,RNSModalScreen, …) were absent from the App binary,RNScreens.oheld no Objective-C class, and the scaffoldedPackage.swiftlisted 49 sources, all undercommon/cpp/andcpp/. No build with this change yet.Podspec reader, tests written failing first: on a minimal screens 4.24.0 fixture (its podspec and
package.json, empty files at the paths the globs must match), the scaffold lacked everyios/source before and hasios/*.mm,ios/bridging/*.mmandios/stubs/*.mmafter, nothing underios/gamma, thecommonsubspec's C++, a clang-only manifest and a module map that leaves out the gamma headers andbridging/Swift-Bridging.h; a synthetic podspec covers ternaries on locals,!,ENV,if/elsif/else,unless, modifiers,pushand<<; single quotes do not interpolate and the last assignment wins; an unknown identifier, a method call, an interpolated call, a local built from a call and a local set under an unevaluable condition each fail the scaffold naming the podspec, the field and the expression, with noPackage.swiftwritten. The real 4.24.0 tarball scaffolds 195 sources (147 underios/, 67.mm, none underios/gamma, no Swift). Every podspec under the workspace's reference apps (bare 0.86, 0.87, 0.88; Expo SDK 57 and 58) was read with the old and the new reader: no library is refused, and the models differ only by what deadelsebranches declared (react-native-svg, react-native-webview, @react-native-community/datetimepicker, expo-modules-core). The golden scaffold of the reference libraries, rebuilt from a replica, differs only in react-native-svg (the header and the module map above). Both 0.88 patches were regenerated; the byte-identity, upstream dry-run and "carry the patch" tests pass, none skipped; the golden test is skipped without the reference app.Codegen class check: unit tests on generated-provider fixtures and a fake
llvm-nm: present classes (in the App binary, in an embedded framework, a SwiftModule.Class) pass and keep the app; the 10 react-native-screens classes absent give the exact message and remove the app and its.ipa; a module provider and a library fromcodegenConfigor "a library" are named; no providers means nollvm-nmrun; a stripped binary set gives theℹline.buildruns it afterxtool-buildand leaves the build unrecorded when it throws;installbuilds first and does not reachxtool dev runwhen it throws. Run with the realllvm-nmagainst copies of three device-tested packed apps from the workspace (a bare app with 63 components and a module, the reference Expo app with 32, an Expo SDK 57 app with none): no class reported missing.Regression found on the real app's rebuild, fixed: with the first version of the evaluator, react-native-worklets 0.8.3 stopped in
Common/cpp/worklets/Tools/WorkletsVersion.cpp:19withuse of undeclared identifier 'WORKLETS_VERSION_STRING': its compile line had-DHERMES_V1_ENABLED -DRCT_NEW_ARCH_ENABLED=1and neither-DWORKLETS_VERSION=…nor-DREACT_NATIVE_MINOR_VERSION=….version_flagsinterpolates$worklets_config[…], which the evaluator could not compute, so the whole string was unknown and the flag was dropped without a word. A test on the worklets 0.8.3 fixture (its podspec,scripts/worklets_utils.rb,package.json, empty sources) failed first and now finds.define("WORKLETS_VERSION", to: "0.8.3")and.define("REACT_NATIVE_MINOR_VERSION", to: "86")(the harness's React Native 0.86.3) incxxSettings, plus the two namedLeft out ofwarnings; refusal tests cover a method call incompiler_flagsand an unknown local asheader_dir.Regression sweep: the 15 libraries of the real app (from their npm tarballs), the workspace apps' scaffolded libraries (masked-view, screens 4.30.0 and 4.24.0, datetimepicker, gesture-handler 3.3.0, svg, webview, pager-view 9.0.7) and every podspec fixture were scaffolded with the scaffolder before this PR's reader change and with this one, and the full outputs compared (sources, defines, flags, header search paths, frameworks, module maps). Every difference: react-native-screens 4.24.0 gets its
ios/sources (the fix); react-native-svg getsapple/Utils/RNSVGFabricConversions.hand no module map (only its old-architectureelseexcluded it); react-native-webview, @react-native-async-storage/async-storage 1.24.0, react-native-keychain, react-native-video and @aws-amplify/react-native get-Wno-comma -Wno-shorten-64-to-32fromfolly_compiler_flags, which is now read (itsFOLLY_*defines stay dropped, with the existing warning); dead-elsedependencies drop out of the models. Defines and header search paths are otherwise identical, worklets' and reanimated's version defines included. New warnings name what was already left out silently before: worklets'#{feature_flags}and#{fetch_preview_flag}, reanimated's feature flags, example and compilation-database flags, vision-camera's frame processor define and its location and frame processor Swift conditions, gesture-handler 3.3.0's#{worklets_flag}.Checks
npm test(2442 passed, 6 skipped) andnpm run lintpass.npm run scan:privateis clean on every commit.