🚧 fix compilation with clang

This commit is contained in:
Vladislav Nepogodin 2022-01-03 01:45:54 +04:00
parent c608ed3e66
commit f7d464842a
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
11 changed files with 64 additions and 24 deletions

View File

@ -103,8 +103,8 @@ add_executable(test-exec-interactive
) )
add_executable(test-process-tailing add_executable(test-process-tailing
src/config.cpp src/config.cpp src/config.hpp
src/utils.cpp src/utils.cpp src/utils.hpp
src/widgets.cpp src/widgets.hpp src/widgets.cpp src/widgets.hpp
src/follow_process_log.hpp src/follow_process_log.cpp src/follow_process_log.hpp src/follow_process_log.cpp
src/tui.cpp src/tui.hpp src/tui.cpp src/tui.hpp
@ -124,8 +124,8 @@ enable_sanitizers(project_options)
include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${CMAKE_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::screen ftxui::dom ftxui::component simdjson::simdjson cpr::cpr PkgConfig::GLIBMM) target_link_libraries(${PROJECT_NAME} PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::screen ftxui::dom ftxui::component simdjson::simdjson cpr::cpr PkgConfig::GLIBMM)
target_link_libraries(test-exec-interactive PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr PkgConfig::GLIBMM) target_link_libraries(test-exec-interactive PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component simdjson::simdjson cpr::cpr PkgConfig::GLIBMM)
target_link_libraries(test-process-tailing PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component cpr::cpr PkgConfig::GLIBMM) target_link_libraries(test-process-tailing PRIVATE project_warnings project_options spdlog::spdlog fmt::fmt ftxui::component simdjson::simdjson cpr::cpr PkgConfig::GLIBMM)
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_link_libraries(${PROJECT_NAME} PRIVATE range-v3::range-v3) target_link_libraries(${PROJECT_NAME} PRIVATE range-v3::range-v3)

View File

@ -58,6 +58,19 @@ function(set_project_warnings project_name)
-Wduplicated-branches # warn if if / else branches have duplicated code -Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted -Wlogical-op # warn about logical operations being used where bitwise were probably wanted
-Wuseless-cast # warn if you perform a cast to the same type -Wuseless-cast # warn if you perform a cast to the same type
-Wsuggest-attribute=cold
-Wsuggest-attribute=format
-Wsuggest-attribute=malloc
-Wsuggest-attribute=noreturn
-Wsuggest-attribute=pure
-Wsuggest-final-methods
-Wsuggest-final-types
-Wdiv-by-zero
-Wanalyzer-double-fclose
-Wanalyzer-double-free
-Wanalyzer-malloc-leak
-Wanalyzer-use-after-free
) )
if(MSVC) if(MSVC)

View File

