diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..4e09424 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,31 @@ +name: Maven + +on: + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + with: + submodules: 'recursive' + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: 'gradle' + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + - name: Build with Gradle + run: ./gradlew :cxx:publish + env: + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.maven_pgp_signingKey }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.maven_pgp_signingPassword }} + ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.maven_ossrhUsername }} + ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.maven_ossrhPassword }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index aa724b7..5bd175f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .externalNativeBuild .cxx local.properties +.idea diff --git a/.gitmodules b/.gitmodules index a6f5836..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "cxx-source"] - path = cxx-source - url = git@github.com:topjohnwu/libcxx.git - branch = master diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 05b62ee..0000000 --- a/build.gradle +++ /dev/null @@ -1,61 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - mavenCentral() - google() - } - dependencies { - classpath "com.android.tools.build:gradle:7.0.3" - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0' - } -} - -allprojects { - repositories { - mavenCentral() - google() - } - plugins.withId("com.vanniktech.maven.publish") { - mavenPublish { - sonatypeHost = "S01" - } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -subprojects { - afterEvaluate { - if (plugins.hasPlugin('com.vanniktech.maven.publish')) { - if (it.parent == rootProject) { - group = "${groupIdBase}" - } else { - group = "${groupIdBase}.${it.parent.name}" - } - version = android.defaultConfig.versionName - println("${it.displayName}: ${group}:${it.name}:${version}") - } - } -} - -ext { - groupIdBase = "dev.rikka.ndk.thirdparty" - - POM_INCEPTION_YEAR = "2021" - POM_PACKAGING = "aar" - - POM_URL = "https://github.com/RikkaW/libcxx-prefab" - POM_SCM_URL = "https://github.com/RikkaW/libcxx-prefab" - POM_SCM_CONNECTION = "scm:git@github.com:RikkaW/libcxx-prefab.git" - POM_SCM_DEV_CONNECTION = "scm:git@github.com:RikkaW/libcxx-prefab.git" - - POM_LICENCE_NAME = "Apache License v2.0" - POM_LICENCE_URL = "https://github.com/topjohnwu/libcxx/blob/master/LICENSE.TXT" - POM_LICENCE_DIST = "repo" - - POM_DEVELOPER_ID = "rikka" - POM_DEVELOPER_NAME = "Rikka" - POM_DEVELOPER_URL = "https://github.com/RikkaW" -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..7dc3f25 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + alias(libs.plugins.lsplugin.publish) +} + +val androidTargetSdkVersion by extra(34) +val androidMinSdkVersion by extra(21) +val androidBuildToolsVersion by extra("34.0.0") +val androidCompileSdkVersion by extra(34) +val androidNdkVersion by extra("27.0.11718014-beta1") +val androidCmakeVersion by extra("3.28.0+") diff --git a/cxx-source b/cxx-source deleted file mode 160000 index b74fd59..0000000 --- a/cxx-source +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b74fd5905f1064c1a33b213fca58b45441651ad1 diff --git a/cxx/build.gradle b/cxx/build.gradle deleted file mode 100644 index 1bb16ed..0000000 --- a/cxx/build.gradle +++ /dev/null @@ -1,78 +0,0 @@ -import java.nio.file.Files -import java.nio.file.Paths - -plugins { - id 'com.android.library' - id 'com.vanniktech.maven.publish' -} - -android { - compileSdkVersion 31 - buildToolsVersion "30.0.3" - defaultConfig { - minSdkVersion 16 - targetSdkVersion 31 - versionCode 1 - versionName "1.2.0" - externalNativeBuild { - ndkBuild { - arguments "-j${Runtime.getRuntime().availableProcessors()}" - } - } - } - buildFeatures { - androidResources false - prefabPublishing true - buildConfig false - } - externalNativeBuild { - ndkBuild { - path "jni/Android.mk" - } - } - prefab { - cxx { - headers "$rootDir/cxx-source/include" - } - } -} - -// NDK does not run strip on static libraries, do it ourselves -def allAbi = [ - 'armeabi-v7a': 'arm-linux-androideabi-strip', - 'arm64-v8a' : 'aarch64-linux-android-strip', - 'x86' : 'i686-linux-android-strip', - 'x86_64' : 'x86_64-linux-android-strip'] - -def stripNativeRelease = task('stripNativeRelease').doLast { - def isWindows = org.gradle.internal.os.OperatingSystem.current().isWindows() - - for (String abi : allAbi.keySet()) { - def path = Paths.get(project.buildDir.path, 'intermediates', - 'ndkBuild', 'release', 'obj', 'local', abi) - def lib = path.resolve('libcxx.a') - - def toolchain = Paths.get(android.ndkDirectory.toString(), 'toolchains', 'llvm', 'prebuilt') - toolchain = Files.walk(toolchain).filter { it != toolchain }.findFirst().get() - - def strip = "${allAbi.get(abi)}${isWindows ? ".exe" : ""}" - def stripPath = toolchain.resolve(Paths.get('bin', strip)) - - exec { - commandLine stripPath, '--strip-unneeded', '--remove-section=.comment', lib - workingDir path - ignoreExitValue false - } - } -} - -tasks.whenTaskAdded { task -> - if (task.name == 'externalNativeBuildRelease') { - task.finalizedBy stripNativeRelease - } -} - -ext { - POM_NAME = "libcxx Prefab" - POM_DESCRIPTION = "LLVM libc++, specifically for Android, removing exception and RTTI support (https://github.com/topjohnwu/libcxx)." -} diff --git a/cxx/build.gradle.kts b/cxx/build.gradle.kts new file mode 100644 index 0000000..812495a --- /dev/null +++ b/cxx/build.gradle.kts @@ -0,0 +1,111 @@ +plugins { + alias(libs.plugins.agp.lib) + alias(libs.plugins.lsplugin.jgit) + alias(libs.plugins.lsplugin.publish) + alias(libs.plugins.lsplugin.cmaker) + `maven-publish` + signing +} + +val androidTargetSdkVersion: Int by rootProject.extra +val androidMinSdkVersion: Int by rootProject.extra +val androidBuildToolsVersion: String by rootProject.extra +val androidCompileSdkVersion: Int by rootProject.extra +val androidNdkVersion: String by rootProject.extra +val androidCmakeVersion: String by rootProject.extra + + +android { + compileSdk = androidCompileSdkVersion + ndkVersion = androidNdkVersion + buildToolsVersion = androidBuildToolsVersion + + buildFeatures { + buildConfig = false + prefabPublishing = true + androidResources = false + prefab = true + } + + packaging { + jniLibs { + excludes += "**.so" + } + } + + prefab { + register("cxx") { + headers = "jni/libcxx/include" + } + } + + defaultConfig { + minSdk = androidMinSdkVersion + } + + lint { + abortOnError = true + checkReleaseBuilds = false + } + + externalNativeBuild { + cmake { + path = file("jni/CMakeLists.txt") + version = androidCmakeVersion + } + } + namespace = "org.lsposed.libcxx" + + publishing { + singleVariant("release") { + withSourcesJar() + withJavadocJar() + } + } +} + +cmaker { + default { + abiFilters("armeabi-v7a", "arm64-v8a", "x86", "x86_64", "riscv64") + arguments += "-DANDROID_STL=none" + arguments += "-DCMAKE_VERBOSE_MAKEFILE=ON" + } + buildTypes { + + } +} + +publish { + githubRepo = "LSPosed/prefab-libcxx" + publications { + register("libcxx") { + artifactId = "libcxx" + afterEvaluate { + from(components.getByName("release")) + } + group = "org.lsposed.libcxx" + version = androidNdkVersion + pom { + name.set("libcxx") + description.set("libcxx") + url.set("https://github.com/LSPosed/prefab-libcxx") + licenses { + license { + name.set("Apache v2.0") + url.set("https://github.com/llvm/llvm-project/blob/main/LICENSE.TXT") + } + } + developers { + developer { + name.set("LLVM") + url.set("https://llvm.org/") + } + } + scm { + connection.set("scm:git:https://github.com/LSPosed/prefab-libcxx.git") + url.set("https://github.com/LSPosed/prefab-libcxx") + } + } + } + } +} diff --git a/cxx/jni/Android.mk b/cxx/jni/Android.mk deleted file mode 100644 index 1c7902a..0000000 --- a/cxx/jni/Android.mk +++ /dev/null @@ -1,3 +0,0 @@ -LOCAL_PATH := $(call my-dir)/../../cxx-source - -include $(LOCAL_PATH)/Android.mk \ No newline at end of file diff --git a/cxx/jni/Application.mk b/cxx/jni/Application.mk deleted file mode 100644 index 8cbef05..0000000 --- a/cxx/jni/Application.mk +++ /dev/null @@ -1,6 +0,0 @@ -APP_ABI := arm64-v8a armeabi-v7a x86 x86_64 -APP_PROJECT_PATH := $(call my-dir)/../../cxx-source -APP_PLATFORM := android-16 -APP_CPPFLAGS := -std=c++17 -APP_STL := none -APP_CFLAGS := -Wno-builtin-macro-redefined -D__FILE__=__FILE_NAME__ \ No newline at end of file diff --git a/cxx/jni/CMakeLists.txt b/cxx/jni/CMakeLists.txt new file mode 100644 index 0000000..115778d --- /dev/null +++ b/cxx/jni/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.22.1) + +project(cxx) + +set(CMAKE_CXX_STANDARD 23) + +file(GLOB LIBCXX_SOURCES "libcxx/src/*.cpp" "libcxx/src/filesystem/*.cpp") + +list(FILTER LIBCXX_SOURCES EXCLUDE REGEX ".*/(tzdb_list|tz|locale|ios|iostream|ostream|fstream|regex|ios.instantiations|strstream)\.cpp$") + +message(STATUS "LIBCXX_SOURCES: ${LIBCXX_SOURCES}") + +set(LIBCXX_EXPORT_FLAGS + -DLIBCXX_BUILDING_LIBCXXABI + -D_LIBCPP_HAS_NO_EXCEPTIONS + -D_LIBCPP_NO_RTTI + -D_LIBCPP_BUILDING_LIBRARY + -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS + -D_LIBCXXABI_NO_EXCEPTIONS + -D_LIBCPP_HAS_NO_LOCALIZATION +) +set(LIBCXX_FLAGS + -fvisibility-global-new-delete-hidden + -fvisibility=hidden + -fvisibility-inlines-hidden +) +set(LIBCXX_EXPORT_INCLUDES libcxx/include) +set(LIBCXX_INCLUDES libcxx/src) + +set(LIBCXXABI_SOURCES + abort_message.cpp + cxa_aux_runtime.cpp + cxa_default_handlers.cpp + cxa_exception_storage.cpp + cxa_guard.cpp + cxa_handlers.cpp + cxa_noexception.cpp + cxa_thread_atexit.cpp + cxa_vector.cpp + cxa_virtual.cpp + stdlib_exception.cpp + stdlib_new_delete.cpp + stdlib_stdexcept.cpp + stdlib_typeinfo.cpp +) +list(TRANSFORM LIBCXXABI_SOURCES PREPEND libcxxabi/src/) +set(LIBCXXABI_FLAGS + -Wno-macro-redefined + -Wno-unknown-attributes + -DHAS_THREAD_LOCAL) +set(LIBCXXABI_INCLUDES libcxxabi/include) + +add_library(cxx STATIC ${LIBCXX_SOURCES} ${LIBCXXABI_SOURCES}) +target_compile_options(cxx PUBLIC ${LIBCXX_EXPORT_FLAGS}) +target_compile_options(cxx PRIVATE ${LIBCXX_FLAGS} ${LIBCXXABI_FLAGS} -ffunction-sections -fdata-sections) +target_include_directories(cxx PUBLIC ${LIBCXX_EXPORT_INCLUDES}) +target_include_directories(cxx PRIVATE ${LIBCXX_INCLUDES} ${LIBCXXABI_INCLUDES}) + +target_compile_options(cxx PRIVATE -flto) +target_link_options(cxx PRIVATE -flto) diff --git a/cxx/jni/libcxx/.clang-format b/cxx/jni/libcxx/.clang-format new file mode 100644 index 0000000..56bdf2b --- /dev/null +++ b/cxx/jni/libcxx/.clang-format @@ -0,0 +1,82 @@ +BasedOnStyle: LLVM +# Note that we don't specify the language in this file because some files are +# detected as Cpp, but others are detected as ObjC and we want this formatting +# to apply to all types of files. + +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: Consecutive +AlignEscapedNewlines: Right +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortFunctionsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AttributeMacros: [ + '_ALIGNAS_TYPE', + '_ALIGNAS', + '_LIBCPP_ALIGNOF', + '_LIBCPP_ALWAYS_INLINE', + '_LIBCPP_CONSTEXPR_SINCE_CXX14', + '_LIBCPP_CONSTEXPR_SINCE_CXX17', + '_LIBCPP_CONSTEXPR_SINCE_CXX20', + '_LIBCPP_CONSTEXPR_SINCE_CXX23', + '_LIBCPP_CONSTEXPR', + '_LIBCPP_CONSTINIT', + '_LIBCPP_DEPRECATED_IN_CXX11', + '_LIBCPP_DEPRECATED_IN_CXX14', + '_LIBCPP_DEPRECATED_IN_CXX17', + '_LIBCPP_DEPRECATED_IN_CXX20', + '_LIBCPP_DEPRECATED', + '_LIBCPP_DISABLE_EXTENTSION_WARNING', + '_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION', + '_LIBCPP_EXPORTED_FROM_ABI', + '_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS', + '_LIBCPP_FALLTHROUGH', + '_LIBCPP_HIDDEN', + '_LIBCPP_HIDE_FROM_ABI_AFTER_V1', + '_LIBCPP_HIDE_FROM_ABI', + '_LIBCPP_INTERNAL_LINKAGE', + '_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS', + '_LIBCPP_NO_SANITIZE', + '_LIBCPP_NO_UNIQUE_ADDRESS', + '_LIBCPP_NOALIAS', + '_LIBCPP_NODISCARD_EXT', + '_LIBCPP_NODISCARD', + '_LIBCPP_NORETURN', + '_LIBCPP_OVERRIDABLE_FUNC_VIS', + '_LIBCPP_STANDALONE_DEBUG', + '_LIBCPP_TEMPLATE_DATA_VIS', + '_LIBCPP_TEMPLATE_VIS', + '_LIBCPP_THREAD_SAFETY_ANNOTATION', + '_LIBCPP_USING_IF_EXISTS', + '_LIBCPP_WEAK', + ] +BinPackArguments: false +BinPackParameters: false +BreakBeforeConceptDeclarations: true +BreakInheritanceList: BeforeColon +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +IndentWrappedFunctionNames: false +IndentRequires: true +InsertTrailingCommas: Wrapped +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +PackConstructorInitializers: NextLine + +PenaltyIndentedWhitespace: 2 + +Standard: c++20 +SpacesInAngles: Leave + +AlwaysBreakTemplateDeclarations: true +PointerAlignment: Left + + +# libc++'s preferred indentions of preprocessor statements. +IndentPPDirectives: AfterHash + +# libc++ has some long names so we need more than the 80 column limit imposed by LLVM style, for sensible formatting +ColumnLimit: 120 diff --git a/cxx/jni/libcxx/.clang-tidy b/cxx/jni/libcxx/.clang-tidy new file mode 100644 index 0000000..2146617 --- /dev/null +++ b/cxx/jni/libcxx/.clang-tidy @@ -0,0 +1,79 @@ +Checks: > + bugprone-copy-constructor-init, + bugprone-dangling-handle, + bugprone-infinite-loop, + bugprone-stringview-nullptr, + bugprone-use-after-move, + + llvm-include-order, + llvm-namespace-comment, + + misc-definitions-in-headers, + misc-misplaced-const, + misc-non-copyable-objects, + misc-uniqueptr-reset-release, + + modernize-loop-convert, + modernize-redundant-void-arg, + modernize-use-override, + + readability-duplicate-include, + readability-identifier-naming, + readability-function-cognitive-complexity, + readability-function-size, + readability-misplaced-array-index, + readability-redundant-control-flow, + readability-redundant-function-ptr-dereference, + readability-redundant-preprocessor, + readability-simplify-boolean-expr, + readability-simplify-subscript-expr, + readability-uniqueptr-delete-release, + +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: 143 # TODO: bring that number down + - key: readability-function-size.LineThreshold + value: 194 # TODO: bring that number down + - key: readability-identifier-naming.GetConfigPerFile + value: false + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.ParameterPrefix + value: __ + - key: readability-identifier-naming.PrivateMemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberPrefix + value: __ + - key: readability-identifier-naming.PrivateMemberSuffix + value: _ + - key: readability-identifier-naming.LocalVariableCase + value: lower_case + - key: readability-identifier-naming.LocalVariablePrefix + value: __ + - key: readability-identifier-naming.TemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TemplateParameterPrefix + value: _ + - key: readability-identifier-naming.TemplateParameterIgnoredRegexp + value: (.*\:auto|expr-type) # This is https://llvm.org/PR56464 + - key: readability-identifier-naming.ValueTemplateParameterIgnoredRegexp # TODO: enforce naming of variable parameters + value: .* + +# TODO: investigate these checks +# bugprone-branch-clone, +# bugprone-macro-parentheses, +# cppcoreguidelines-prefer-member-initializer, +# misc-unused-parameters, +# modernize-use-bool-literals, +# modernize-use-default-member-init, +# modernize-use-equals-default, +# modernize-use-equals-delete, +# modernize-use-nullptr, +# portability-restrict-system-includes, +# readability-function-cognitive-complexity, +# readability-implicit-bool-conversion, +# readability-isolate-declaration, +# readability-redundant-access-specifiers, +# readability-redundant-declaration, +# readability-redundant-member-init, +# diff --git a/cxx/jni/libcxx/.gitignore b/cxx/jni/libcxx/.gitignore new file mode 100644 index 0000000..4b214ca --- /dev/null +++ b/cxx/jni/libcxx/.gitignore @@ -0,0 +1,55 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +#lib/ # We actually have things checked in to lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# MSVC libraries test harness +env.lst +keep.lst + +# Editor by-products +.vscode/ diff --git a/cxx/jni/libcxx/CMakeLists.txt b/cxx/jni/libcxx/CMakeLists.txt new file mode 100644 index 0000000..75cb632 --- /dev/null +++ b/cxx/jni/libcxx/CMakeLists.txt @@ -0,0 +1,884 @@ +# See https://libcxx.llvm.org/docs/BuildingLibcxx.html for instructions on how +# to build libcxx with CMake. + +#=============================================================================== +# Setup Project +#=============================================================================== +cmake_minimum_required(VERSION 3.20.0) + +set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") + +# Add path for custom modules +list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" + "${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules" + "${LLVM_COMMON_CMAKE_UTILS}" + "${LLVM_COMMON_CMAKE_UTILS}/Modules" + ) + +set(CMAKE_FOLDER "libc++") + +set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") + +include(GNUInstallDirs) +include(WarningFlags) + +# Require out of source build. +include(MacroEnsureOutOfSourceBuild) +MACRO_ENSURE_OUT_OF_SOURCE_BUILD( + "${PROJECT_NAME} requires an out of source build. Please create a separate + build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." + ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") + message(STATUS "Configuring for clang-cl") + set(LIBCXX_TARGETING_CLANG_CL ON) +endif() + +if (MSVC) + message(STATUS "Configuring for MSVC") +endif() + +#=============================================================================== +# Setup CMake Options +#=============================================================================== +include(CMakeDependentOption) +include(HandleCompilerRT) + +# Basic options --------------------------------------------------------------- +option(LIBCXX_ENABLE_ASSERTIONS + "Enable assertions inside the compiled library, and at the same time make it the + default when compiling user code. Note that assertions can be enabled or disabled + by users in their own code regardless of this option." OFF) +option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) +option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) +option(LIBCXX_ENABLE_FILESYSTEM + "Whether to include support for parts of the library that rely on a filesystem being + available on the platform. This includes things like most parts of and + others like " ON) +option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) +set(LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug) +set(LIBCXX_HARDENING_MODE "none" CACHE STRING + "Specify the default hardening mode to use. This mode will be used inside the + compiled library and will be the default when compiling user code. Note that + users can override this setting in their own code. This does not affect the + ABI. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.") +if (NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES) + message(FATAL_ERROR + "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.") +endif() +option(LIBCXX_ENABLE_RANDOM_DEVICE + "Whether to include support for std::random_device in the library. Disabling + this can be useful when building the library for platforms that don't have + a source of randomness, such as some embedded platforms. When this is not + supported, most of will still be available, but std::random_device + will not." ON) +option(LIBCXX_ENABLE_LOCALIZATION + "Whether to include support for localization in the library. Disabling + localization can be useful when porting to platforms that don't support + the C locale API (e.g. embedded). When localization is not supported, + several parts of the library will be disabled: , , + will be completely unusable, and other parts may be only partly available." ON) +option(LIBCXX_ENABLE_UNICODE + "Whether to include support for Unicode in the library. Disabling Unicode can + be useful when porting to platforms that don't support UTF-8 encoding (e.g. + embedded)." ON) +option(LIBCXX_ENABLE_WIDE_CHARACTERS + "Whether to include support for wide characters in the library. Disabling + wide character support can be useful when porting to platforms that don't + support the C functionality for wide characters. When wide characters are + not supported, several parts of the library will be disabled, notably the + wide character specializations of std::basic_string." ON) + +# To use time zone support in libc++ the platform needs to have the IANA +# database installed. Libc++ will fail to build if this is enabled on a +# platform that does not provide the IANA database. The default is set to the +# current implementation state on the different platforms. +# +# TODO TZDB make the default always ON when most platforms ship with the IANA +# database. +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(ENABLE_TIME_ZONE_DATABASE_DEFAULT ON) +else() + set(ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF) +endif() +option(LIBCXX_ENABLE_TIME_ZONE_DATABASE + "Whether to include support for time zones in the library. Disabling + time zone support can be useful when porting to platforms that don't + ship the IANA time zone database. When time zones are not supported, + time zone support in will be disabled." ${ENABLE_TIME_ZONE_DATABASE_DEFAULT}) +option(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS + "Whether to turn on vendor availability annotations on declarations that depend + on definitions in a shared library. By default, we assume that we're not building + libc++ for any specific vendor, and we disable those annotations. Vendors wishing + to provide compile-time errors when using features unavailable on some version of + the shared library they shipped should turn this on and see `include/__availability` + for more details." OFF) +option(LIBCXX_ENABLE_CLANG_TIDY "Whether to compile and run clang-tidy checks" OFF) +# TODO MODULES Remove this option and test for the requirements (CMake/Clang) instead. +option(LIBCXX_ENABLE_STD_MODULES + "Whether to enable the building the C++23 `std` module. This feature is + experimental and has additional dependencies. Only enable this when + interested in testing or developing this module. See + https://libcxx.llvm.org/Modules.html for more information." OFF) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in") +elseif(MINGW) + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in") +elseif(WIN32) # clang-cl + if (LIBCXX_ENABLE_SHARED) + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in") + else() + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in") + endif() +else() + if (LIBCXX_ENABLE_SHARED) + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in") + else() + set(LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in") + endif() +endif() +set(LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING + "The path to the Lit testing configuration to use when running the tests. + If a relative path is provided, it is assumed to be relative to '/libcxx/test/configs'.") +if (NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}") + set(LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}") +endif() +message(STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}") +set(LIBCXX_TEST_PARAMS "" CACHE STRING + "A list of parameters to run the Lit test suite with.") + +# Benchmark options ----------------------------------------------------------- +option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ON) + +set(LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT --benchmark_min_time=0.01) +set(LIBCXX_BENCHMARK_TEST_ARGS "${LIBCXX_BENCHMARK_TEST_ARGS_DEFAULT}" CACHE STRING + "Arguments to pass when running the benchmarks using check-cxx-benchmarks") + +set(LIBCXX_BENCHMARK_NATIVE_STDLIB "" CACHE STRING + "Build the benchmarks against the specified native STL. + The value must be one of libc++/libstdc++") +set(LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN "" CACHE STRING + "Use alternate GCC toolchain when building the native benchmarks") + +if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + if (NOT (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libc++" + OR LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++")) + message(FATAL_ERROR "Invalid value for LIBCXX_BENCHMARK_NATIVE_STDLIB: " + "'${LIBCXX_BENCHMARK_NATIVE_STDLIB}'") + endif() +endif() + +option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) +set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING + "Define suffix of library directory name (32/64)") +option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) +option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) +cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY + "Install the static libc++ library." ON + "LIBCXX_ENABLE_STATIC;LIBCXX_INSTALL_LIBRARY" OFF) +cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY + "Install the shared libc++ library." ON + "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF) + +option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF) +if (LIBCXX_ABI_UNSTABLE) + set(abi_version "2") +else() + set(abi_version "1") +endif() +set(LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING + "ABI version of libc++. Can be either 1 or 2, where 2 is currently the unstable ABI. + Defaults to 1 unless LIBCXX_ABI_UNSTABLE is specified, in which case this is 2.") +set(LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING + "Version of libc++. This will be reflected in the name of the shared library produced. + For example, -DLIBCXX_LIBRARY_VERSION=x.y will result in the library being named + libc++.x.y.dylib, along with the usual symlinks pointing to that. On Apple platforms, + this also controls the linker's 'current_version' property.") +set(LIBCXX_ABI_NAMESPACE "__${LIBCXX_ABI_VERSION}" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version.") +if (NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*") + message(FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'.") +endif() +option(LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI.") +option(LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI.") + +set(LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING + "Override the implementation to use for comparing typeinfos. By default, this + is detected automatically by the library, but this option allows overriding + which implementation is used unconditionally. + + See the documentation in for details on what each + value means.") +set(TYPEINFO_COMPARISON_VALUES "default;1;2;3") +if (NOT ("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES)) + message(FATAL_ERROR "Value '${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}' is not a valid value for + LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION") +endif() + +set(LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header.") +set(LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site") +option(LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF) + +# ABI Library options --------------------------------------------------------- +if (MSVC) + set(LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime") +elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxrt") +else() + set(LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi") +endif() + +set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime) +set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.") +if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES) + message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.") +endif() + +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY + "Use a static copy of the ABI library when linking libc++. + This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF) + +option(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY + "Statically link the ABI library to static library" + ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) + +option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY + "Statically link the ABI library to shared library" + ${LIBCXX_ENABLE_STATIC_ABI_LIBRARY}) + +# Generate and install a linker script inplace of libc++.so. The linker script +# will link libc++ to the correct ABI library. This option is on by default +# on UNIX platforms other than Apple, and on the Fuchsia platform unless we +# statically link libc++abi inside libc++.so, we don't build libc++.so at all +# or we don't have any ABI library. +if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY + OR NOT LIBCXX_ENABLE_SHARED + OR LIBCXX_CXX_ABI STREQUAL "none") + set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) +elseif((UNIX OR FUCHSIA) AND NOT APPLE) + set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) +else() + set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) +endif() +option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT + "Use and install a linker script for the given ABI library" + ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) + +option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS + "Build libc++ with definitions for operator new/delete. These are normally + defined in libc++abi, but this option can be used to define them in libc++ + instead. If you define them in libc++, make sure they are NOT defined in + libc++abi. Doing otherwise is an ODR violation." OFF) +# Build libc++abi with libunwind. We need this option to determine whether to +# link with libunwind or libgcc_s while running the test cases. +option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) + +# Target options -------------------------------------------------------------- +option(LIBCXX_BUILD_32_BITS "Build 32 bit multilib libc++. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS}) +if (LIBCXX_BUILD_32_BITS) + message(FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead.") +endif() + +# Feature options ------------------------------------------------------------- +option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) +option(LIBCXX_ENABLE_RTTI + "Use runtime type information. + This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON) +option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) +option(LIBCXX_ENABLE_MONOTONIC_CLOCK + "Build libc++ with support for a monotonic clock. + This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) +option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) +option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) +option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF) +option(LIBCXX_HAS_EXTERNAL_THREAD_API + "Build libc++ with an externalized threading API. + This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF) + +if (LIBCXX_ENABLE_THREADS) + set(LIBCXX_PSTL_CPU_BACKEND "std_thread" CACHE STRING "Which PSTL CPU backend to use") +else() + set(LIBCXX_PSTL_CPU_BACKEND "serial" CACHE STRING "Which PSTL CPU backend to use") +endif() + +# Misc options ---------------------------------------------------------------- +# FIXME: Turn -pedantic back ON. It is currently off because it warns +# about #include_next which is used everywhere. +option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) +option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) + +option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) +set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING + "The Profile-rt library used to build with code coverage") + +set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) +if (XCODE OR MSVC_IDE) + set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) +endif() +option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" + ${LIBCXX_CONFIGURE_IDE_DEFAULT}) + +set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF) +if (WIN32) + set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON) +endif() +option(LIBCXX_HERMETIC_STATIC_LIBRARY + "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT}) + +#=============================================================================== +# Check option configurations +#=============================================================================== + +# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when +# LIBCXX_ENABLE_THREADS is on. +if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) + message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" + " when LIBCXX_ENABLE_THREADS is also set to OFF.") +endif() + +if(NOT LIBCXX_ENABLE_THREADS) + if(LIBCXX_HAS_PTHREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON" + " when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + if(LIBCXX_HAS_EXTERNAL_THREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON" + " when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON" + " when LIBCXX_ENABLE_THREADS is also set to ON.") + endif() + +endif() + +if (LIBCXX_HAS_EXTERNAL_THREAD_API) + if (LIBCXX_HAS_PTHREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" + " and LIBCXX_HAS_PTHREAD_API cannot be both" + " set to ON at the same time.") + endif() + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API" + " and LIBCXX_HAS_WIN32_THREAD_API cannot be both" + " set to ON at the same time.") + endif() +endif() + +if (LIBCXX_HAS_PTHREAD_API) + if (LIBCXX_HAS_WIN32_THREAD_API) + message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API" + " and LIBCXX_HAS_WIN32_THREAD_API cannot be both" + " set to ON at the same time.") + endif() +endif() + +if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS) + message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI" + " disabled, since that configuration is broken. See" + " https://github.com/llvm/llvm-project/issues/66117" + " for details.") +endif() + +# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE +# is ON. +if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) + message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") +endif() + +if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + if (APPLE) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") + endif() + if (NOT LIBCXX_ENABLE_SHARED) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds.") + endif() +endif() + +if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + message(FATAL_ERROR "Conflicting options given. + LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with + LIBCXX_ENABLE_ABI_LINKER_SCRIPT") +endif() + +if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT) + message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.") +endif () + +if (LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND + (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")) + message(WARNING "A static CRT linked into a shared libc++ doesn't work correctly.") +endif() + +#=============================================================================== +# Configure System +#=============================================================================== + +# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR +# instead of hard-coding include/c++/v1. + +set(LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING + "Path where target-agnostic libc++ headers should be installed.") +set(LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING + "Path where built libc++ runtime libraries should be installed.") + +set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.") +set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.") + +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") + set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE STRING + "Path where target-specific libc++ headers should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + endif() +else() + if(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1") + else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") + set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE STRING + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING + "Path where target-specific libc++ headers should be installed.") +endif() + +file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) + +# Declare libc++ configuration variables. +# They are intended for use as follows: +# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. +# LIBCXX_COMPILE_FLAGS: Compile only flags. +# LIBCXX_LINK_FLAGS: Linker only flags. +# LIBCXX_LIBRARIES: libraries libc++ is linked to. +set(LIBCXX_COMPILE_FLAGS "") +set(LIBCXX_LINK_FLAGS "") +set(LIBCXX_LIBRARIES "") +set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING + "Additional Compile only flags which can be provided in cache") +set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING + "Additional libraries libc++ is linked to which can be provided in cache") + +# Include macros for adding and removing libc++ flags. +include(HandleLibcxxFlags) + +# Target flags ================================================================ +# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that +# 'config-ix' use them during feature checks. It also adds them to both +# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS' + +if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_flags_if_supported("-mdefault-visibility-export-mapping=explicit") + set(CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF) +endif() + +# Configure compiler. +include(config-ix) + +# Configure coverage options. +if (LIBCXX_GENERATE_COVERAGE) + include(CodeCoverage) + set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) +endif() + +#=============================================================================== +# Setup Compiler Flags +#=============================================================================== + +include(HandleLibCXXABI) # Setup the ABI library flags + +# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. +# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors +# so they don't get transformed into -Wno and -errors respectively. +remove_flags(-Wno-pedantic -pedantic-errors -pedantic) + +# Required flags ============================================================== +function(cxx_add_basic_build_flags target) + + # Use C++23 for all targets. + set_target_properties(${target} PROPERTIES + CXX_STANDARD 23 + CXX_STANDARD_REQUIRED OFF # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake + CXX_EXTENSIONS NO) + + # When building the dylib, don't warn for unavailable aligned allocation + # functions based on the deployment target -- they are always available + # because they are provided by the dylib itself with the exception of z/OS. + if (ZOS) + target_add_compile_flags_if_supported(${target} PRIVATE -fno-aligned-allocation) + else() + target_add_compile_flags_if_supported(${target} PRIVATE -faligned-allocation) + endif() + + # On all systems the system c++ standard library headers need to be excluded. + # MSVC only has -X, which disables all default includes; including the crt. + # Thus, we do nothing and hope we don't accidentally include any of the C++ + # headers + target_add_compile_flags_if_supported(${target} PUBLIC -nostdinc++) + + # Hide all inline function definitions which have not explicitly been marked + # visible. This prevents new definitions for inline functions from appearing in + # the dylib when get ODR used by another function. + target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility-inlines-hidden) + + # Our visibility annotations are not quite right for non-Clang compilers, + # so we end up not exporting all the symbols we should. In the future, we + # can improve the situation by providing an explicit list of exported + # symbols on all compilers. + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_add_compile_flags_if_supported(${target} PRIVATE -fvisibility=hidden) + endif() + + # Let the library headers know they are currently being used to build the + # library. + target_compile_definitions(${target} PRIVATE -D_LIBCPP_BUILDING_LIBRARY) + + # Make sure the library can be build without transitive includes. This makes + # it easier to upgrade the library to a newer language standard without build + # errors. + target_compile_definitions(${target} PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) + + if (C_SUPPORTS_COMMENT_LIB_PRAGMA) + if (LIBCXX_HAS_PTHREAD_LIB) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB) + endif() + if (LIBCXX_HAS_RT_LIB) + target_compile_definitions(${target} PRIVATE -D_LIBCPP_LINK_RT_LIB) + endif() + endif() + target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}") +endfunction() + +# Exception flags ============================================================= +function(cxx_add_exception_flags target) + if (LIBCXX_ENABLE_EXCEPTIONS) + # Catches C++ exceptions only and tells the compiler to assume that extern C + # functions never throw a C++ exception. + target_add_compile_flags_if_supported(${target} PUBLIC -EHsc) + else() + target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-) + target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions) + endif() +endfunction() + +# RTTI flags ================================================================== +function(cxx_add_rtti_flags target) + if (NOT LIBCXX_ENABLE_RTTI) + if (MSVC) + target_add_compile_flags_if_supported(${target} PUBLIC -GR-) + else() + target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti) + endif() + endif() +endfunction() + +# Modules flags =============================================================== +# FIXME The libc++ sources are fundamentally non-modular. They need special +# versions of the headers in order to provide C++03 and legacy ABI definitions. +# NOTE: The public headers can be used with modules in all other contexts. +function(cxx_add_module_flags target) + if (LLVM_ENABLE_MODULES) + # Ignore that the rest of the modules flags are now unused. + target_add_compile_flags_if_supported(${target} PUBLIC -Wno-unused-command-line-argument) + target_compile_options(${target} PUBLIC -fno-modules) + endif() +endfunction() + +string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + +# Sanitizer flags ============================================================= + +function(get_sanitizer_flags OUT_VAR USE_SANITIZER) + set(SANITIZER_FLAGS) + set(USE_SANITIZER "${USE_SANITIZER}") + # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. + # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. + if (USE_SANITIZER AND NOT MSVC) + append_flags_if_supported(SANITIZER_FLAGS "-fno-omit-frame-pointer") + append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") + + if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND + NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + append_flags_if_supported(SANITIZER_FLAGS "-gline-tables-only") + endif() + if (USE_SANITIZER STREQUAL "Address") + append_flags(SANITIZER_FLAGS "-fsanitize=address") + elseif (USE_SANITIZER STREQUAL "HWAddress") + append_flags(SANITIZER_FLAGS "-fsanitize=hwaddress") + elseif (USE_SANITIZER MATCHES "Memory(WithOrigins)?") + append_flags(SANITIZER_FLAGS -fsanitize=memory) + if (USE_SANITIZER STREQUAL "MemoryWithOrigins") + append_flags(SANITIZER_FLAGS "-fsanitize-memory-track-origins") + endif() + elseif (USE_SANITIZER STREQUAL "Undefined") + append_flags(SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all") + elseif (USE_SANITIZER STREQUAL "Address;Undefined" OR + USE_SANITIZER STREQUAL "Undefined;Address") + append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all") + elseif (USE_SANITIZER STREQUAL "Thread") + append_flags(SANITIZER_FLAGS -fsanitize=thread) + elseif (USE_SANITIZER STREQUAL "DataFlow") + append_flags(SANITIZER_FLAGS -fsanitize=dataflow) + else() + message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") + endif() + elseif(USE_SANITIZER AND MSVC) + message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") + endif() + set(${OUT_VAR} "${SANITIZER_FLAGS}" PARENT_SCOPE) +endfunction() + +get_sanitizer_flags(SANITIZER_FLAGS "${LLVM_USE_SANITIZER}") +add_library(cxx-sanitizer-flags INTERFACE) +target_compile_options(cxx-sanitizer-flags INTERFACE ${SANITIZER_FLAGS}) + +# _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan. +# Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required. +# Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether +# dylibs are built with AddressSanitizer. However, when building libc++, +# this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag. +# If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++ +# will not be compiled into it, resulting in false positives. +# For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800 +string(FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan) +if (NOT "${building_with_asan}" STREQUAL "-1") + config_define(ON _LIBCPP_INSTRUMENTED_WITH_ASAN) +endif() + +# Link system libraries ======================================================= +function(cxx_link_system_libraries target) + if (NOT MSVC) + target_link_libraries(${target} PRIVATE "-nostdlib++") + endif() + + if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER) + # If we're linking directly against the libunwind that we're building + # in the same invocation, don't try to link in the toolchain's + # default libunwind (which may be missing still). + target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none") + endif() + + if (MSVC) + if (LIBCXX_USE_COMPILER_RT) + find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) + if (LIBCXX_BUILTINS_LIBRARY) + target_link_libraries(${target} PRIVATE "${LIBCXX_BUILTINS_LIBRARY}") + endif() + elseif (LIBCXX_HAS_GCC_LIB) + target_link_libraries(${target} PRIVATE gcc) + elseif (LIBCXX_HAS_GCC_S_LIB) + target_link_libraries(${target} PRIVATE gcc_s) + endif() + endif() + + if (LIBCXX_HAS_ATOMIC_LIB) + target_link_libraries(${target} PRIVATE atomic) + endif() + + if (MINGW) + target_link_libraries(${target} PRIVATE "${MINGW_LIBRARIES}") + endif() + + if (MSVC) + if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") + OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug")) + set(LIB_SUFFIX "d") + else() + set(LIB_SUFFIX "") + endif() + + if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$") + set(CRT_LIB "msvcrt") + set(CXX_LIB "msvcprt") + else() + set(CRT_LIB "libcmt") + set(CXX_LIB "libcpmt") + endif() + + target_link_libraries(${target} PRIVATE ${CRT_LIB}${LIB_SUFFIX}) # C runtime startup files + target_link_libraries(${target} PRIVATE ${CXX_LIB}${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. + # Required for standards-complaint wide character formatting functions + # (e.g. `printfw`/`scanfw`) + target_link_libraries(${target} PRIVATE iso_stdio_wide_specifiers) + endif() + + if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21) + target_link_libraries(${target} PUBLIC android_support) + endif() + target_link_libraries(${target} PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}") +endfunction() + +# Windows-related flags ======================================================= +function(cxx_add_windows_flags target) + if(WIN32 AND NOT MINGW) + target_compile_definitions(${target} PRIVATE + # Ignore the -MSC_VER mismatch, as we may build + # with a different compatibility version. + _ALLOW_MSC_VER_MISMATCH + # Don't check the msvcprt iterator debug levels + # as we will define the iterator types; libc++ + # uses a different macro to identify the debug + # level. + _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH + # We are building the c++ runtime, don't pull in + # msvcprt. + _CRTBLD + # Don't warn on the use of "deprecated" + # "insecure" functions which are standards + # specified. + _CRT_SECURE_NO_WARNINGS + # Use the ISO conforming behaviour for conversion + # in printf, scanf. + _CRT_STDIO_ISO_WIDE_SPECIFIERS) + endif() +endfunction() + +# Configuration file flags ===================================================== +config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) +config_define(${LIBCXX_ABI_NAMESPACE} _LIBCPP_ABI_NAMESPACE) +config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM) +config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT) +config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) +config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) +if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default") + config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION) +endif() +config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD) +config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL) +config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32) +config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) +config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) +config_define_if_not(LIBCXX_ENABLE_FILESYSTEM _LIBCPP_HAS_NO_FILESYSTEM) +config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE) +config_define_if_not(LIBCXX_ENABLE_LOCALIZATION _LIBCPP_HAS_NO_LOCALIZATION) +config_define_if_not(LIBCXX_ENABLE_UNICODE _LIBCPP_HAS_NO_UNICODE) +config_define_if_not(LIBCXX_ENABLE_WIDE_CHARACTERS _LIBCPP_HAS_NO_WIDE_CHARACTERS) +config_define_if_not(LIBCXX_ENABLE_STD_MODULES _LIBCPP_HAS_NO_STD_MODULES) +config_define_if_not(LIBCXX_ENABLE_TIME_ZONE_DATABASE _LIBCPP_HAS_NO_TIME_ZONE_DATABASE) +config_define_if_not(LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) + +# TODO(LLVM 19): Produce a deprecation warning. +if (LIBCXX_ENABLE_ASSERTIONS) + set(LIBCXX_HARDENING_MODE "extensive") +endif() +if (LIBCXX_HARDENING_MODE STREQUAL "none") + config_define(2 _LIBCPP_HARDENING_MODE_DEFAULT) +elseif (LIBCXX_HARDENING_MODE STREQUAL "fast") + config_define(4 _LIBCPP_HARDENING_MODE_DEFAULT) +elseif (LIBCXX_HARDENING_MODE STREQUAL "extensive") + config_define(16 _LIBCPP_HARDENING_MODE_DEFAULT) +elseif (LIBCXX_HARDENING_MODE STREQUAL "debug") + config_define(8 _LIBCPP_HARDENING_MODE_DEFAULT) +endif() + +if (LIBCXX_PSTL_CPU_BACKEND STREQUAL "serial") + config_define(1 _LIBCPP_PSTL_CPU_BACKEND_SERIAL) +elseif(LIBCXX_PSTL_CPU_BACKEND STREQUAL "std_thread") + config_define(1 _LIBCPP_PSTL_CPU_BACKEND_THREAD) +elseif(LIBCXX_PSTL_CPU_BACKEND STREQUAL "libdispatch") + config_define(1 _LIBCPP_PSTL_CPU_BACKEND_LIBDISPATCH) +else() + message(FATAL_ERROR "LIBCXX_PSTL_CPU_BACKEND is set to ${LIBCXX_PSTL_CPU_BACKEND}, which is not a valid backend. + Valid backends are: serial, std_thread and libdispatch") +endif() + +if (LIBCXX_ABI_DEFINES) + set(abi_defines) + foreach (abi_define ${LIBCXX_ABI_DEFINES}) + if (NOT abi_define MATCHES "^_LIBCPP_ABI_") + message(SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES") + endif() + list(APPEND abi_defines "#define ${abi_define}") + endforeach() + string(REPLACE ";" "\n" abi_defines "${abi_defines}") + config_define(${abi_defines} _LIBCPP_ABI_DEFINES) +endif() + +if (LIBCXX_EXTRA_SITE_DEFINES) + set(extra_site_defines) + foreach (extra_site_define ${LIBCXX_EXTRA_SITE_DEFINES}) + # Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL". + string(REPLACE "=" " " extra_site_define "${extra_site_define}") + list(APPEND extra_site_defines "#define ${extra_site_define}") + endforeach() + string(REPLACE ";" "\n" extra_site_defines "${extra_site_defines}") + config_define(${extra_site_defines} _LIBCPP_EXTRA_SITE_DEFINES) +endif() + +# By default libc++ on Windows expects to use a shared library, which requires +# the headers to use DLL import/export semantics. However when building a +# static library only we modify the headers to disable DLL import/export. +if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) + message(STATUS "Generating custom __config for non-DLL Windows build") + config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +endif() + +if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + # If linking libcxxabi statically into libcxx, skip the dllimport attributes + # on symbols we refer to from libcxxabi. + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) +endif() + +# Setup all common build flags ================================================= +function(cxx_add_common_build_flags target) + cxx_add_basic_build_flags(${target}) + cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC}) + cxx_add_windows_flags(${target}) + cxx_add_exception_flags(${target}) + cxx_add_rtti_flags(${target}) + cxx_add_module_flags(${target}) + cxx_link_system_libraries(${target}) + target_link_libraries(${target} PRIVATE cxx-sanitizer-flags) +endfunction() + +#=============================================================================== +# Setup Source Code And Tests +#=============================================================================== +add_subdirectory(include) +add_subdirectory(src) +add_subdirectory(utils) +if (LIBCXX_ENABLE_STD_MODULES) + add_subdirectory(modules) +endif() + +set(LIBCXX_TEST_DEPS "cxx_experimental") + +if (LIBCXX_ENABLE_CLANG_TIDY) + list(APPEND LIBCXX_TEST_DEPS cxx-tidy) +endif() + +if (LIBCXX_ENABLE_STD_MODULES) + list(APPEND LIBCXX_TEST_DEPS generate-cxx-modules generate-test-module-std) +endif() + +if (LIBCXX_INCLUDE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + +if (LIBCXX_INCLUDE_TESTS) + add_subdirectory(test) + add_subdirectory(lib/abi) +endif() + +if (LIBCXX_INCLUDE_DOCS) + add_subdirectory(docs) +endif() diff --git a/cxx/jni/libcxx/CREDITS.TXT b/cxx/jni/libcxx/CREDITS.TXT new file mode 100644 index 0000000..aa3c8cf --- /dev/null +++ b/cxx/jni/libcxx/CREDITS.TXT @@ -0,0 +1,195 @@ +This file is a partial list of people who have contributed to the LLVM/libc++ +project. If you have contributed a patch or made some other contribution to +LLVM/libc++, please submit a patch to this file to add yourself, and it will be +done! + +The list is sorted by surname and formatted to allow easy grepping and +beautification by scripts. The fields are: name (N), email (E), web-address +(W), PGP key ID and fingerprint (P), description (D), and snail-mail address +(S). + +N: Saleem Abdulrasool +E: compnerd@compnerd.org +D: Minor patches and Linux fixes. + +N: Ulf Adams +D: Invented the Ryu and Ryu Printf algorithms used in floating-point to_chars, and wrote the initial code. + +N: Muiez Ahmed +E: muiez@ibm.com +D: z/OS port. + +N: Dan Albert +E: danalbert@google.com +D: Android support and test runner improvements. + +N: Dimitry Andric +E: dimitry@andric.com +D: Visibility fixes, minor FreeBSD portability patches. + +N: Holger Arnold +E: holgerar@gmail.com +D: Minor fix. + +N: Jorg Brown +D: Ported floating-point to_chars from MSVC to libc++. + +N: David Chisnall +E: theraven at theravensnest dot org +D: FreeBSD and Solaris ports, libcxxrt support, some atomics work. + +N: Marshall Clow +E: mclow.lists@gmail.com +E: marshall@idio.com +D: C++14 support, patches and bug fixes. + +N: Jonathan B Coe +E: jbcoe@me.com +D: Implementation of propagate_const. + +N: Matthew Dempsky +E: matthew@dempsky.org +D: Minor patches and bug fixes. + +N: Christopher Di Bella +E: cjdb@google.com +E: cjdb.ns@gmail.com +D: Library concepts. + +N: Glen Joseph Fernandes +E: glenjofe@gmail.com +D: Implementation of to_address. + +N: Eric Fiselier +E: eric@efcs.ca +D: LFTS support, patches and bug fixes. + +N: Bill Fisher +E: william.w.fisher@gmail.com +D: Regex bug fixes. + +N: Google Inc. +D: Copyright owner and contributor of the CityHash algorithm + +N: Howard Hinnant +E: hhinnant@apple.com +D: Architect and primary author of libc++ + +N: Sergej Jaskiewicz +E: jaskiewiczs@icloud.com +D: Minor improvements in the testing infrastructure + +N: Hyeon-bin Jeong +E: tuhertz@gmail.com +D: Minor patches and bug fixes. + +N: Argyrios Kyrtzidis +E: kyrtzidis@apple.com +D: Bug fixes. + +N: Stephan T. Lavavej +E: stl@microsoft.com +E: stl@nuwen.net +D: Implemented floating-point to_chars. + +N: Damien Lebrun-Grandie +E: dalg24@gmail.com +E: lebrungrandt@ornl.gov +D: Implementation of mdspan. + +N: Microsoft Corporation +D: Contributed floating-point to_chars. + +N: Bruce Mitchener, Jr. +E: bruce.mitchener@gmail.com +D: Emscripten-related changes. + +N: Michel Morin +E: mimomorin@gmail.com +D: Minor patches to is_convertible. + +N: Andrew Morrow +E: andrew.c.morrow@gmail.com +D: Minor patches and Linux fixes. + +N: Michael Park +E: mcypark@gmail.com +D: Implementation of . + +N: Arvid Picciani +E: aep at exys dot org +D: Minor patches and musl port. + +N: Bjorn Reese +E: breese@users.sourceforge.net +D: Initial regex prototype + +N: Nico Rieck +E: nico.rieck@gmail.com +D: Windows fixes + +N: Jon Roelofs +E: jroelofS@jroelofs.com +D: Remote testing, Newlib port, baremetal/single-threaded support. + +N: Kent Ross +E: k@mad.cash +D: Patches for operator<=> support + +N: Jonathan Sauer +D: Minor patches, mostly related to constexpr + +N: Craig Silverstein +E: csilvers@google.com +D: Implemented Cityhash as the string hash function on 64-bit machines + +N: Richard Smith +D: Minor patches. + +N: Joerg Sonnenberger +E: joerg@NetBSD.org +D: NetBSD port. + +N: Stephan Tolksdorf +E: st@quanttec.com +D: Minor fix + +N: Christian Trott +E: crtrott@sandia.gov +D: Implementation of mdspan. + +N: Ruben Van Boxem +E: vanboxem dot ruben at gmail dot com +D: Initial Windows patches. + +N: Michael van der Westhuizen +E: r1mikey at gmail dot com + +N: Larisse Voufo +D: Minor patches. + +N: Klaas de Vries +E: klaas at klaasgaaf dot nl +D: Minor bug fix. + +N: Mark de Wever +E: koraq at xs4all dot nl +D: Format library support. +D: Finalized the porting of MSVC's to_chars to libc++. + +N: Zhang Xiongpang +E: zhangxiongpang@gmail.com +D: Minor patches and bug fixes. + +N: Xing Xue +E: xingxue@ca.ibm.com +D: AIX port + +N: Jeffrey Yasskin +E: jyasskin@gmail.com +E: jyasskin@google.com +D: Linux fixes. + +N: Zhihao Yuan +E: lichray@gmail.com +D: Standard compatibility fixes. diff --git a/cxx/jni/libcxx/LICENSE.TXT b/cxx/jni/libcxx/LICENSE.TXT new file mode 100644 index 0000000..e159d28 --- /dev/null +++ b/cxx/jni/libcxx/LICENSE.TXT @@ -0,0 +1,311 @@ +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): +============================================================================== + +The libc++ library is dual licensed under both the University of Illinois +"BSD-Like" license and the MIT license. As a user of this code you may choose +to use it under either license. As a contributor, you agree to allow your code +to be used under both. + +Full text of the relevant licenses is included below. + +============================================================================== + +University of Illinois/NCSA +Open Source License + +Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT + +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. + +============================================================================== + +Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/cxx/jni/libcxx/TODO.TXT b/cxx/jni/libcxx/TODO.TXT new file mode 100644 index 0000000..bc78554 --- /dev/null +++ b/cxx/jni/libcxx/TODO.TXT @@ -0,0 +1,23 @@ +This is meant to be a general place to list things that should be done "someday" + +CXX Runtime Library Tasks +========================= +* Look into mirroring libsupc++'s typeinfo vtable layout when libsupc++/libstdc++ + is used as the runtime library. +* Investigate and document interoperability between libc++ and libstdc++ on + linux. Do this for every supported c++ runtime library. + +Atomic Related Tasks +==================== +* future should use for synchronization. + +Test Suite Tasks +================ +* Improve the quality and portability of the locale test data. +* Convert failure tests to use Clang Verify. + +Misc Tasks +========== +* Find all sequences of >2 underscores and eradicate them. +* run clang-tidy on libc++ +* Document the "conditionally-supported" bits of libc++ diff --git a/cxx/jni/libcxx/appveyor-reqs-install.cmd b/cxx/jni/libcxx/appveyor-reqs-install.cmd new file mode 100644 index 0000000..e3bd018 --- /dev/null +++ b/cxx/jni/libcxx/appveyor-reqs-install.cmd @@ -0,0 +1,53 @@ +@echo on + +if NOT EXIST C:\projects\deps ( + mkdir C:\projects\deps +) +cd C:\projects\deps + +::########################################################################### +:: Setup Compiler +::########################################################################### +if NOT EXIST llvm-installer.exe ( + appveyor DownloadFile https://prereleases.llvm.org/win-snapshots/LLVM-9.0.0-r357435-win32.exe -FileName llvm-installer.exe +) +if "%CLANG_VERSION%"=="ToT" ( + START /WAIT llvm-installer.exe /S /D=C:\"Program Files\LLVM" +) +if DEFINED CLANG_VERSION @set PATH="C:\Program Files\LLVM\bin";%PATH% +if DEFINED CLANG_VERSION clang-cl -v + +if DEFINED MINGW_PATH rename "C:\Program Files\Git\usr\bin\sh.exe" "sh-ignored.exe" +if DEFINED MINGW_PATH @set "PATH=%PATH:C:\Program Files (x86)\Git\bin=%" +if DEFINED MINGW_PATH @set "PATH=%PATH%;%MINGW_PATH%" +if DEFINED MINGW_PATH g++ -v + +::########################################################################### +:: Install a recent CMake +::########################################################################### +if NOT EXIST cmake ( + appveyor DownloadFile https://cmake.org/files/v3.7/cmake-3.7.2-win64-x64.zip -FileName cmake.zip + 7z x cmake.zip -oC:\projects\deps > nul + move C:\projects\deps\cmake-* C:\projects\deps\cmake + rm cmake.zip +) +@set PATH=C:\projects\deps\cmake\bin;%PATH% +cmake --version + +::########################################################################### +:: Install Ninja +::########################################################################### +if NOT EXIST ninja ( + appveyor DownloadFile https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip -FileName ninja.zip + 7z x ninja.zip -oC:\projects\deps\ninja > nul + rm ninja.zip +) +@set PATH=C:\projects\deps\ninja;%PATH% +ninja --version + +::########################################################################### +:: Setup the cached copy of LLVM +::########################################################################### +git clone --depth=1 http://llvm.org/git/llvm.git + +@echo off diff --git a/cxx/jni/libcxx/appveyor.yml b/cxx/jni/libcxx/appveyor.yml new file mode 100644 index 0000000..8a69cb9 --- /dev/null +++ b/cxx/jni/libcxx/appveyor.yml @@ -0,0 +1,71 @@ +version: '{build}' + +shallow_clone: true + +build: + verbosity: detailed + +configuration: + - Debug + +environment: + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_OPTIONS: -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe + CLANG_VERSION: ToT + MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat + MSVC_SETUP_ARG: x86 + GENERATOR: Ninja + MAKE_PROGRAM: ninja + APPVEYOR_SAVE_CACHE_ON_ERROR: true +# TODO: Maybe re-enable this configuration? Do we want to support MSVC 2015's runtime? +# - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 +# MINGW_PATH: C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin +# GENERATOR: MinGW Makefiles +# MAKE_PROGRAM: mingw32-make +# APPVEYOR_SAVE_CACHE_ON_ERROR: true + +install: + ############################################################################ + # All external dependencies are installed in C:\projects\deps + ############################################################################ + - call "%APPVEYOR_BUILD_FOLDER%\\appveyor-reqs-install.cmd" + +before_build: + - if DEFINED MSVC_SETUP_PATH call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG% + - cd %APPVEYOR_BUILD_FOLDER% + +build_script: + - md C:\projects\build-libcxx + - cd C:\projects\build-libcxx + - echo %configuration% + + ############################################################################# + # Configuration Step + ############################################################################# + - cmake -G "%GENERATOR%" %CMAKE_OPTIONS% + "-DCMAKE_BUILD_TYPE=%configuration%" + "-DLLVM_PATH=C:\projects\deps\llvm" + -DLLVM_LIT_ARGS="-v --show-xfail --show-unsupported" + %APPVEYOR_BUILD_FOLDER% + + ############################################################################# + # Build Step + ############################################################################# + - "%MAKE_PROGRAM%" + +test_script: + - "%MAKE_PROGRAM% check-cxx" + +on_failure: + - appveyor PushArtifact CMakeFiles/CMakeOutput.log + - appveyor PushArtifact CMakeFiles/CMakeError.log + +artifacts: + - path: '_build/CMakeFiles/*.log' + name: logs + +cache: + - C:\projects\deps\ninja + - C:\projects\deps\cmake + - C:\projects\deps\llvm-installer.exe diff --git a/cxx/jni/libcxx/benchmarks/CMakeLists.txt b/cxx/jni/libcxx/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..ce4f5fd --- /dev/null +++ b/cxx/jni/libcxx/benchmarks/CMakeLists.txt @@ -0,0 +1,261 @@ +include(ExternalProject) +include(CheckCXXCompilerFlag) + +#============================================================================== +# Build Google Benchmark for libc++ +#============================================================================== + +set(CMAKE_FOLDER "${CMAKE_FOLDER}/Benchmarks") + +set(BENCHMARK_LIBCXX_COMPILE_FLAGS + -Wno-unused-command-line-argument + -nostdinc++ + -isystem "${LIBCXX_GENERATED_INCLUDE_DIR}" + -L${LIBCXX_LIBRARY_DIR} + -Wl,-rpath,${LIBCXX_LIBRARY_DIR} + ${SANITIZER_FLAGS} + ) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS + -isystem "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}") +endif() +if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH) + list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS + -L${LIBCXX_CXX_ABI_LIBRARY_PATH} + -Wl,-rpath,${LIBCXX_CXX_ABI_LIBRARY_PATH}) +endif() +split_list(BENCHMARK_LIBCXX_COMPILE_FLAGS) + +ExternalProject_Add(google-benchmark-libcxx + EXCLUDE_FROM_ALL ON + DEPENDS cxx cxx-headers + PREFIX benchmark-libcxx + SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx + CMAKE_CACHE_ARGS + -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_BUILD_TYPE:STRING=RELEASE + -DCMAKE_INSTALL_PREFIX:PATH= + -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_LIBCXX_COMPILE_FLAGS} + -DBENCHMARK_USE_LIBCXX:BOOL=ON + -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) + +#============================================================================== +# Build Google Benchmark for the native stdlib +#============================================================================== +set(BENCHMARK_NATIVE_TARGET_FLAGS) +if (LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN) + set(BENCHMARK_NATIVE_TARGET_FLAGS + --gcc-toolchain=${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN}) +endif() +split_list(BENCHMARK_NATIVE_TARGET_FLAGS) + +if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + ExternalProject_Add(google-benchmark-native + EXCLUDE_FROM_ALL ON + PREFIX benchmark-native + SOURCE_DIR ${LLVM_THIRD_PARTY_DIR}/benchmark + INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native + CMAKE_CACHE_ARGS + -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_NATIVE_TARGET_FLAGS} + -DCMAKE_BUILD_TYPE:STRING=RELEASE + -DCMAKE_INSTALL_PREFIX:PATH= + -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) +endif() + + +#============================================================================== +# Benchmark tests configuration +#============================================================================== +add_custom_target(cxx-benchmarks) +set(BENCHMARK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(BENCHMARK_LIBCXX_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx) +set(BENCHMARK_NATIVE_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native) + +add_library( cxx-benchmarks-flags INTERFACE) + +# TODO(cmake): remove. This is a workaround to prevent older versions of GCC +# from failing the configure step because they don't support C++23. +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13.0") + return() +endif() +#TODO(cmake): remove the `add_compile_options`. Currently we have to explicitly +# pass the `std:c++latest` flag on Windows to work around an issue where +# requesting `cxx_std_23` results in an error -- somehow CMake fails to +# translate the `c++23` flag into `c++latest`, and the highest numbered C++ +# version that MSVC flags support is C++20. +if (MSVC) + add_compile_options(/std:c++latest) +# ibm-clang does not recognize the cxx_std_23 flag, so use this as a temporary +# workaround on AIX as well. +elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + add_compile_options(-std=c++23) +else() + target_compile_features( cxx-benchmarks-flags INTERFACE cxx_std_23) +endif() + +target_compile_options( cxx-benchmarks-flags INTERFACE -fsized-deallocation -nostdinc++) +target_include_directories(cxx-benchmarks-flags INTERFACE "${LIBCXX_GENERATED_INCLUDE_DIR}" + INTERFACE "${BENCHMARK_LIBCXX_INSTALL}/include" + INTERFACE "${LIBCXX_SOURCE_DIR}/test/support") + +add_library( cxx-benchmarks-flags-native INTERFACE) +target_link_libraries( cxx-benchmarks-flags-native INTERFACE cxx-benchmarks-flags) +target_compile_options(cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS}) +target_link_options( cxx-benchmarks-flags-native INTERFACE ${BENCHMARK_NATIVE_TARGET_FLAGS} "-L${BENCHMARK_NATIVE_INSTALL}/lib") +if (LIBCXX_BENCHMARK_NATIVE_STDLIB STREQUAL "libstdc++") + find_library(LIBSTDCXX_FILESYSTEM_TEST stdc++fs + PATHS ${LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN} + PATH_SUFFIXES lib lib64 + DOC "The libstdc++ filesystem library used by the benchmarks" + ) + if (LIBSTDCXX_FILESYSTEM_TEST) + target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lstdc++fs) + endif() +else() + target_link_libraries(cxx-benchmarks-flags-native INTERFACE -lc++fs -lc++experimental) +endif() + +add_library( cxx-benchmarks-flags-libcxx INTERFACE) +target_link_libraries( cxx-benchmarks-flags-libcxx INTERFACE cxx-benchmarks-flags) +target_compile_options(cxx-benchmarks-flags-libcxx INTERFACE ${SANITIZER_FLAGS} -Wno-user-defined-literals -Wno-suggest-override) +target_link_options( cxx-benchmarks-flags-libcxx INTERFACE -nostdlib++ "-L${BENCHMARK_LIBCXX_INSTALL}/lib" "-L${BENCHMARK_LIBCXX_INSTALL}/lib64" ${SANITIZER_FLAGS}) + +set(libcxx_benchmark_targets) + +function(add_benchmark_test name source_file) + set(libcxx_target ${name}_libcxx) + list(APPEND libcxx_benchmark_targets ${libcxx_target}) + add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file}) + target_link_libraries(${libcxx_target} PRIVATE cxx-benchmarks-flags-libcxx) + add_dependencies(${libcxx_target} cxx google-benchmark-libcxx) + add_dependencies(cxx-benchmarks ${libcxx_target}) + if (LIBCXX_ENABLE_SHARED) + target_link_libraries(${libcxx_target} PRIVATE cxx_shared) + else() + target_link_libraries(${libcxx_target} PRIVATE cxx_static) + endif() + target_link_libraries(${libcxx_target} PRIVATE cxx_experimental benchmark) + if (LLVM_USE_SANITIZER) + target_link_libraries(${libcxx_target} PRIVATE -ldl) + endif() + set_target_properties(${libcxx_target} + PROPERTIES + OUTPUT_NAME "${name}.libcxx.out" + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + CXX_EXTENSIONS NO) + cxx_link_system_libraries(${libcxx_target}) + if (LIBCXX_BENCHMARK_NATIVE_STDLIB) + set(native_target ${name}_native) + add_executable(${native_target} EXCLUDE_FROM_ALL ${source_file}) + target_link_libraries(${native_target} PRIVATE cxx-benchmarks-flags-native) + add_dependencies(${native_target} google-benchmark-native + google-benchmark-libcxx) + target_link_libraries(${native_target} PRIVATE -lbenchmark) + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${native_target} PRIVATE -pthread) + endif() + add_dependencies(cxx-benchmarks ${native_target}) + set_target_properties(${native_target} + PROPERTIES + OUTPUT_NAME "${name}.native.out" + RUNTIME_OUTPUT_DIRECTORY "${BENCHMARK_OUTPUT_DIR}" + CXX_EXTENSIONS NO) + endif() +endfunction() + + +#============================================================================== +# Register Benchmark tests +#============================================================================== +set(BENCHMARK_TESTS + algorithms.partition_point.bench.cpp + algorithms/count.bench.cpp + algorithms/equal.bench.cpp + algorithms/find.bench.cpp + algorithms/for_each.bench.cpp + algorithms/lower_bound.bench.cpp + algorithms/make_heap.bench.cpp + algorithms/make_heap_then_sort_heap.bench.cpp + algorithms/min.bench.cpp + algorithms/min_max_element.bench.cpp + algorithms/pop_heap.bench.cpp + algorithms/pstl.stable_sort.bench.cpp + algorithms/push_heap.bench.cpp + algorithms/ranges_contains.bench.cpp + algorithms/ranges_ends_with.bench.cpp + algorithms/ranges_make_heap.bench.cpp + algorithms/ranges_make_heap_then_sort_heap.bench.cpp + algorithms/ranges_pop_heap.bench.cpp + algorithms/ranges_push_heap.bench.cpp + algorithms/ranges_sort.bench.cpp + algorithms/ranges_sort_heap.bench.cpp + algorithms/ranges_stable_sort.bench.cpp + algorithms/sort.bench.cpp + algorithms/sort_heap.bench.cpp + algorithms/stable_sort.bench.cpp + libcxxabi/dynamic_cast.bench.cpp + libcxxabi/dynamic_cast_old_stress.bench.cpp + allocation.bench.cpp + deque.bench.cpp + deque_iterator.bench.cpp + filesystem.bench.cpp + format_to_n.bench.cpp + format_to.bench.cpp + format.bench.cpp + formatted_size.bench.cpp + formatter_float.bench.cpp + formatter_int.bench.cpp + function.bench.cpp + join_view.bench.cpp + lexicographical_compare_three_way.bench.cpp + map.bench.cpp + monotonic_buffer.bench.cpp + ordered_set.bench.cpp + stop_token.bench.cpp + std_format_spec_string_unicode.bench.cpp + string.bench.cpp + stringstream.bench.cpp + system_error.bench.cpp + to_chars.bench.cpp + unordered_set_operations.bench.cpp + util_smartptr.bench.cpp + variant_visit_1.bench.cpp + variant_visit_2.bench.cpp + variant_visit_3.bench.cpp + vector_operations.bench.cpp + ) + +foreach(test_path ${BENCHMARK_TESTS}) + get_filename_component(test_file "${test_path}" NAME) + string(REPLACE ".bench.cpp" "" test_name "${test_file}") + if (NOT DEFINED ${test_name}_REPORTED) + message(STATUS "Adding Benchmark: ${test_file}") + # Only report the adding of the benchmark once. + set(${test_name}_REPORTED ON CACHE INTERNAL "") + endif() + add_benchmark_test(${test_name} ${test_path}) +endforeach() + +if (LIBCXX_INCLUDE_TESTS) + include(AddLLVM) + + if (NOT DEFINED LIBCXX_TEST_DEPS) + message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined") + endif() + + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py) + + set(BENCHMARK_LIT_ARGS "--show-all --show-xfail --show-unsupported ${LIT_ARGS_DEFAULT}") + + add_lit_target(check-cxx-benchmarks + "Running libcxx benchmarks tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS cxx-benchmarks ${LIBCXX_TEST_DEPS} + ARGS ${BENCHMARK_LIT_ARGS}) +endif() diff --git a/cxx/jni/libcxx/benchmarks/CartesianBenchmarks.h b/cxx/jni/libcxx/benchmarks/CartesianBenchmarks.h new file mode 100644 index 0000000..eca4e15 --- /dev/null +++ b/cxx/jni/libcxx/benchmarks/CartesianBenchmarks.h @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +#include "benchmark/benchmark.h" +#include "test_macros.h" + +namespace internal { + +template +struct EnumValue : std::integral_constant(I)> { + static std::string name() { return std::string("_") + D::Names[I]; } +}; + +template +constexpr auto makeEnumValueTuple(std::index_sequence) { + return std::make_tuple(EnumValue{}...); +} + +template +static auto skip(const B& Bench, int) -> decltype(Bench.skip()) { + return Bench.skip(); +} +template +static auto skip(const B& Bench, char) { + return false; +} + +template +void makeBenchmarkFromValuesImpl(const Args& A, std::index_sequence) { + for (auto& V : A) { + B Bench{std::get(V)...}; + if (!internal::skip(Bench, 0)) { + benchmark::RegisterBenchmark(Bench.name().c_str(), [=](benchmark::State& S) { Bench.run(S); }); + } + } +} + +template +void makeBenchmarkFromValues(const std::vector >& A) { + makeBenchmarkFromValuesImpl(A, std::index_sequence_for()); +} + +template