Upgrade libcxx and use c++ 23

1. Meet latest glaze's requirements, and upgrade it
2. Get rid of glaze_write_json to avoid using iostream, which made binary size increased. Use C methods instead.

Signed-off-by: GarfieldHan <2652609017@qq.com>
This commit is contained in:
GarfieldHan
2024-07-18 10:27:54 +08:00
parent 4d7257fcc7
commit 55cbe69ad5
7 changed files with 47 additions and 110 deletions

3
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "module/src/main/cpp/external/libcxx"]
path = module/src/main/cpp/external/libcxx
url = https://github.com/topjohnwu/libcxx
[submodule "module/src/main/cpp/external/LSPlt"]
path = module/src/main/cpp/external/LSPlt
url = https://github.com/LSPosed/LSPlt

View File

@@ -7,6 +7,7 @@ annotation = "1.8.0"
[libraries]
annotation = { module = "androidx.annotation:annotation", version.ref = "annotation" }
bcpkix-jdk18on = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bcpkix-jdk18on" }
cxx = { module = "org.lsposed.libcxx:libcxx", version = "27.0.12077973" }
[plugins]
agp-app = { id = "com.android.application", version.ref = "agp" }

View File

@@ -28,7 +28,7 @@ android {
}
externalNativeBuild {
cmake {
cppFlags("-std=c++20")
cppFlags("-std=c++23")
arguments(
"-DANDROID_STL=none",
"-DMODULE_NAME=$moduleId"
@@ -36,8 +36,14 @@ android {
}
}
}
buildFeatures {
prefab = true
}
externalNativeBuild {
cmake {
version = "3.28.0+"
path("src/main/cpp/CMakeLists.txt")
}
}
@@ -51,6 +57,10 @@ android {
}
}
dependencies {
compileOnly(libs.cxx)
}
androidComponents.onVariants { variant ->
afterEvaluate {
val variantLowered = variant.name.lowercase()

View File

@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.22.1)
cmake_minimum_required(VERSION 3.28)
project(sample)
find_package(cxx REQUIRED CONFIG)
link_libraries(cxx::cxx)
set(LINKER_FLAGS "-ffixed-x18 -Wl,--hash-style=both")
set(CXX_FLAGS "${CXX_FLAGS} -fno-exceptions -fno-rtti")
@@ -14,13 +17,12 @@ add_library(elf_util STATIC elf_util/elf_util.cpp)
add_library(my_logging STATIC logging/logging.cpp)
add_subdirectory(external)
link_libraries(cxx)
target_include_directories(my_logging PUBLIC logging/include)
target_include_directories(elf_util PUBLIC elf_util/include)
target_link_libraries(my_logging cxx log)
target_link_libraries(elf_util cxx lsplt my_logging)
target_link_libraries(my_logging log)
target_link_libraries(elf_util lsplt my_logging)
# libutils stub
add_library(utils SHARED binder/stub_utils.cpp)

View File

@@ -6,102 +6,7 @@ set(SOURCES LSPlt/lsplt/src/main/jni/lsplt.cc LSPlt/lsplt/src/main/jni/elf_util.
add_library(lsplt STATIC ${SOURCES})
target_include_directories(lsplt PUBLIC LSPlt/lsplt/src/main/jni/include)
target_include_directories(lsplt PRIVATE LSPlt/lsplt/src/main/jni)
target_link_libraries(lsplt PUBLIC my_logging cxx)
target_link_libraries(lsplt PUBLIC my_logging)
# end lsplt
add_subdirectory(glaze)
# cxx
set(LIBCXX_SOURCES
algorithm.cpp
# any.cpp
atomic.cpp
barrier.cpp
# bind.cpp
charconv.cpp
chrono.cpp
condition_variable.cpp
condition_variable_destructor.cpp
# debug.cpp
exception.cpp
filesystem/directory_iterator.cpp
filesystem/int128_builtins.cpp
filesystem/operations.cpp
functional.cpp
future.cpp
hash.cpp
ios.cpp
ios.instantiations.cpp
iostream.cpp
locale.cpp
memory.cpp
mutex.cpp
mutex_destructor.cpp
new.cpp
optional.cpp
random.cpp
# regex.cpp
# ryu/d2fixed.cpp
# ryu/d2s.cpp
# ryu/f2s.cpp
shared_mutex.cpp
stdexcept.cpp
string.cpp
# strstream.cpp
system_error.cpp
thread.cpp
# typeinfo.cpp
utility.cpp
valarray.cpp
variant.cpp
vector.cpp
)
list(TRANSFORM LIBCXX_SOURCES PREPEND libcxx/src/)
set(LIBCXX_EXPORT_FLAGS
-DLIBCXX_BUILDING_LIBCXXABI
-D_LIBCPP_NO_EXCEPTIONS
-D_LIBCPP_NO_RTTI
-D_LIBCPP_BUILDING_LIBRARY
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
-D_LIBCXXABI_NO_EXCEPTIONS
)
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 libcxx/src/abi/)
set(LIBCXXABI_FLAGS
-Wno-macro-redefined
-Wno-unknown-attributes
-DHAS_THREAD_LOCAL)
set(LIBCXXABI_INCLUDES libcxx/include/abi)
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})
# end cxx

View File

@@ -111,6 +111,33 @@ private:
}
};
static inline void write_spoof_configs(const struct spoof_config& spoofConfig) {
std::string buffer{};
if (glz::write<glz::opts{.prettify = true}>(spoofConfig, buffer)) [[unlikely]] {
// This should NEVER happen, but it's not the reason we don't handle the case
LOGE("[write_spoof_configs] Failed to parse json to std::string");
return;
}
// Remove old one first
std::filesystem::remove("/data/adb/tricky_store/spoof_build_vars"sv);
FILE* file = fopen("/data/adb/tricky_store/spoof_build_vars", "w");
if (!file) [[unlikely]] {
LOGE("[write_spoof_configs] Failed to open spoof_build_vars");
return;
}
if (fprintf(file, "%s", buffer.c_str()) < 0) [[unlikely]] {
LOGE("[write_spoof_configs] Failed to write spoof_build_vars");
fclose(file);
return;
}
fclose(file);
LOGI("[write_spoof_configs] write done!");
}
static void companion_handler(int fd) {
int enabled = access("/data/adb/tricky_store/spoof_build_vars", F_OK) == 0;
write(fd, &enabled, sizeof(enabled));
@@ -123,11 +150,7 @@ static void companion_handler(int fd) {
auto ec = glz::read_file_json(spoofConfig, "/data/adb/tricky_store/spoof_build_vars"sv, std::string{});
if (ec) [[unlikely]] {
LOGW("[companion_handler] Failed to parse spoof_build_vars, writing and using default spoof config...");
ec = glz::write_file_json<glz::opts{.prettify = true}>(spoofConfig, "/data/adb/tricky_store/spoof_build_vars"sv, std::string{});
if (ec) [[unlikely]] {
LOGW("[companion_handler] Failed to write spoof_build_vars");
}
LOGI("[write_spoof_configs@companion_handler] write done!");
write_spoof_configs(spoofConfig);
}
std::string buffer = glz::write_json(spoofConfig).value_or("");