Skip to content

Truly independent web browser

Meta: Leave unused converters and StringPrep out of the ICU data

Aliaksandr Kalenik7641d123cce0
diff --git a/Libraries/LibUnicode/CMakeLists.txt b/Libraries/LibUnicode/CMakeLists.txt
index 91c0fe4c21e..d6f6f8d7dc9 100644
--- a/Libraries/LibUnicode/CMakeLists.txt
+++ b/Libraries/LibUnicode/CMakeLists.txt
@@ -63,13 +63,28 @@ if (EXISTS "${icu_data_file}")
set(icu_data_build_directory "${CMAKE_BINARY_DIR}/${IN_BUILD_PREFIX}${CMAKE_INSTALL_DATADIR}/Lagom/icu")
set(icu_data_build_file "${icu_data_build_directory}/${icu_data_file_name}")
set(LADYBIRD_ICU_DATA_FILE "${icu_data_build_file}" CACHE INTERNAL "The ICU data file that ships with the resources")
- add_custom_command(
- OUTPUT "${icu_data_build_file}"
- COMMAND "${CMAKE_COMMAND}" -E make_directory "${icu_data_build_directory}"
- COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${icu_data_file}" "${icu_data_build_file}"
- DEPENDS "${icu_data_file}"
- VERBATIM
- )
+ if (ICU_ICUPKG_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING)
+ set(trim_icu_data_script "${LADYBIRD_SOURCE_DIR}/Meta/CMake/trim_icu_data.cmake")
+ add_custom_command(
+ OUTPUT "${icu_data_build_file}"
+ COMMAND "${CMAKE_COMMAND}"
+ "-DICUPKG=${ICU_ICUPKG_EXECUTABLE}"
+ "-DINPUT=${icu_data_file}"
+ "-DOUTPUT=${icu_data_build_file}"
+ "-DREMOVED_ITEMS_LIST=${CMAKE_CURRENT_BINARY_DIR}/icu_data_removed_items.txt"
+ -P "${trim_icu_data_script}"
+ DEPENDS "${icu_data_file}" "${trim_icu_data_script}"
+ VERBATIM
+ )
+ else()
+ add_custom_command(
+ OUTPUT "${icu_data_build_file}"
+ COMMAND "${CMAKE_COMMAND}" -E make_directory "${icu_data_build_directory}"
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${icu_data_file}" "${icu_data_build_file}"
+ DEPENDS "${icu_data_file}"
+ VERBATIM
+ )
+ endif()
add_custom_target(copy_icu_data_to_build DEPENDS "${icu_data_build_file}")
add_dependencies(LibUnicode copy_icu_data_to_build)
else()
diff --git a/Meta/CMake/trim_icu_data.cmake b/Meta/CMake/trim_icu_data.cmake
new file mode 100644
index 00000000000..17acf107e41
--- /dev/null
+++ b/Meta/CMake/trim_icu_data.cmake
@@ -0,0 +1,20 @@
+# Copies the ICU data file INPUT to OUTPUT without the items that nothing in Ladybird uses: the character set converters,
+# as text decoding goes through LibTextCodec, and the StringPrep profiles, as IDNA uses UTS #46 instead.
+#
+# ICUPKG is ICU's icupkg tool, and REMOVED_ITEMS_LIST a .txt file to write the list of removed items to.
+
+get_filename_component(output_directory "${OUTPUT}" DIRECTORY)
+file(MAKE_DIRECTORY "${output_directory}")
+file(COPY_FILE "${INPUT}" "${OUTPUT}")
+
+execute_process(COMMAND "${ICUPKG}" -l "${OUTPUT}" OUTPUT_VARIABLE items COMMAND_ERROR_IS_FATAL ANY)
+string(REPLACE "\r" "" items "${items}")
+string(REPLACE "\n" ";" items "${items}")
+list(FILTER items INCLUDE REGEX "(\\.cnv|^cnvalias\\.icu|\\.spp)$")
+if (NOT items)
+ message(FATAL_ERROR "${INPUT} has none of the items to remove")
+endif()
+list(JOIN items "\n" removed_items)
+file(WRITE "${REMOVED_ITEMS_LIST}" "${removed_items}\n")
+
+execute_process(COMMAND "${ICUPKG}" -r "${REMOVED_ITEMS_LIST}" "${OUTPUT}" COMMAND_ERROR_IS_FATAL ANY)