Skip to content

Truly independent web browser

Meta: Add a vcpkg port for the math functions of LLVM libc

Shannon Booth74b0ad1c3ab5
diff --git a/Meta/CMake/check_for_dependencies.cmake b/Meta/CMake/check_for_dependencies.cmake
index 3a1dc8768a0..636bcf18f4c 100644
--- a/Meta/CMake/check_for_dependencies.cmake
+++ b/Meta/CMake/check_for_dependencies.cmake
@@ -12,6 +12,7 @@ find_package(mimalloc CONFIG REQUIRED)
find_package(Backtrace)
find_package(cpptrace CONFIG)
find_package(FastFloat CONFIG REQUIRED)
+find_path(LLVM_LIBC_INCLUDE_DIR NAMES llvm-libc/shared/math.h REQUIRED)
find_package(simdutf REQUIRED)
find_package(zmij CONFIG REQUIRED)
diff --git a/Meta/CMake/flatpak/org.ladybird.Ladybird.json b/Meta/CMake/flatpak/org.ladybird.Ladybird.json
index 353eea0e28d..3c50a076a85 100644
--- a/Meta/CMake/flatpak/org.ladybird.Ladybird.json
+++ b/Meta/CMake/flatpak/org.ladybird.Ladybird.json
@@ -662,6 +662,20 @@
"-DMI_USE_CXX=ON"
]
},
+ {
+ "name": "llvm-libc",
+ "buildsystem": "simple",
+ "build-commands": [
+ "cd libc && find hdr include shared src/__support src/string/memory_utils -name '*.h' -exec install -D -m644 {} /app/include/llvm-libc/{} \\;"
+ ],
+ "sources": [
+ {
+ "type": "archive",
+ "url": "https://github.com/llvm/llvm-project/archive/e54169423e7ee5d8b41c2f1b6f7a59000c901ee0.tar.gz",
+ "sha256": "db3ee51752d716118e3ff1109c7920a32dfc29bd414112e8d18ff6280e608c1c"
+ }
+ ]
+ },
{
"name": "wuffs",
"buildsystem": "simple",
diff --git a/Meta/CMake/vcpkg/overlay-ports/llvm-libc/portfile.cmake b/Meta/CMake/vcpkg/overlay-ports/llvm-libc/portfile.cmake
new file mode 100644
index 00000000000..c4d67c82e9d
--- /dev/null
+++ b/Meta/CMake/vcpkg/overlay-ports/llvm-libc/portfile.cmake
@@ -0,0 +1,39 @@
+# The math functions of LLVM libc are header-only, so this installs the headers of libc/ and builds nothing.
+set(VCPKG_BUILD_TYPE release)
+
+# NB: Double sinh, cosh and tanh are not in a release yet, so the version is a commit of main. From LLVM 24, this can
+# take https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/llvm-project-${VERSION}.src.tar.xz.
+vcpkg_download_distfile(ARCHIVE
+ URLS "https://github.com/llvm/llvm-project/archive/${VERSION}.tar.gz"
+ FILENAME "llvm-project-${VERSION}.tar.gz"
+ SHA512 4ab7f1f2c49a661148b38414c16d3600467f43a295ab0383358098eb2434dd0c21ea202da25bcd466d3b8f1b397527dd7793f4a7025f79388492fee291947bed
+)
+
+# The archive holds all of llvm-project, so only libc/ is extracted.
+set(SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src")
+file(REMOVE_RECURSE "${SOURCE_PATH}")
+file(MAKE_DIRECTORY "${SOURCE_PATH}")
+vcpkg_execute_required_process(
+ COMMAND "${CMAKE_COMMAND}" -E tar xzf "${ARCHIVE}" "llvm-project-${VERSION}/libc"
+ WORKING_DIRECTORY "${SOURCE_PATH}"
+ LOGNAME extract
+)
+set(LIBC_PATH "${SOURCE_PATH}/llvm-project-${VERSION}/libc")
+
+# The headers the math functions include, at their paths under libc/.
+foreach(directory hdr include shared src/__support src/string/memory_utils)
+ get_filename_component(destination "${CURRENT_PACKAGES_DIR}/include/llvm-libc/${directory}" DIRECTORY)
+ file(INSTALL "${LIBC_PATH}/${directory}" DESTINATION "${destination}" FILES_MATCHING PATTERN "*.h")
+endforeach()
+
+# FILES_MATCHING leaves the directories that hold no headers behind empty.
+file(GLOB_RECURSE directories LIST_DIRECTORIES true "${CURRENT_PACKAGES_DIR}/include/*")
+list(SORT directories ORDER DESCENDING)
+foreach(directory IN LISTS directories)
+ file(GLOB children "${directory}/*")
+ if(IS_DIRECTORY "${directory}" AND NOT children)
+ file(REMOVE_RECURSE "${directory}")
+ endif()
+endforeach()
+
+vcpkg_install_copyright(FILE_LIST "${LIBC_PATH}/LICENSE.TXT")
diff --git a/Meta/CMake/vcpkg/overlay-ports/llvm-libc/vcpkg.json b/Meta/CMake/vcpkg/overlay-ports/llvm-libc/vcpkg.json
new file mode 100644
index 00000000000..294be023d1d
--- /dev/null
+++ b/Meta/CMake/vcpkg/overlay-ports/llvm-libc/vcpkg.json
@@ -0,0 +1,7 @@
+{
+ "name": "llvm-libc",
+ "version-string": "e54169423e7ee5d8b41c2f1b6f7a59000c901ee0",
+ "description": "The header-only math functions of LLVM libc",
+ "homepage": "https://libc.llvm.org/",
+ "license": "Apache-2.0 WITH LLVM-exception"
+}
diff --git a/vcpkg.json b/vcpkg.json
index 4145a8e91ba..bfebfcb9441 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -112,6 +112,7 @@
]
},
"libxml2",
+ "llvm-libc",
{
"name": "mman",
"platform": "windows"
@@ -367,6 +368,10 @@
"name": "libxml2",
"version": "2.15.4#0"
},
+ {
+ "name": "llvm-libc",
+ "version": "e54169423e7ee5d8b41c2f1b6f7a59000c901ee0#0"
+ },
{
"name": "md4c",
"version": "0.5.3#0",