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

RNGP - Honor the --active-arch-only when configuring the NDK #35860

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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.facebook.react.utils
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.Variant
import com.facebook.react.ReactExtension
import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
import java.io.File
import org.gradle.api.Project
Expand Down Expand Up @@ -49,6 +50,13 @@ internal object NdkConfiguratorUtils {
if ("-DANDROID_STL" !in cmakeArgs) {
cmakeArgs.add("-DANDROID_STL=c++_shared")
}

val architectures = project.getReactNativeArchitectures()
// abiFilters are split ABI are not compatible each other, so we set the abiFilters
// only if the user hasn't enabled the split abi feature.
if (architectures.isNotEmpty() && !ext.splits.abi.isEnable) {
ext.defaultConfig.ndk.abiFilters.addAll(architectures)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ internal object ProjectUtils {
internal fun Project.needsCodegenFromPackageJson(model: ModelPackageJson?): Boolean {
return model?.codegenConfig != null
}

internal fun Project.getReactNativeArchitectures(): List<String> {
val architectures = mutableListOf<String>()
if (project.hasProperty("reactNativeArchitectures")) {
val architecturesString = project.property("reactNativeArchitectures").toString()
architectures.addAll(architecturesString.split(",").filter { it.isNotBlank() })
}
return architectures
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import com.facebook.react.TestReactExtension
import com.facebook.react.model.ModelCodegenConfig
import com.facebook.react.model.ModelPackageJson
import com.facebook.react.tests.createProject
import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
import java.io.File
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
Expand Down Expand Up @@ -169,4 +169,41 @@ class ProjectUtilsTest {

assertFalse(project.needsCodegenFromPackageJson(extension))
}

@Test
fun getReactNativeArchitectures_withMissingProperty_returnsEmptyList() {
val project = createProject()
assertTrue(project.getReactNativeArchitectures().isEmpty())
}

@Test
fun getReactNativeArchitectures_withEmptyProperty_returnsEmptyList() {
val project = createProject()
project.extensions.extraProperties.set("reactNativeArchitectures", "")
assertTrue(project.getReactNativeArchitectures().isEmpty())
}

@Test
fun getReactNativeArchitectures_withSingleArch_returnsSingleton() {
val project = createProject()
project.extensions.extraProperties.set("reactNativeArchitectures", "x86")

val archs = project.getReactNativeArchitectures()
assertEquals(1, archs.size)
assertEquals("x86", archs[0])
}

@Test
fun getReactNativeArchitectures_withMultipleArch_returnsList() {
val project = createProject()
project.extensions.extraProperties.set(
"reactNativeArchitectures", "armeabi-v7a,arm64-v8a,x86,x86_64")

val archs = project.getReactNativeArchitectures()
assertEquals(4, archs.size)
assertEquals("armeabi-v7a", archs[0])
assertEquals("arm64-v8a", archs[1])
assertEquals("x86", archs[2])
assertEquals("x86_64", archs[3])
}
}