-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Conversation
Base commit: d992ae0 |
Base commit: d992ae0 |
@@ -283,6 +283,7 @@ android { | |||
cmake { | |||
arguments "-DREACT_COMMON_DIR=${reactNativeRootDir}/ReactCommon", | |||
"-DREACT_ANDROID_DIR=$projectDir", | |||
"-DREACT_BUILD_DIR=$buildDir", |
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.
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.
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 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.
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.
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',
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.
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.
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @janicduplessis in 6ab7a99. When will my fix make it into a release? | Upcoming Releases |
Summary
The ReactAndroid cmake build assumes that the build directory is ReactAndroid/build, but this is not always the case if gradle is configured with a different build location. Instead of assuming the build location in cmake, pass it from gradle.
Changelog
[Android] [Fixed] - Pass react build dir to cmake
Test Plan
Tested in an app with a custom build dir that RN now builds properly after this change.
In build.gradle add: