Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add linting to react-native-worklets #6825

Merged
merged 8 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/reanimated-static-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ on:
workflow_dispatch:

jobs:
check:
reanimated-static-checks:
if: github.repository == 'software-mansion/react-native-reanimated'
env:
PACKAGE_PATH: packages/react-native-reanimated
runs-on: ubuntu-latest
concurrency:
group: static-root-${{ github.ref }}
cancel-in-progress: true
steps:
# Setup VM
- name: checkout
uses: actions/checkout@v4
- name: Use Node.js
Expand All @@ -29,27 +32,29 @@ jobs:
- name: Clear annotations
run: .github/workflows/helper/clear-annotations.sh

# Setup repo
- name: Install monorepo node dependencies
run: yarn install --immutable
- name: Build Reanimated for TypeScript types
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn build

# Checks
- name: Check TypeScript types
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn type:check
- name: Lint JavaScript
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn lint:js
- name: Find unused code
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn find-unused-code:js
- name: Find circular dependencies
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn circular-dependency-check
- name: Check use strict
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn use-strict-check
- name: Run jest unit tests
working-directory: packages/react-native-reanimated
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn test
51 changes: 51 additions & 0 deletions .github/workflows/worklets-static-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Worklets static checks
env:
YARN_ENABLE_HARDENED_MODE: 0
on:
pull_request:
merge_group:
branches:
- main
push:
branches:
- main
workflow_call:
workflow_dispatch:

jobs:
worklets-static-checks:
if: github.repository == 'software-mansion/react-native-reanimated'
env:
PACKAGE_PATH: packages/react-native-worklets
runs-on: ubuntu-latest
concurrency:
group: worklets-static-checks-${{ github.ref }}
cancel-in-progress: true
steps:
# Setup VM
- name: checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: 'yarn'
- name: Clear annotations
run: .github/workflows/helper/clear-annotations.sh

# Setup repo
- name: Install monorepo node dependencies
run: yarn install --immutable
- name: Build Worklets for TypeScript types
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn build

# Checks
- name: Check TypeScript types
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn type-check
- name: Lint JavaScript
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn lint
- name: Find circular dependencies
working-directory: ${{ env.PACKAGE_PATH }}
run: yarn circular-dependency-check
30 changes: 18 additions & 12 deletions packages/react-native-reanimated/RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,24 @@ Pod::Spec.new do |s|
s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14", :visionos => "1.0" }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.subspec "worklets" do |ss|
ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}"
ss.header_dir = "worklets"
ss.header_mappings_dir = "Common/cpp/worklets"

ss.subspec "apple" do |sss|
# Please be careful with the snakes.
# 🐍🐍🐍
# Thank you for your understanding.
sss.source_files = "apple/worklets/**/*.{mm,h,m}"
sss.header_dir = "worklets"
sss.header_mappings_dir = "apple/worklets"
# TODO: Uncomment me when dynamic worklets linking is ready
# if File.directory?(File.join(__dir__, "../react-native-worklets"))
# # This condition is really naïve...
# s.dependency "RNWorklets"
# else
s.subspec "worklets" do |ss|
ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}"
ss.header_dir = "worklets"
ss.header_mappings_dir = "Common/cpp/worklets"

ss.subspec "apple" do |sss|
# Please be careful with the snakes.
# 🐍🐍🐍
# Thank you for your understanding.
sss.source_files = "apple/worklets/**/*.{mm,h,m}"
sss.header_dir = "worklets"
sss.header_mappings_dir = "apple/worklets"
# end
end
end

