feat(Worklets): experimental public RNWorklets headers #8679
+247
−18
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.
Summary
Requires:
Currently we don't denote what headers are public and what are private in worklets. While the sole distinction is out of scope of this PR and something for the future, we could implement how the user is supposed to import them.
iOS (Cocoapods)
With Cocoapods the issue is quite straightforward. Running
pod installwill create a directoryPods/Headerswith the following structure (only RNWorklets included), havingPublicandPrivatedirs:You can see that all of the headers are actual symlinks to the source files - this is crucial for
#pragma once, I will explain it later on.Reading CocoaPods documentation:
This is why all the headers are in the Public dir. AFAIK the Private dir always has all the headers.
The Public dir is in the include list, therefore to import i.e.
AsyncQueue.hthe user has to do#include <RNWorklets/worklets/WorkletRuntime/WorkletRuntime.h>.We can easily turn this import to
<RNWorklets/AsyncQueue.h>by specifying flattened, public headers as done in this PR.react-native-reanimateddoesn't do<RNWorklets/...>for import because it adds'"$(PODS_ROOT)/Headers/Public/RNWorklets"',toHEADER_SEARCH_PATHSfor compilation - but it would be better if the user didn't have to do it.Android
If the user consumes Worklets as a prefab (which is the preferred way) he automatically has access to the includes in the prefabs, with the following structure:
To import, i.e.
AsyncQueue.hthe user has to do#include <worklets/WorkletRuntime/WorkletRuntime.h>and this way can also access all other "private" headers.This include can be changed to
<RNWorklets/...>only if we modify this header directory structure.One option here would be to copy the public headers to the root of the inclusion tree, so it would look like
However, this will break compilation as
#pragma onceinclusion guards are based on the file path. ThereforeRNWorklets/AsyncQueue.handworklets/RunLoop/AsyncQueue.hwould be treated as different headers and re-compiled, resulting in duplicated symbols. Cocoapods resolves this issue by using symlinks everywhere.We have two options to solve this problem:
#pragma onceguards toThe latter is less invasive for the time being - that's why I decided to opt into it.
Test plan
CI
Windows build CI: https://github.com/software-mansion/react-native-reanimated/actions/runs/19826776715