[libc-commits] [libc] ca2a4e7 - [libc] Generate configure.rst from the JSON config information. (#65791)
via libc-commits
libc-commits at lists.llvm.org
Fri Sep 8 13:11:13 PDT 2023
Author: Siva Chandra
Date: 2023-09-08T13:11:09-07:00
New Revision: ca2a4e76ea905e7874010c7203a0792ed2fa90e5
URL: https://github.com/llvm/llvm-project/commit/ca2a4e76ea905e7874010c7203a0792ed2fa90e5
DIFF: https://github.com/llvm/llvm-project/commit/ca2a4e76ea905e7874010c7203a0792ed2fa90e5.diff
LOG: [libc] Generate configure.rst from the JSON config information. (#65791)
Added:
libc/docs/configure.rst
Modified:
libc/CMakeLists.txt
libc/cmake/modules/LibcConfig.cmake
libc/docs/index.rst
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 0665cf0f7a1d900..12fff25c197e2d9 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -143,6 +143,7 @@ foreach(opt IN LISTS global_config)
message(STATUS "${opt_name}: ${opt_value}")
set(${opt_name} ${opt_value})
endforeach()
+generate_config_doc(${main_config_file} ${LIBC_SOURCE_DIR}/docs/configure.rst)
load_libc_config(${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/config.json ${cmd_line_conf})
load_libc_config(${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/config.json ${cmd_line_conf})
diff --git a/libc/cmake/modules/LibcConfig.cmake b/libc/cmake/modules/LibcConfig.cmake
index a9c69de8a310a9b..7a3e6066b3cc06e 100644
--- a/libc/cmake/modules/LibcConfig.cmake
+++ b/libc/cmake/modules/LibcConfig.cmake
@@ -47,7 +47,6 @@ function(read_libc_config config_file opt_list)
# to load. If there are no config options, it is better to remove that
# config.json file instead of including an empty file.
message(FATAL_ERROR "${config_file}: Does not contain any config option groups")
- return()
endif()
math(EXPR group_count_1 "${group_count} - 1")
@@ -135,3 +134,84 @@ function(load_libc_config config_file)
set(${opt_name} ${opt_value} PARENT_SCOPE)
endforeach()
endfunction()
+
+function(generate_config_doc config_file doc_file)
+ if(NOT EXISTS ${config_file})
+ message(FATAL_ERROR "${config_file} does not exist")
+ endif()
+ file(READ ${config_file} json_config)
+ string(JSON group_count ERROR_VARIABLE json_error LENGTH ${json_config})
+ if(json_error)
+ message(FATAL_ERROR "${config_file}: ${json_error}")
+ endif()
+ if(${group_count} EQUAL 0)
+ message(FATAL_ERROR "${config_file}: Does not contain any config option groups")
+ endif()
+ math(EXPR group_count_1 "${group_count} - 1")
+
+ set(doc_string ".. _configure:\n"
+ "..\n"
+ " Do not edit this file directly. CMake will auto generate it.\n"
+ " If the changes are intended, add this file to your commit.\n"
+ "\n"
+ "==========================\n"
+ "Configure Options\n"
+ "==========================\n"
+ "\n"
+ "Below is the full set of options one can use to configure the libc build.\n"
+ "An option can be given an explicit value on the CMake command line using\n"
+ "the following syntax:\n"
+ "\n"
+ ".. code-block:: sh\n"
+ "\n"
+ " $> cmake <other build options> -D<libc config option name>=<option value> <more options>\n"
+ "\n"
+ "For example:\n"
+ "\n"
+ ".. code-block:: sh\n"
+ "\n"
+ " $> cmake <other build options> -DLIBC_CONF_PRINTF_DISABLE_FLOAT=ON <more options>\n"
+ "\n"
+ "See the main ``config/config.json``, and the platform and architecture specific\n"
+ "overrides in ``config/<platform>/config.json`` and ``config/<platform>/<arch>/config.json,``\n"
+ "to learn about the defaults for your platform and target.\n"
+ "\n")
+
+ foreach(group_num RANGE ${group_count_1})
+ string(JSON group_name ERROR_VARIABLE json_error MEMBER ${json_config} ${group_num})
+ if(json_error)
+ message(FATAL_ERROR "${config_file}: ${json_error}")
+ endif()
+ string(APPEND doc_string "* **\"${group_name}\" options**\n")
+ string(JSON option_map ERROR_VARIABLE json_error GET ${json_config} ${group_name})
+ if(json_error)
+ message(FATAL_ERROR ${json_error})
+ endif()
+ string(JSON option_count ERROR_VARIABLE jsor_error LENGTH ${option_map})
+ if(json_error)
+ message(FATAL_ERROR ${json_error})
+ endif()
+ if(${option_count} EQUAL 0)
+ message(FATAL_ERROR "${config_file}: No options listed against the config option group '${group_name}'")
+ endif()
+
+ math(EXPR option_count_1 "${option_count} - 1")
+ foreach(opt_num RANGE ${option_count_1})
+ string(JSON option_name ERROR_VARIABLE json_error MEMBER ${option_map} ${opt_num})
+ if(json_error)
+ message(FATAL_ERROR ${json_error})
+ endif()
+ string(JSON opt_object ERROR_VARIABLE json_error GET ${option_map} ${option_name})
+ if(json_error)
+ message(FATAL_ERROR "Error generating ${doc_file}: ${json_error}\n${opt_object}")
+ endif()
+ string(JSON opt_doc ERROR_VARIABLE json_error GET ${opt_object} "doc")
+ if(json_error)
+ message(FATAL_ERROR "Error generating ${doc_file}: ${json_error}")
+ endif()
+ string(APPEND doc_string " - ``${option_name}``: ${opt_doc}\n")
+ endforeach()
+ endforeach()
+ message(STATUS "Writing config doc to ${doc_file}")
+ file(WRITE ${doc_file} ${doc_string})
+endfunction()
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
new file mode 100644
index 000000000000000..9b4d6034129351d
--- /dev/null
+++ b/libc/docs/configure.rst
@@ -0,0 +1,31 @@
+.. _configure:
+..
+ Do not edit this file directly. CMake will auto generate it.
+ If the changes are intended, add this file to your commit.
+
+==========================
+Configure Options
+==========================
+
+Below is the full set of options one can use to configure the libc build.
+An option can be given an explicit value on the CMake command line using
+the following syntax:
+
+.. code-block:: sh
+
+ $> cmake <other build options> -D<libc config option name>=<option value> <more options>
+
+For example:
+
+.. code-block:: sh
+
+ $> cmake <other build options> -DLIBC_CONF_PRINTF_DISABLE_FLOAT=ON <more options>
+
+See the main ``config/config.json``, and the platform and architecture specific
+overrides in ``config/<platform>/config.json`` and ``config/<platform>/<arch>/config.json,``
+to learn about the defaults for your platform and target.
+
+* **"printf" options**
+ - ``LIBC_CONF_PRINTF_DISABLE_FLOAT``: Disable printing floating point values in printf and friends.
+ - ``LIBC_CONF_PRINTF_DISABLE_INDEX_MODE``: Disable index mode in the printf format string.
+ - ``LIBC_CONF_PRINTF_DISABLE_WRITE_INT``: Disable handling of %n in printf format string.
diff --git a/libc/docs/index.rst b/libc/docs/index.rst
index 5e9a602b5a96af4..6d36351b7ce1fc4 100644
--- a/libc/docs/index.rst
+++ b/libc/docs/index.rst
@@ -52,6 +52,7 @@ stages there is no ABI stability in any form.
usage_modes
overlay_mode
fullbuild_mode
+ configure
gpu/index.rst
.. toctree::
More information about the libc-commits
mailing list