@ -5,7 +5,7 @@ include(CheckCXXCompilerFlag)
set(USER_LINKER_OPTION set(USER_LINKER_OPTION
"lld" "lld"
CACHE STRING "Linker to be used") CACHE STRING "Linker to be used")
set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd") set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold")
set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES}) set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES})
list( list(
FIND FIND

View File

@ -14,6 +14,7 @@ cc = meson.get_compiler('cpp')
if cc.get_id() == 'clang' if cc.get_id() == 'clang'
specific_cc_flags = [ specific_cc_flags = [
'-nostdlib++', '-nostdlib++',
#'-stdlib=libc++',
'-nodefaultlibs', '-nodefaultlibs',
] ]
specific_link_flags = [ specific_link_flags = [
@ -32,7 +33,7 @@ if not is_dev_environment
endif endif
# Common dependencies # Common dependencies
spdlog = dependency('spdlog', version : ['>=1.9.2']) spdlog = dependency('spdlog', version : ['>=1.9.2'], fallback : ['spdlog', 'spdlog_dep'])
fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep']) fmt = dependency('fmt', version : ['>=8.0.0'], fallback : ['fmt', 'fmt_dep'])
ftxui = dependency('ftxui', modules : ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], fallback : ['ftxui', 'ftxui_dep']) ftxui = dependency('ftxui', modules : ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], fallback : ['ftxui', 'ftxui_dep'])
simdjson = dependency('simdjson', version : ['>=1.0.2'], fallback : ['simdjson', 'simdjson_dep']) simdjson = dependency('simdjson', version : ['>=1.0.2'], fallback : ['simdjson', 'simdjson_dep'])
@ -80,6 +81,19 @@ if cc.get_id() == 'gcc'
'-Wduplicated-branches', '-Wduplicated-branches',
'-Wlogical-op', '-Wlogical-op',
'-Wuseless-cast', '-Wuseless-cast',
'-Wsuggest-attribute=cold',
'-Wsuggest-attribute=format',
'-Wsuggest-attribute=malloc',
'-Wsuggest-attribute=noreturn',
'-Wsuggest-attribute=pure',
'-Wsuggest-final-methods',
'-Wsuggest-final-types',
'-Wdiv-by-zero',
'-Wanalyzer-double-fclose',
'-Wanalyzer-double-free',
'-Wanalyzer-malloc-leak',
'-Wanalyzer-use-after-free',
] ]
endif endif
@ -102,24 +116,30 @@ endif
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp') add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'cpp')
deps = [fmt, spdlog, ftxui, simdjson, cpr, glibmm]
if cc.get_id() == 'clang'
ranges = dependency('range-v3', version : ['>=0.11.0'])
deps += [ranges]
endif
executable( executable(
'cachyos-installer', 'cachyos-installer',
src_files, src_files,
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm], dependencies: deps,
include_directories: [include_directories('src')], include_directories: [include_directories('src')],
install: true) install: true)
executable( executable(
'test-exec-interactive', 'test-exec-interactive',
files('src/config.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/main_test.cpp'), files('src/config.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/main_test.cpp'),
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm], dependencies: deps,
include_directories: [include_directories('src')], include_directories: [include_directories('src')],
install: false) install: false)
executable( executable(
'test-process-tailing', 'test-process-tailing',
files('src/config.cpp', 'src/widgets.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/follow_process_log.cpp','src/test_proccess_tailing.cpp'), files('src/config.cpp', 'src/widgets.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/follow_process_log.cpp','src/test_proccess_tailing.cpp'),
dependencies: [fmt, spdlog, ftxui, simdjson, cpr, glibmm], dependencies: deps,
include_directories: [include_directories('src')], include_directories: [include_directories('src')],
install: false) install: false)

View File

