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

Pass react build dir to cmake #33736

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ android {
cmake {
arguments "-DREACT_COMMON_DIR=${reactNativeRootDir}/ReactCommon",
"-DREACT_ANDROID_DIR=$projectDir",
"-DREACT_BUILD_DIR=$buildDir",
Copy link
Contributor

Choose a reason for hiding this comment

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

Change looks fine 👍

I'm curious to know why do you need to change this though.
We need to make some assumptions from time to time (e.g. where the codegen output folder is and so on) so allowing for full customization is not always possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason for me to change the build directory is to avoid having to rebuild everything when node_modules gets changed. Building from source can be quite long so keeping the build cache is nice by moving the build directory to somewhere else.

This used to work with ndk build so I think changing build dir should be supported and is possible to avoid assuming the location.

Copy link
Contributor

Choose a reason for hiding this comment

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

Following up here: how do you handle iOS build dir?

The reason why I'm asking is that we have build/ hardcoded in several other places in the codebase:

$ rg "build/"

react.gradle
110:        new File(hermesOverrideDir, "build/bin/hermesc") :
111:        new File(reactRoot, "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")

ReactAndroid/src/main/jni/CMakeLists.txt
20:  add_react_android_subdir(build/third-party-ndk/${relative_path})
87:add_react_android_subdir(build/generated/source/codegen/jni)

scripts/generate-artifacts.js
217:      'build/generated/ios',

scripts/android-e2e-test.js
83:      app: path.resolve('android/app/build/outputs/apk/debug/app-debug.apk'),

scripts/react_native_pods.rb
9:$CODEGEN_OUTPUT_DIR = 'build/generated/ios'

scripts/react_native_pods_utils/__tests__/script_phases.snap.rb
50:    export RCT_SCRIPT_OUTPUT_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT/build/generated/ios

scripts/react_native_pods_utils/__tests__/script_phases.test.rb
33:            codegen_output_dir: 'build/generated/ios',

packages/rn-tester/package.json
19:    "clean-ios": "rm -rf build/generated/ios && rm -rf Pods && rm Podfile.lock"

scripts/objc-test.sh
102:    REPORTS_DIR="$THIS_DIR/../build/reports"

packages/rn-tester/Podfile.lock
758:  - React-Codegen (from `build/generated/ios`)
833:    :path: build/generated/ios

packages/rn-tester/android/app/build.gradle
86:    hermesCommand = "$rootDir/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"

packages/react-native-codegen/scripts/buck-oss/combine_js_to_schema.sh
14:node "build/lib/cli/combine/combine-js-to-schema-cli.js" "$@"

packages/react-native-codegen/scripts/buck-oss/generate-all.sh
14:node "build/lib/cli/generators/generate-all.js" "$@"

packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/PathUtilsTest.kt
173:    tempFolder.newFolder("node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/")
176:            "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")
199:    tempFolder.newFolder("node_modules/react-native/sdks/hermes/build/bin/")
200:    tempFolder.newFile("node_modules/react-native/sdks/hermes/build/bin/hermesc")
211:    tempFolder.newFolder("node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/")
214:            "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")
226:            "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"),
233:        File("/home/circleci/hermes/build/bin/hermesc"),

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PathUtils.kt
47: * 2. The file located in `node_modules/react-native/sdks/hermes/build/bin/hermesc`. This will be
118: * 2. The file located in `node_modules/react-native/sdks/hermes/build/bin/hermesc`. This will be
173:      File(pathOverride, "build/bin/hermesc")
196:    "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"

template/android/app/build.gradle
245:            // https://developer.android.com/studio/build/configure-apk-splits.html

template/_gitignore
7:build/
27:build/

tools/build_defs/oss/rn_defs.bzl
41:GLOG_DEP = "//ReactAndroid/build/third-party-ndk/glog:glog"

bots/report-bundle-size.js
169:    `packages/rn-tester/android/app/build/outputs/apk/${engine}/release/app-${engine}-${arch}-release.apk`,
234:            'packages/rn-tester/build/Build/Products/Release-iphonesimulator/RNTester.app/RNTester',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For iOS the build is already outside node_modules in ~/Library/Developer/Xcode/DerivedData afaik so I don’t do anything special. Codegen output is in /ios/build, but that doesn’t really cause problems.

I think it is fine to assume build path in certain cases when we control output, but in the case of android build directory it is possible to change via gradle so we should use that config value.

"-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
"-DANDROID_PLATFORM=android-21"
Expand Down
8 changes: 6 additions & 2 deletions ReactAndroid/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ function(add_react_android_subdir relative_path)
add_subdirectory(${REACT_ANDROID_DIR}/${relative_path} ReactAndroid/${relative_path})
endfunction()

function(add_react_build_subdir relative_path)
add_subdirectory(${REACT_BUILD_DIR}/${relative_path} build/${relative_path})
endfunction()

function(add_react_third_party_ndk_subdir relative_path)
add_react_android_subdir(build/third-party-ndk/${relative_path})
add_react_build_subdir(third-party-ndk/${relative_path})
endfunction()

function(add_react_common_subdir relative_path)
Expand Down Expand Up @@ -84,7 +88,7 @@ add_react_common_subdir(react/renderer/mapbuffer)
add_react_common_subdir(react/nativemodule/core)

# ReactAndroid JNI targets
add_react_android_subdir(build/generated/source/codegen/jni)
add_react_build_subdir(generated/source/codegen/jni)
add_react_android_subdir(src/main/java/com/facebook/hermes/reactexecutor)
add_react_android_subdir(src/main/jni/first-party/fbjni)
add_react_android_subdir(src/main/jni/first-party/fb)
Expand Down