Skip to content
Draft
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 @@ -32,9 +32,9 @@ abstract class GenerateAutolinkingNewArchitecturesFileTask : DefaultTask() {
fun taskAction() {
val model = JsonUtils.fromAutolinkingConfigJson(autolinkInputFile.get().asFile)

val packages = filterAndroidPackages(model)
val cmakeFileContent = generateCmakeFileContent(packages)
val cppFileContent = generateCppFileContent(packages)
val dependenciesWithNames = filterAndroidPackagesWithNames(model)
val cmakeFileContent = generateCmakeFileContent(dependenciesWithNames)
val cppFileContent = generateCppFileContent(dependenciesWithNames.map { it.second })

val outputDir = generatedOutputDirectory.get().asFile
outputDir.mkdirs()
Expand All @@ -43,49 +43,69 @@ abstract class GenerateAutolinkingNewArchitecturesFileTask : DefaultTask() {
File(outputDir, H_FILENAME).apply { writeText(hTemplate) }
}

internal fun filterAndroidPackages(
internal fun filterAndroidPackagesWithNames(
model: ModelAutolinkingConfigJson?
): List<ModelAutolinkingDependenciesPlatformAndroidJson> =
model?.dependencies?.values?.mapNotNull { it.platforms?.android } ?: emptyList()
): List<Pair<String, ModelAutolinkingDependenciesPlatformAndroidJson>> {
return model?.dependencies?.entries
?.mapNotNull { (name, depValue) ->
depValue.platforms?.android?.let { android -> name to android }
} ?: emptyList()
}

internal fun generateCmakeFileContent(
packages: List<ModelAutolinkingDependenciesPlatformAndroidJson>
dependenciesWithNames: List<Pair<String, ModelAutolinkingDependenciesPlatformAndroidJson>>
): String {
val libraryIncludes =
packages.joinToString("\n") { dep ->
dependenciesWithNames.joinToString("\n") { (depName, dep) ->
var addDirectoryString = ""
val libraryName = dep.libraryName
val cmakeListsPath = dep.cmakeListsPath
val cxxModuleCMakeListsPath = dep.cxxModuleCMakeListsPath
if (libraryName != null && cmakeListsPath != null) {
// If user provided a custom cmakeListsPath, let's honor it.
val nativeFolderPath = sanitizeCmakeListsPath(cmakeListsPath)
addDirectoryString +=
"add_subdirectory(\"$nativeFolderPath\" ${libraryName}_autolinked_build)"
}
if (cxxModuleCMakeListsPath != null) {
// If user provided a custom cxxModuleCMakeListsPath, let's honor it.
val nativeFolderPath = sanitizeCmakeListsPath(cxxModuleCMakeListsPath)
addDirectoryString +=
"\nadd_subdirectory(\"$nativeFolderPath\" ${libraryName}_cxxmodule_autolinked_build)"

if (dep.hasCodegenPrefab) {
addDirectoryString += "find_package($depName CONFIG REQUIRED)"
} else {
if (libraryName != null && cmakeListsPath != null) {
val nativeFolderPath = sanitizeCmakeListsPath(cmakeListsPath)
addDirectoryString +=
"add_subdirectory(\"$nativeFolderPath\" ${libraryName}_autolinked_build)"
}

if (cxxModuleCMakeListsPath != null) {
val nativeFolderPath = sanitizeCmakeListsPath(cxxModuleCMakeListsPath)
addDirectoryString +=
"\nadd_subdirectory(\"$nativeFolderPath\" ${libraryName}_cxxmodule_autolinked_build)"
}
}
addDirectoryString
}

val libraryModules =
packages.joinToString("\n ") { dep ->
dependenciesWithNames.joinToString("\n ") { (depName, dep) ->
var autolinkedLibraries = ""
if (dep.libraryName != null) {
autolinkedLibraries += "$CODEGEN_LIB_PREFIX${dep.libraryName}"
}
if (dep.cxxModuleCMakeListsModuleName != null) {
autolinkedLibraries += "\n${dep.cxxModuleCMakeListsModuleName}"
if (!dep.hasCodegenPrefab) {
if (dep.libraryName != null) {
autolinkedLibraries += "$CODEGEN_LIB_PREFIX${dep.libraryName}"
}
if (dep.cxxModuleCMakeListsModuleName != null) {
autolinkedLibraries += "\n${dep.cxxModuleCMakeListsModuleName}"
}
}
autolinkedLibraries
}

val prefabModules =
dependenciesWithNames.joinToString("\n ") { (depName, dep) ->
var prefabLibraries = ""
if (dep.hasCodegenPrefab) {
prefabLibraries += "$depName::$CODEGEN_LIB_PREFIX${dep.libraryName}"
}
prefabLibraries
}

return CMAKE_TEMPLATE.replace("{{ libraryIncludes }}", libraryIncludes)
.replace("{{ libraryModules }}", libraryModules)
.replace("{{ prefabModules }}", prefabModules)
}

internal fun generateCppFileContent(
Expand Down Expand Up @@ -178,6 +198,10 @@ abstract class GenerateAutolinkingNewArchitecturesFileTask : DefaultTask() {
set(AUTOLINKED_LIBRARIES
{{ libraryModules }}
)

set(PREFAB_LIBRARIES
{{ prefabModules }}
)
"""
.trimIndent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ data class ModelAutolinkingDependenciesPlatformAndroidJson(
val cxxModuleHeaderName: String? = null,
val dependencyConfiguration: String? = null,
val isPureCxxDependency: Boolean? = null,
val hasCodegenPrefab: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/$

add_library(
react_codegen_${targetName}
OBJECT
SHARED
\${react_codegen_SRCS}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ target_compile_options(common_flags INTERFACE ${folly_FLAGS})
# If project is on RN CLI v9, then we can use the following lines to link against the autolinked 3rd party libraries.
if(EXISTS ${PROJECT_BUILD_DIR}/generated/autolinking/src/main/jni/Android-autolinking.cmake)
include(${PROJECT_BUILD_DIR}/generated/autolinking/src/main/jni/Android-autolinking.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} ${AUTOLINKED_LIBRARIES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${AUTOLINKED_LIBRARIES} ${PREBUILT_LIBRARIES})
foreach(autolinked_library ${AUTOLINKED_LIBRARIES})
target_link_libraries(${autolinked_library} common_flags)
endforeach()
Expand Down
Loading