Expand Down
4 changes: 3 additions & 1 deletion packages/react-native-reanimated/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ set(BUILD_DIR "${CMAKE_SOURCE_DIR}/build")
set(ANDROID_CPP_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp")
set(COMMON_CPP_DIR "${CMAKE_SOURCE_DIR}/../Common/cpp")

add_subdirectory("${ANDROID_CPP_DIR}/worklets")
if(NOT ${HAS_EXTERNAL_WORKLETS})
add_subdirectory("${ANDROID_CPP_DIR}/worklets")
endif()
add_subdirectory("${ANDROID_CPP_DIR}/reanimated")
41 changes: 30 additions & 11 deletions packages/react-native-reanimated/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
def reactNativeThirdParty = new File("$reactNativeRootDir/ReactAndroid/src/main/jni/third-party")
def reactNativeAndroidDownloadDir = new File("$reactNativeRootDir/ReactAndroid/build/downloads")

// TODO: Uncomment me when when dynamic worklets linking is ready
// def hasExternalWorklets = rootProject.subprojects.find { it.name == 'react-native-worklets' } != null
def hasExternalWorklets = false

def workletsPrefabHeadersDir = project.file("$buildDir/prefab-headers/worklets")
def reanimatedPrefabHeadersDir = project.file("$buildDir/prefab-headers/reanimated")

Expand Down Expand Up @@ -232,8 +236,10 @@ android {
}

prefab {
worklets {
headers workletsPrefabHeadersDir.absolutePath
if(!hasExternalWorklets){
worklets {
headers workletsPrefabHeadersDir.absolutePath
}
}
reanimated {
headers reanimatedPrefabHeadersDir.absolutePath
Expand All @@ -257,7 +263,8 @@ android {
"-DJS_RUNTIME_DIR=${jsRuntimeDir}",
"-DIS_NEW_ARCHITECTURE_ENABLED=${IS_NEW_ARCHITECTURE_ENABLED}",
"-DIS_REANIMATED_EXAMPLE_APP=${isReanimatedExampleApp()}",
"-DREANIMATED_VERSION=${REANIMATED_VERSION}"
"-DREANIMATED_VERSION=${REANIMATED_VERSION}",
"-DHAS_EXTERNAL_WORKLETS=${hasExternalWorklets}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down Expand Up @@ -406,11 +413,13 @@ def assertMinimalReactNativeVersion = task assertMinimalReactNativeVersionTask {
}
}

task prepareWorkletsHeadersForPrefabs(type: Copy) {
from("$projectDir/src/main/cpp")
from("$projectDir/../Common/cpp")
include("worklets/**/*.h")
into(workletsPrefabHeadersDir)
if(!hasExternalWorklets) {
task prepareWorkletsHeadersForPrefabs(type: Copy) {
from("$projectDir/src/main/cpp")
from("$projectDir/../Common/cpp")
include("worklets/**/*.h")
into(workletsPrefabHeadersDir)
}
}

task prepareReanimatedHeadersForPrefabs(type: Copy) {
Expand Down Expand Up @@ -439,13 +448,17 @@ task printVersions {
task createNativeDepsDirectories() {
downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
workletsPrefabHeadersDir.mkdirs()
if(!hasExternalWorklets) {
workletsPrefabHeadersDir.mkdirs()
}
reanimatedPrefabHeadersDir.mkdirs()
}

task packageNdkLibs(type: Copy) {
from("$buildDir/reanimated-ndk/all")
include("**/libworklets.so")
if(!hasExternalWorklets){
include("**/libworklets.so")
}
include("**/libreanimated.so")
into("$projectDir/src/main/jniLibs")
}
Expand Down Expand Up @@ -473,6 +486,10 @@ dependencies {
if (JS_RUNTIME == "hermes") {
implementation "com.facebook.react:hermes-android" // version substituted by RNGP
}

if (hasExternalWorklets) {
implementation project(":react-native-worklets")
}
}

def nativeBuildDependsOn(dependsOnTask) {
Expand All @@ -487,7 +504,9 @@ def nativeBuildDependsOn(dependsOnTask) {
}

afterEvaluate {
preBuild.dependsOn(prepareWorkletsHeadersForPrefabs)
if(!hasExternalWorklets){
preBuild.dependsOn(prepareWorkletsHeadersForPrefabs)
}
preBuild.dependsOn(prepareReanimatedHeadersForPrefabs)

tasks.forEach({ task ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 3.8)
file(GLOB_RECURSE REANIMATED_COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/reanimated/*.cpp")
file(GLOB_RECURSE REANIMATED_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/reanimated/*.cpp")

find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
if(${HAS_EXTERNAL_WORKLETS})
find_package(react-native-worklets REQUIRED CONFIG)
endif()

add_library(
reanimated
Expand All @@ -12,6 +16,10 @@ add_library(
${REANIMATED_ANDROID_CPP_SOURCES}
)

if(${JS_RUNTIME} STREQUAL "hermes")
find_package(hermes-engine REQUIRED CONFIG)
endif()

target_include_directories(
reanimated
PRIVATE
Expand Down Expand Up @@ -41,9 +49,23 @@ set_target_properties(

target_link_libraries(
reanimated
worklets
log
ReactAndroid::jsi
fbjni::fbjni
)

if(${HAS_EXTERNAL_WORKLETS})
target_link_libraries(
reanimated
react-native-worklets::worklets
)
else()
target_link_libraries(
reanimated
worklets
)
endif()

if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(
reanimated
Expand All @@ -55,3 +77,34 @@ else()
ReactAndroid::react_nativemodule_core
)
endif()

if(${JS_RUNTIME} STREQUAL "hermes")
target_link_libraries(reanimated hermes-engine::libhermes)

if(${HERMES_ENABLE_DEBUGGER})
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(reanimated ReactAndroid::hermestooling)
else()
target_link_libraries(reanimated ReactAndroid::hermes_executor)
endif()
endif()
elseif(${JS_RUNTIME} STREQUAL "jsc")
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(reanimated ReactAndroid::jsctooling)
else()
target_link_libraries(reanimated ReactAndroid::jscexecutor)
endif()
elseif(${JS_RUNTIME} STREQUAL "v8")
# TODO: Refactor this when adding support for newest V8
target_include_directories(reanimated PRIVATE "${JS_RUNTIME_DIR}/src")
file(
GLOB
V8_SO_DIR
"${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/**/jni/${ANDROID_ABI}"
)
find_library(
V8EXECUTOR_LIB v8executor
PATHS ${V8_SO_DIR}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
target_link_libraries(reanimated ${V8EXECUTOR_LIB})
endif()
6 changes: 3 additions & 3 deletions packages/react-native-reanimated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"type:check:tests:common": "./scripts/test-ts.sh __typetests__/common",
"build": "yarn build:plugin && bob build",
"build:plugin": "cd plugin && yarn build",
"circular-dependency-check": "yarn madge --extensions js,ts,tsx --circular src lib",
"circular-dependency-check": "yarn madge --extensions js,jsx,ts,tsx --circular src lib",
"use-strict-check": "node ./scripts/validate-use-strict.js",
"prepack": "cp ../../README.md ./README.md",
"postpack": "rm ./README.md"
Expand Down Expand Up @@ -146,6 +146,7 @@
"react-native-builder-bob": "0.33.1",
"react-native-gesture-handler": "2.20.2",
"react-native-web": "0.19.11",
"react-native-worklets": "workspace:*",
"react-test-renderer": "18.2.0",
"shelljs": "^0.8.5",
"ts-prune": "^0.10.3",
Expand Down Expand Up @@ -178,6 +179,5 @@
"./lib/module/core.js",
"./lib/module/initializers.js",
"./lib/module/index.js"
],
"packageManager": "[email protected]"
]
}
19 changes: 8 additions & 11 deletions packages/react-native-worklets/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ project(Worklets)
cmake_minimum_required(VERSION 3.8)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE INTERNAL "")

set(CMAKE_CXX_STANDARD 20)

Expand All @@ -17,14 +14,13 @@ add_compile_options(${folly_FLAGS})
string(
APPEND
CMAKE_CXX_FLAGS
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}"
)
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} \
-DREANIMATED_VERSION=${REANIMATED_VERSION} \
-DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}")

string(
APPEND
CMAKE_CXX_FLAGS
" -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++${CMAKE_CXX_STANDARD} -Wall -Werror"
)
string(APPEND CMAKE_CXX_FLAGS
" -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all \
-std=c++${CMAKE_CXX_STANDARD} -Wall -Werror")

if(${IS_NEW_ARCHITECTURE_ENABLED})
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
Expand Down Expand Up @@ -57,4 +53,5 @@ set(BUILD_DIR "${CMAKE_SOURCE_DIR}/build")
set(ANDROID_CPP_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp")
set(COMMON_CPP_DIR "${CMAKE_SOURCE_DIR}/../Common/cpp")

add_subdirectory("${ANDROID_CPP_DIR}/worklets")
# TODO: Uncomment me when worklets get some sources
# add_subdirectory("${ANDROID_CPP_DIR}/worklets")
Loading
Loading