[libcxx-commits] [libcxx] [libc++][hardening] Rework how the assertion handler can be overridden. (PR #77883)

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 12 22:52:42 PST 2024


================
@@ -1020,9 +1020,11 @@ endforeach()
 
 configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
 configure_file("module.modulemap.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/module.modulemap" @ONLY)
+configure_file("${LIBCXX_ASSERTION_HANDLER_FILE}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler" @ONLY)
----------------
var-const wrote:

Note: I first tried using `file(COPY ...)`, but there seem to be several downsides to it:
1. It doesn't support changing the filename (I think). The newer (and simpler) `file(COPY_FILE ...)` command does, but it's only available starting from CMake `3.21`, which is above the minimum version we support (`3.20`). I tried renaming after copying, but it looks pretty ugly:
```cmake
file(COPY "${LIBCXX_ASSERTION_HANDLER_FILE}" DESTINATION "${LIBCXX_GENERATED_INCLUDE_DIR}")
cmake_path(GET LIBCXX_ASSERTION_HANDLER_FILE FILENAME _assertion_handler_short_name)
file(RENAME "${LIBCXX_GENERATED_INCLUDE_DIR}/${_assertion_handler_short_name}" "${LIBCXX_GENERATED_INCLUDE_DIR}/__assertion_handler")
```
2. [The docs](https://cmake.org/cmake/help/latest/command/file.html#copy-file) state the following: 
> An important difference is that [configure_file()](https://cmake.org/cmake/help/latest/command/configure_file.html#command:configure_file) creates a dependency on the source file, so CMake will be re-run if it changes. The file(COPY_FILE) sub-command does not create such a dependency.

(It is said about `COPY_FILE` but seems to apply to `COPY` as well)

This seems to be a downside. Testing locally, I can confirm that modifying the header triggers a rebuild of `cxx-test-depends` if I use `configure_file` but not if I use `file(COPY ...)`.

IIUC, the `COPYONLY` option prevents variables from being expanded, making the behavior identical. Let me know if I'm missing anything!

https://github.com/llvm/llvm-project/pull/77883


More information about the libcxx-commits mailing list