@ -18,7 +18,7 @@ class Config final {
virtual ~Config() noexcept = default; virtual ~Config() noexcept = default;
static bool initialize() noexcept; static bool initialize() noexcept;
static Config* instance(); [[gnu::pure]] static Config* instance();
/* clang-format off */ /* clang-format off */

View File

@ -30,10 +30,10 @@ void follow_process_log_widget(const std::vector<std::string>& vec, Decorator bo
std::this_thread::sleep_for(0.05s); std::this_thread::sleep_for(0.05s);
} }
}; };
std::jthread t(execute_thread); std::thread t(execute_thread);
auto screen = ScreenInteractive::Fullscreen(); auto screen = ScreenInteractive::Fullscreen();
std::jthread refresh_ui([&] { std::thread refresh_ui([&] {
while (running) { while (running) {
std::this_thread::sleep_for(0.05s); std::this_thread::sleep_for(0.05s);
screen.PostEvent(Event::Custom); screen.PostEvent(Event::Custom);
@ -63,11 +63,17 @@ void follow_process_log_widget(const std::vector<std::string>& vec, Decorator bo
auto container = Container::Horizontal({button_back}); auto container = Container::Horizontal({button_back});
auto renderer = Renderer(container, [&] { auto renderer = Renderer(container, [&] {
return tui::detail::centered_widget(container, "New CLI Installer", tui::detail::multiline_text(utils::make_multiline(process_log)) | boxsize | vscroll_indicator | yframe | flex); return tui::detail::centered_widget(container, "New CLI Installer", tui::detail::multiline_text(utils::make_multiline(process_log, true)) | boxsize | vscroll_indicator | yframe | flex);
}); });
screen.Loop(renderer); screen.Loop(renderer);
running = false; running = false;
if (refresh_ui.joinable()) {
refresh_ui.join();
}
if (t.joinable()) {
t.join();
}
} }
} // namespace tui::detail } // namespace tui::detail

View File

@ -20,7 +20,7 @@ class screen_service final {
virtual ~screen_service() noexcept = default; virtual ~screen_service() noexcept = default;
static bool initialize() noexcept; static bool initialize() noexcept;
static screen_service* instance(); [[gnu::pure]] static screen_service* instance();
/* clang-format off */ /* clang-format off */

View File

@ -1,5 +1,5 @@
#include "follow_process_log.hpp" #include "follow_process_log.hpp"
int main() { int main() {
tui::detail::follow_process_log_widget({"/bin/sh", "-c", "sleep 1 && echo \"I slept\""}); tui::detail::follow_process_log_widget({"/bin/sh", "-c", "sleep 1 && echo \"I slept\" && sleep 1 && echo \"I slept twice\""});
} }

View File

@ -751,7 +751,7 @@ void install_base() noexcept {
// utils::exec(fmt::format("pacstrap {} {} |& tee /tmp/pacstrap.log", mountpoint, packages)); // utils::exec(fmt::format("pacstrap {} {} |& tee /tmp/pacstrap.log", mountpoint, packages));
detail::follow_process_log_widget({"/bin/sh", "-c", fmt::format("pacstrap {} {} |& tee /tmp/pacstrap.log", mountpoint, packages)}); detail::follow_process_log_widget({"/bin/sh", "-c", fmt::format("pacstrap {} {} |& tee /tmp/pacstrap.log", mountpoint, packages)});
std::filesystem::copy("/etc/pacman.conf", fmt::format("{}/etc/pacman.conf", mountpoint)); std::filesystem::copy_file("/etc/pacman.conf", fmt::format("{}/etc/pacman.conf", mountpoint), fs::copy_options::overwrite_existing);
#endif #endif
std::ofstream{base_installed}; std::ofstream{base_installed};
} }

View File

@ -8,6 +8,7 @@
#include <algorithm> // for transform #include <algorithm> // for transform
#include <array> // for array #include <array> // for array
#include <bit> // for bit_cast
#include <chrono> // for filesystem, seconds #include <chrono> // for filesystem, seconds
#include <cstdint> // for int32_t #include <cstdint> // for int32_t
#include <cstdio> // for feof, fgets, pclose, perror, popen #include <cstdio> // for feof, fgets, pclose, perror, popen
@ -49,6 +50,7 @@ namespace ranges = std::ranges;
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion" #pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wambiguous-reversed-operator"
#elif defined(__GNUC__) #elif defined(__GNUC__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
@ -257,12 +259,11 @@ auto make_multiline(std::vector<std::string>& multiline, bool reverse, const std
// install a pkg in the live session if not installed // install a pkg in the live session if not installed
void inst_needed(const std::string_view& pkg) { void inst_needed(const std::string_view& pkg) {
const auto& pkg_info = utils::exec(fmt::format("pacman -Q {}", pkg)); if (utils::exec(fmt::format("pacman -Q {}", pkg), true) != "0") {
const std::regex pkg_regex("/error/"); std::this_thread::sleep_for(std::chrono::seconds(1));
if (!std::regex_search(pkg_info, pkg_regex)) {
std::this_thread::sleep_for(std::chrono::seconds(2));
utils::clear_screen(); utils::clear_screen();
utils::exec(fmt::format("pacman -Sy --noconfirm {}", pkg)); tui::detail::follow_process_log_widget({"/bin/sh", "-c", fmt::format("pacman -Sy --noconfirm {}", pkg)});
// utils::exec(fmt::format("pacman -Sy --noconfirm {}", pkg));
} }
} }

View File

@ -9,17 +9,17 @@ project('simdjson', 'cpp',
simdjson_lib = library('simdjson', simdjson_lib = library('simdjson',
sources : ['singleheader/simdjson.cpp'], sources : ['singleheader/simdjson.cpp'],
cpp_args : '-DSIMDJSON_THREADS_ENABLED=1', cpp_args : ['-DSIMDJSON_THREADS_ENABLED=1', '-Wno-ambiguous-reversed-operator'],
include_directories: include_directories('singleheader') include_directories: include_directories('singleheader')
) )
simdjson_dep = declare_dependency( simdjson_dep = declare_dependency(
include_directories: include_directories('singleheader'), include_directories: include_directories('singleheader'),
compile_args : '-DSIMDJSON_THREADS_ENABLED=1', compile_args : ['-DSIMDJSON_THREADS_ENABLED=1', '-Wno-ambiguous-reversed-operator'],
link_with : simdjson_lib link_with : simdjson_lib
) )
simdjson_multiple_headers = declare_dependency( simdjson_multiple_headers = declare_dependency(
include_directories: include_directories('include'), include_directories: include_directories('include'),
compile_args : '-DSIMDJSON_THREADS_ENABLED=1' compile_args : ['-DSIMDJSON_THREADS_ENABLED=1', '-Wno-ambiguous-reversed-operator'],
) )