-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all header imports to "<React/..>"
Summary: To make React Native play nicely with our internal build infrastructure we need to properly namespace all of our header includes. Where previously you could do `#import "RCTBridge.h"`, you must now write this as `#import <React/RCTBridge.h>`. If your xcode project still has a custom header include path, both variants will likely continue to work, but for new projects, we're defaulting the header include path to `$(BUILT_PRODUCTS_DIR)/usr/local/include`, where the React and CSSLayout targets will copy a subset of headers too. To make Xcode copy headers phase work properly, you may need to add React as an explicit dependency to your app's scheme and disable "parallelize build". Reviewed By: mmmulani Differential Revision: D4213120 fbshipit-source-id: 84a32a4b250c27699e6795f43584f13d594a9a82
- Loading branch information
Showing
220 changed files
with
1,492 additions
and
1,197 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
Examples/UIExplorer/UIExplorer.xcodeproj/xcshareddata/xcschemes/UIExplorer-tvOS.xcscheme
This file contains 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
18 changes: 16 additions & 2 deletions
18
Examples/UIExplorer/UIExplorer.xcodeproj/xcshareddata/xcschemes/UIExplorer.xcscheme
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache For clarify maybe headers should be prefixed with
ReactNative
instead of justReact
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache I'm having some issues with building an archive in xcode after updating past this commit. Updated
HEADER_SEARCH_PATHS
to$(BUILT_PRODUCTS_DIR)/usr/local/include
and everything works fine when running with eitherdebug
orrelease
scheme (so it's not a scheme issue). However when building an archive to upload on the app store I get header not found errors. After looking a bit I found that xcode uses a different folder structure when archiving and adding"$(BUILD_ROOT)/../InstallationBuildProductsLocation/usr/local/include"
to the paths does fix it but kind of feels like a fragile solution. Found a bunch of different solutions on SO that all didn't work probably due to different xcode versions so I ended looking at the build dir to figure out the right path. Any ideas on a better solution? If not I guess we should add this to the header include paths so it doesn't break archive generation.e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache @janicduplessis I've been in a battle trying to build after upgrade to RN0.40, as this commit breaks all the third-party libraries, got errors such as can't find React/RCTXXX.h blablabla , and I ended up to add
$(BUILT_PRODUCTS_DIR)/usr/local/include
to theHEADER_SEARCH_PATHS
of every third-party library, I think it's wired to make such a big change with building settings, I haven't try to archive, and I believe I will encounter with the issue janic said aboveSo, are there more clever solution?
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also another issue, headers get included in the archive so it cannot get uploaded to the store as an iOS app. Looks like the recommended solution for this is to use a copy files build phase instead of headers build phase but I couldn't get it working so I ended using a pre-archive script to manually delete the headers from the archive. I added
rm -rf "${OBJROOT}/../InstallationBuildProductsLocation/usr"
in edit scheme -> archive section -> pre-archive -> add script.e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'll try what happens when I do a production build of UIExplorer, but I'm really surprised the copy headers phase is not behaving correctly like that.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nihgwu: none of the headers inside React moved locations, so I'm wondering why this would cause 3rd party packages with existing header include paths to break. I'd appreciate any help since this xcode config is very frustrating, internally we just use Buck.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(DSTROOT)/usr/local/include seems to be the correct path when archiving, but not when doing regular builds...
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache Yeah, from what I read the archive process has a different folder structure -_-, I guess we could include both paths. Also from your previous comment I don't think this change is backwards compatible, I don't know enough about xcode build stuff to know why (I agree it's weird since headers didn't move) but they are not accesible anymore with the old include path so every single lib need to update both their header include path and every import to <React/...>.
Once you manage to generate an archive you will also probably hit the 2nd issue I mentionned because the headers get included in the archive so it cannot be published as an app...
How does this improve builds internally? Is it worth breaking all 3rd party libs and having to work through these issues? I was starting to consider if we should rather just revert this at least until we can have a better solution.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, I see how this could break 3rd party libs. Besides reverting this commit, are there any other options that could limit the impact this has?
We do need this internally to have RN behave will with the rest of our build tooling. Having imports as "..." means you're filling the global namespace with RN header references which we had to move away from.
For the xcarchive containing headers issue, I'm now trying https://developer.apple.com/library/content/technotes/tn2215/_index.html as "Headers build phases do not work correctly with static library targets when archiving in Xcode"
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I'm fine with keeping this as no matter the change we make to avoid polluting the global header namespace it will break 3rd party libs. At least it's a simple fix for library authors.
I also tried using copy files build phase as mentioned in this article but couldn't get it working and gave up since I had to ship a build asap :)
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache This is affecting us badly too. Is there a short term fix? and should we ask 3rd party libs to update their imports/headers?
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3rd parties should only need to update their header search path. I'm working on fixing the setup for archiving builds.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache not only the header search path, if you need to import the header files from the 3rd party libraries in
AppDelegate.m
, you will still get errors, you have to change$(BUILT_PRODUCTS_DIR)/usr/local/include
to be recursive in your project targets as those libraries are importing "RCTXXX.h" not <React/RCTXXX.h>So the best way is to update their header search path and import path both
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I'll be landing a change today (and picking it to 0.40), which moves the exported headers to
$(BUILT_PRODUCTS_DIR)/include
which actually is on Xcode's default include path it seems, so no changes should be required anymore.e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news, I'm really frustrating with the XCode stuff.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new version of this just landed as 59407f3 Can you try it out? @mkonicek will be merging this in v0.40 if all goes well.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache Just tested and it works really well, thanks for figuring out this frustrating xcode build stuff. Third party libs will still have to update their RN imports and remove React from their headers path otherwise you get header redefinition errors but I think this is fine.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually headers still get included in the archive, looks like they need to be in the 'Project' section instead of 'Private' (as if that makes any sense). After changing that it works properly :)
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache 59407f3 seems does't solve the 3rd party libraries's search issue, and this commit included CSSLayout->yoga, can't be cherry-picked in v0.40 directly
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't see janic's comment when I commented above, I have to say that frustrated me so and I don't want to make another try, I'll try janic's solution mentioned earlier.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes that were needed to be able to archive my app here #11395
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicduplessis We still need to update the header paths in 3rd party libs, do we? I'll try it later.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I don't think there is a way to make this change and not have libs update their headers.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is another frustrating change for developers just like 0.26 or 0.29 😞
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has anyone tested this yet in a swift project? I removed the following from header search paths:
Then added
$(BUILT_PRODUCTS_DIR)/include/**
and still getting tons of errors on both core and 3rd party libs:Please advise...
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjmueller You definitely missed something:
$(BUILT_PRODUCTS_DIR)/include/**
to the search path as it already in the default search pathI'll send a patch file and write a tutorial to make those changes
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a patch for RN0.40-stable branch
https://gist.github.com/nihgwu/7d03ca80fc807d5449a6862f2cbf54d8, this patch reverts the
CSSLayout -> yoga
change which hasn't been shipped to 0.40-stable branchgit apply patch.diff
react-native upgrade
andreact-native link
and other upgrade steps"RCTXXX.h"
to<React/RCTXXX.h>
inAppDelegate.m
and all your 3rd party libsHEADER_SEARCH_PATHS
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciate your prompt response @nihgwu. Before your answer, I decided to switch from RN 0.40 to master, which includes 59407f3 as you mentioned. However, I still received the same errors, both in 3rd party libs and core libs. I believe I also tried many combinations with header search paths, including removal of all entries. To be honest I'm not entirely sure that the inclusion of certain paths would break something anyway.
I could try going back to 0.40 and apply your patch, but is this going to be a better combo than what's in latest master as of 2 hours ago?
I fear that there may be more to the story here, people are struggling with something similar using swift and cocoapods in #9014 (even though my project doesn't use CocoaPods at all). Over a year of working with RN, I've occasionally had to fork a third party lib to change an import statement from using brackets to quotes, probably because ObjC projects weren't hitting the same build exceptions. However, this change proposes that every dependency switch to brackets, and we should make sure it doesn't leave swift projects in a broken state that requires post install scripts to fixup dependencies 😢
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't switch to the master version because
react-native upgrade
doesn't work well on that branch.And I'm sorry I missed you mention that you are in a swift project, I have no experience on this
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a case for adding
#ifndef HEADER_H
-style guards to React's public headers? That way we wouldn't be forcing third party libs to accommodate this change. It'd be safe for the user's header/library search paths to point to the same headers in multiple ways.Edit: This seems to work. PR: #11614
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is disabling parallelization a good thing? isnt the packager slow enough, now we slow down xcode too? why?
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is the work on swift support going? Any light in the end of the tunnel? Are there any updates in the near future that fixes this?
We are currently looking at RN to be our platform, but we are very interested in using swift with cocoapods. And this issue here has made us stop at version 0.38 so far. But we would really see that we were at the newest version.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Snorlock we are using react native with objc and swift in one project. its not that hard to set it up actually. and then you can just use swift for the native stuff and js for whatever else. the one annoying thing is the bridging files. so i have some managers and viewmanagers in swift, and for each of them i have to have a file called BlaManagerBridge.m that just has the func declarations for rn to see. not too bad for using swift for now. ping me on email me if you wanna talk.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah our choice is that we want a pure swift application, meaning no objc. Then searching for issues related led me to this: #11572.
Which is the header issue that have been roaming around. In this issue they talked about this commit, so I mostly refer to that. Is there any light in the end of the tunnel for pure swift applications, based on the breakage in 0.40 - https://github.com/facebook/react-native/releases/tag/v0.40.0
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, i dont know about that. and i will bet its going to take a long time for that to happen. like at least 2 years, would be my guess. they have so many things to do and so many things in objc already done, that (at least the core team) i dont think they will spend time swiftifying everything.
if i were you, wanting to have a pure swift app with rn, i would write a couple of scripts to generate the bridging .m files, and not think about them any more. but i know thats not a perfect solution.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to archive the project at the moment in
0.41.0
. Running in debug mode works fine, but in release it appears that the React framework is not found:e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajwhite I had the same issue. Sadly the fix was running react-native init again, copying over source files, and redoing the entire project setup.
Should you also take this journey, I wish you Godspeed.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue boiled down to two things:
0.40.0
, it will need to know what scheme to build for. However, it only supports Debug and Release. If you use a custom Scheme configuration, the react project is not going to know about it. It's going to put its Build Products in a Release directory, whereas the rest of your application is reading from your custom scheme configuration's build products directory.Further discussion and solutions can be found in #11813.
I'm all set after having my custom schemes pull in the React Build Products from the Release directories, even though I'm not building a Release scheme.
e1577df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajwhite Ah, that makes sense! I had a custom scheme I was trying to use for archiving. Thanks for the helpful info.