diff --git a/_sources/generated.json b/_sources/generated.json index 0a79905..a0328a4 100644 --- a/_sources/generated.json +++ b/_sources/generated.json @@ -13,16 +13,16 @@ "name": null, "owner": "fmtlib", "repo": "fmt", - "rev": "11.1.3", - "sha256": "sha256-6r9D/csVSgS+T/H0J8cSR+YszxnH/h2V2odi2s6VYN8=", + "rev": "11.1.4", + "sha256": "sha256-sUbxlYi/Aupaox3JjWFqXIjcaQa0LFjclQAOleT+FRA=", "sparseCheckout": [], "type": "github" }, - "version": "11.1.3" + "version": "11.1.4" }, "reflect-cpp": { "cargoLocks": null, - "date": null, + "date": "2025-03-02", "extract": null, "name": "reflect-cpp", "passthru": null, @@ -34,12 +34,12 @@ "name": null, "owner": "getml", "repo": "reflect-cpp", - "rev": "v0.17.0", - "sha256": "sha256-ugMop4Gsw46zFA7mESNzDTAZVzIg3szAX8ND1kUiF2A=", + "rev": "ec8c19fa3e931d736b3f3ff2e400fce4a5f97829", + "sha256": "sha256-3bbaVbU9ICQ8no/3W4M8ePsnrZR3e3CWhT3RO3lL3r0=", "sparseCheckout": [], "type": "github" }, - "version": "v0.17.0" + "version": "ec8c19fa3e931d736b3f3ff2e400fce4a5f97829" }, "sdbus-cpp": { "cargoLocks": null, diff --git a/_sources/generated.nix b/_sources/generated.nix index 41e2033..becfdc3 100644 --- a/_sources/generated.nix +++ b/_sources/generated.nix @@ -3,25 +3,26 @@ { fmt = { pname = "fmt"; - version = "11.1.3"; + version = "11.1.4"; src = fetchFromGitHub { owner = "fmtlib"; repo = "fmt"; - rev = "11.1.3"; + rev = "11.1.4"; fetchSubmodules = false; - sha256 = "sha256-6r9D/csVSgS+T/H0J8cSR+YszxnH/h2V2odi2s6VYN8="; + sha256 = "sha256-sUbxlYi/Aupaox3JjWFqXIjcaQa0LFjclQAOleT+FRA="; }; }; reflect-cpp = { pname = "reflect-cpp"; - version = "v0.17.0"; + version = "ec8c19fa3e931d736b3f3ff2e400fce4a5f97829"; src = fetchFromGitHub { owner = "getml"; repo = "reflect-cpp"; - rev = "v0.17.0"; + rev = "ec8c19fa3e931d736b3f3ff2e400fce4a5f97829"; fetchSubmodules = false; - sha256 = "sha256-ugMop4Gsw46zFA7mESNzDTAZVzIg3szAX8ND1kUiF2A="; + sha256 = "sha256-3bbaVbU9ICQ8no/3W4M8ePsnrZR3e3CWhT3RO3lL3r0="; }; + date = "2025-03-02"; }; sdbus-cpp = { pname = "sdbus-cpp"; diff --git a/flake.nix b/flake.nix index 21c85aa..8f54f2b 100644 --- a/flake.nix +++ b/flake.nix @@ -35,27 +35,15 @@ inherit (pkgs) fetchFromGitHub fetchgit fetchurl dockerTools; }; - mkPkg = name: - pkgs.pkgsStatic.${name}.overrideAttrs { - inherit (sources.${name}) pname version src; - }; - - fmt = mkPkg "fmt"; + fmt = pkgs.pkgsStatic.fmt.overrideAttrs (old: { + inherit (sources.fmt) pname version src; + }); tomlplusplus = pkgs.pkgsStatic.tomlplusplus.overrideAttrs { inherit (sources.tomlplusplus) pname version src; doCheck = false; }; - sdbus-cpp = pkgs.sdbus-cpp.overrideAttrs { - inherit (sources.sdbus-cpp) pname version src; - - cmakeFlags = [ - (pkgs.lib.cmakeBool "BUILD_CODE_GEN" true) - (pkgs.lib.cmakeBool "BUILD_SHARED_LIBS" false) - ]; - }; - yyjson = pkgs.pkgsStatic.stdenv.mkDerivation { inherit (sources.yyjson) pname version src; @@ -70,6 +58,8 @@ cmakeFlags = [ "-DCMAKE_TOOLCHAIN_FILE=OFF" + "-DCMAKE_CXX_VISIBILITY_PRESET=hidden" + "-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON" "-DREFLECTCPP_TOML=ON" "-DREFLECTCPP_JSON=ON" "-DREFLECTCPP_USE_STD_EXPECTED=ON" @@ -78,14 +68,14 @@ deps = with pkgs.pkgsStatic; [ - # curl - # fmt - # libiconv - # tomlplusplus - # yyjson - # reflect-cpp - # sqlitecpp - # ftxui + curl + fmt + libiconv + tomlplusplus + yyjson + reflect-cpp + sqlitecpp + ftxui ] ++ linuxPkgs; @@ -167,6 +157,7 @@ ++ deps; LD_LIBRARY_PATH = "${lib.makeLibraryPath deps}"; + NIX_ENFORCE_NO_NATIVE = 0; name = "C++"; }; diff --git a/meson.build b/meson.build index 1121097..648d688 100644 --- a/meson.build +++ b/meson.build @@ -1,3 +1,6 @@ +# ----------------------- # +# Project Configuration # +# ----------------------- # project( 'draconis++', 'cpp', @@ -5,126 +8,119 @@ project( default_options: [ 'default_library=static', 'warning_level=everything', - 'buildtype=debug', + 'buildtype=release', ], ) cpp = meson.get_compiler('cpp') +host_system = host_machine.system() -if host_machine.system() == 'darwin' - add_languages('objcpp') - objcpp = meson.get_compiler('objcpp') - add_project_arguments( - objcpp.get_supported_arguments( - [ - '-std=c++2b', - '-Wno-c++20-compat', - '-Wno-c++20-extensions', - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-disabled-macro-expansion', - '-Wno-missing-prototypes', - '-Wno-padded', - '-Wno-pre-c++20-compat-pedantic', - '-Wno-switch-default', - '-Wunused-function', - ], - ), - language: 'objcpp', - ) -endif - -common_cpp_args = [] - -if cpp.get_id() == 'msvc' or cpp.get_id() == 'clang-cl' - common_cpp_args += [ - '/std:c++latest', - '/Zc:__cplusplus', - '-DNOMINMAX', - ] - - if cpp.get_id() == 'clang-cl' - common_cpp_args += [ - '-std=c++26', - '-Wno-c++20-compat', - '-Wno-c++20-extensions', - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-disabled-macro-expansion', - '-Wno-missing-prototypes', - '-Wno-padded', - '-Wno-pre-c++20-compat-pedantic', - '-Wunused-function', - '-fno-strict-enums', - ] - endif - - add_project_arguments(common_cpp_args, language: 'cpp') -else - common_cpp_args += [ - '-std=c++26', - '-Wno-c++20-compat', - '-Wno-c++20-extensions', - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-disabled-macro-expansion', - '-Wno-missing-prototypes', - '-Wno-padded', - '-Wno-pre-c++20-compat-pedantic', - '-Wunused-function', - '-fno-strict-enums', - '-nostdlib++', - '-march=native', - ] - - if host_machine.system() == 'windows' - common_cpp_args += '-DCURL_STATICLIB' - endif - - add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp') -endif - -source_file_names = ['src/main.cpp', 'src/config/config.cpp', 'src/config/weather.cpp'] - -if host_machine.system() == 'linux' - source_file_names += ['src/os/linux.cpp', 'src/os/linux/issetugid_stub.cpp'] -elif host_machine.system() == 'freebsd' - source_file_names += ['src/os/freebsd.cpp'] -elif host_machine.system() == 'darwin' - source_file_names += [ - 'src/os/macos.cpp', - 'src/os/macos/bridge.mm', - ] -elif host_machine.system() == 'windows' - source_file_names += ['src/os/windows.cpp'] -endif - -sources = [] - -foreach file : source_file_names - sources += files(file) -endforeach - -deps = [ - dependency('fmt', include_type: 'system', static: true), - dependency('openssl', include_type: 'system', static: true, required: false), - dependency('libcurl', include_type: 'system', static: true), - dependency('tomlplusplus', include_type: 'system', static: true), +# ------------------------ # +# Compiler Configuration # +# ------------------------ # +common_warning_flags = [ + '-Wno-c++20-compat', + '-Wno-c++20-extensions', + '-Wno-c++98-compat', + '-Wno-c++98-compat-pedantic', + '-Wno-disabled-macro-expansion', + '-Wno-missing-prototypes', + '-Wno-padded', + '-Wno-pre-c++20-compat-pedantic', + '-Wunused-function', ] -if host_machine.system() == 'darwin' - deps += dependency( - 'appleframeworks', - modules: ['foundation', 'mediaplayer', 'systemconfiguration'], - static: true, - ) -elif host_machine.system() == 'windows' - deps += [ +common_cpp_flags = { + 'common': [ + '-fno-strict-enums', + '-fvisibility=hidden', + '-fvisibility-inlines-hidden', + '-std=c++26', + ], + 'msvc': [ + '-DNOMINMAX', + '/Zc:__cplusplus', + '/std:c++latest', + ], + 'unix_extra': [ + '-march=native', + '-nostdlib++', + ], + 'windows_extra': '-DCURL_STATICLIB' +} + +# Configure Objective-C++ for macOS +if host_system == 'darwin' + add_languages('objcpp', native: false) + objcpp = meson.get_compiler('objcpp') + objcpp_flags = common_warning_flags + [ + '-Wno-switch-default', + '-std=c++2b', + '-fvisibility=hidden', + '-fvisibility-inlines-hidden', + ] + add_project_arguments(objcpp.get_supported_arguments(objcpp_flags), language: 'objcpp') +endif + +# Apply C++ compiler arguments +if cpp.get_id() in ['msvc', 'clang-cl'] + common_cpp_args = common_cpp_flags['msvc'] + if cpp.get_id() == 'clang-cl' + common_cpp_args += common_warning_flags + common_cpp_flags['common'] + endif +else + common_cpp_args = common_warning_flags + common_cpp_flags['common'] + common_cpp_flags['unix_extra'] + if host_system == 'windows' + common_cpp_args += common_cpp_flags['windows_extra'] + endif + common_cpp_args = cpp.get_supported_arguments(common_cpp_args) +endif + +add_project_arguments(common_cpp_args, language: 'cpp') + +# ------- # +# Files # +# ------- # +base_sources = files( + 'src/main.cpp', + 'src/config/config.cpp', + 'src/config/weather.cpp' +) + +platform_sources = { + 'linux': ['src/os/linux.cpp', 'src/os/linux/issetugid_stub.cpp'], + 'freebsd': ['src/os/freebsd.cpp'], + 'darwin': ['src/os/macos.cpp', 'src/os/macos/bridge.mm'], + 'windows': ['src/os/windows.cpp'] +} + +sources = base_sources + files(platform_sources.get(host_system, [])) + +# --------------------- # +# Dependencies Config # +# --------------------- # +common_deps = [ + dependency('fmt', include_type: 'system', static: true), + dependency('libcurl', include_type: 'system', static: true), + dependency('tomlplusplus', include_type: 'system', static: true), + dependency('openssl', include_type: 'system', static: true, required: false), +] + +# Platform-specific dependencies +platform_deps = [] + +if host_system == 'darwin' + platform_deps += [ + dependency('appleframeworks', modules: ['foundation', 'mediaplayer', 'systemconfiguration'], static: true), + dependency('iconv') + ] +elif host_system == 'windows' + platform_deps += [ cpp.find_library('dwmapi'), cpp.find_library('windowsapp'), ] -elif host_machine.system() == 'linux' or host_machine.system() == 'freebsd' - deps += [ +elif host_system == 'linux' or host_system == 'freebsd' + platform_deps += [ dependency('SQLiteCpp'), dependency('sdbus-c++'), dependency('x11'), @@ -136,60 +132,60 @@ elif host_machine.system() == 'linux' or host_machine.system() == 'freebsd' ] endif +# FTXUI configuration cmake = import('cmake') - -ftxui_dep = dependency( - 'ftxui', - modules: ['ftxui::screen', 'ftxui::dom', 'ftxui::component'], - include_type: 'system', - static: true, - required: false, -) +ftxui_components = ['ftxui::screen', 'ftxui::dom', 'ftxui::component'] +ftxui_dep = dependency('ftxui', modules: ftxui_components, include_type: 'system', static: true, required: false) if not ftxui_dep.found() - ftxui_dom = dependency('ftxui-dom', fallback: ['ftxui', 'dom_dep']) - ftxui_screen = dependency('ftxui-screen', fallback: ['ftxui', 'screen_dep']) - ftxui_component = dependency('ftxui-component', fallback: ['ftxui', 'component_dep']) - ftxui_dep = declare_dependency(dependencies: [ftxui_dom, ftxui_screen, ftxui_component]) + ftxui_dep = declare_dependency( + dependencies: [ + dependency('ftxui-dom', fallback: ['ftxui', 'dom_dep']), + dependency('ftxui-screen', fallback: ['ftxui', 'screen_dep']), + dependency('ftxui-component', fallback: ['ftxui', 'component_dep']) + ] + ) endif -deps += ftxui_dep +# ReflectCpp configuration +reflectcpp_dep = dependency('reflectcpp', include_type: 'system', required: false, static: true) +if not reflectcpp_dep.found() + cmake_opts = cmake.subproject_options() + cxx_flags = cpp.get_id() == 'msvc' ? '/w' : '-Wno-everything -std=c++26 -fvisibility=hidden' # Added visibility flag -cmake_opts = cmake.subproject_options() + cmake_opts.add_cmake_defines({ + 'CMAKE_CXX_FLAGS': cxx_flags, + 'CMAKE_VISIBILITY_INLINES_HIDDEN': 'ON' # Add this line + }) + cmake_opts.append_compile_args('cpp', cxx_flags) -if cpp.get_id() == 'msvc' - cmake_opts.add_cmake_defines( - { - 'CMAKE_CXX_FLAGS': '/w', - }, - ) - cmake_opts.append_compile_args('cpp', '/w') -else - cmake_opts.add_cmake_defines( - { - 'CMAKE_CXX_FLAGS': '-Wno-everything -std=c++26', - }, - ) - cmake_opts.append_compile_args('cpp', '-Wno-everything -std=c++26') + reflectcpp_proj = cmake.subproject('reflectcpp', options: cmake_opts) + reflectcpp_dep = reflectcpp_proj.dependency('reflectcpp', include_type: 'system') endif -reflectcpp_proj = cmake.subproject('reflectcpp', options: cmake_opts) -reflectcpp_dep = reflectcpp_proj.dependency('reflectcpp', include_type: 'system') -deps += reflectcpp_dep +# Combine all dependencies +deps = common_deps + platform_deps + [ftxui_dep, reflectcpp_dep] -objc_args = [] +# ------------------------- # +# Link/ObjC Configuration # +# ------------------------- # link_args = [] +objc_args = [] -if host_machine.system() == 'darwin' +if host_system == 'darwin' objc_args += ['-fobjc-arc'] -elif host_machine.system() == 'linux' +elif host_system == 'linux' link_args += ['-static-libgcc', '-static-libstdc++', '-static'] endif +# ------------------- # +# Executable Target # +# ------------------- # executable( 'draconis++', sources, objc_args: objc_args, link_args: link_args, dependencies: deps, + install: true, ) diff --git a/nvfetcher.toml b/nvfetcher.toml new file mode 100644 index 0000000..e1c35e3 --- /dev/null +++ b/nvfetcher.toml @@ -0,0 +1,19 @@ +[fmt] +src.github = "fmtlib/fmt" +fetch.github = "fmtlib/fmt" + +[reflect-cpp] +src.git = "https://github.com/getml/reflect-cpp" +fetch.github = "getml/reflect-cpp" + +[sdbus-cpp] +src.github = "kistler-group/sdbus-cpp" +fetch.github = "kistler-group/sdbus-cpp" + +[tomlplusplus] +src.github = "marzer/tomlplusplus" +fetch.github = "marzer/tomlplusplus" + +[yyjson] +src.github = "ibireme/yyjson" +fetch.github = "ibireme/yyjson" diff --git a/src/config/weather.cpp b/src/config/weather.cpp index fdb76de..3aa7237 100644 --- a/src/config/weather.cpp +++ b/src/config/weather.cpp @@ -40,7 +40,7 @@ namespace { DEBUG_LOG("Reading from cache file..."); - const std::string content((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + const std::string content((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); rfl::Result result = rfl::json::read(content); if (!result) diff --git a/src/main.cpp b/src/main.cpp index 7e3007a..d5520e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "config/config.h" @@ -95,10 +96,10 @@ namespace { data.window_manager = GetWindowManager(); // Parallel execution for disk/shell only - auto diskShell = std::async(std::launch::async, [] { - auto [used, total] = GetDiskUsage(); - return std::make_tuple(used, total, GetShell()); - }); + // auto diskShell = std::async(std::launch::async, [] { + // auto [used, total] = GetDiskUsage(); + // return std::make_tuple(used, total, GetShell()); + // }); // Conditional tasks std::future weather; @@ -113,10 +114,10 @@ namespace { } // Get remaining results - auto [used, total, shell] = diskShell.get(); - data.disk_used = used; - data.disk_total = total; - data.shell = shell; + // auto [used, total, shell] = diskShell.get(); + // data.disk_used = used; + // data.disk_total = total; + // data.shell = shell; if (weather.valid()) data.weather_info = weather.get(); @@ -167,25 +168,21 @@ namespace { content.push_back(text("  Hello " + name + "! ") | bold | color(Color::Cyan)); content.push_back(separator() | color(borderColor)); - content.push_back(hbox( - { - text("  ") | color(iconColor), // Palette icon - CreateColorCircles(), - } - )); + content.push_back(hbox({ + text("  ") | color(iconColor), // Palette icon + CreateColorCircles(), + })); content.push_back(separator() | color(borderColor)); // Helper function for aligned rows fn createRow = [&](const std::string& icon, const std::string& label, const std::string& value) { - return hbox( - { - text(icon) | color(iconColor), - text(label) | color(labelColor), - filler(), - text(value) | color(valueColor), - text(" "), - } - ); + return hbox({ + text(icon) | color(iconColor), + text(label) | color(labelColor), + filler(), + text(value) | color(valueColor), + text(" "), + }); }; // System info rows @@ -196,39 +193,31 @@ namespace { const WeatherOutput& weatherInfo = data.weather_info.value(); if (weather.show_town_name) - content.push_back(hbox( - { - text(weatherIcon) | color(iconColor), - text("Weather") | color(labelColor), - filler(), + content.push_back(hbox({ + text(weatherIcon) | color(iconColor), + text("Weather") | color(labelColor), + filler(), - hbox( - { - text(fmt::format("{}°F ", std::lround(weatherInfo.main.temp))), - text("in "), - text(weatherInfo.name), - text(" "), - } - ) | - color(valueColor), - } - )); + hbox({ + text(fmt::format("{}°F ", std::lround(weatherInfo.main.temp))), + text("in "), + text(weatherInfo.name), + text(" "), + }) | + color(valueColor), + })); else - content.push_back(hbox( - { - text(weatherIcon) | color(iconColor), - text("Weather") | color(labelColor), - filler(), + content.push_back(hbox({ + text(weatherIcon) | color(iconColor), + text("Weather") | color(labelColor), + filler(), - hbox( - { - text(fmt::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)), - text(" "), - } - ) | - color(valueColor), - } - )); + hbox({ + text(fmt::format("{}°F, {}", std::lround(weatherInfo.main.temp), weatherInfo.weather[0].description)), + text(" "), + }) | + color(valueColor), + })); } content.push_back(separator() | color(borderColor)); @@ -244,19 +233,18 @@ namespace { else ERROR_LOG("Failed to get OS version: {}", data.os_version.error()); - // Add disk row after memory info if (data.mem_info.has_value()) content.push_back(createRow(memoryIcon, "RAM", fmt::format("{}", BytesToGiB { *data.mem_info }))); else ERROR_LOG("Failed to get memory info: {}", data.mem_info.error()); // Add Disk usage row - content.push_back( - createRow(" 󰋊 ", "Disk", fmt::format("{}/{}", BytesToGiB { data.disk_used }, BytesToGiB { data.disk_total })) - ); + // content.push_back( + // createRow(" 󰋊 ", "Disk", fmt::format("{}/{}", BytesToGiB { data.disk_used }, BytesToGiB { data.disk_total + // })) + // ); - // Add Shell row - content.push_back(createRow("  ", "Shell", data.shell)); + // content.push_back(createRow("  ", "Shell", data.shell)); content.push_back(separator() | color(borderColor)); @@ -274,16 +262,14 @@ namespace { const std::string& npText = *nowPlayingResult; content.push_back(separator() | color(borderColor)); - content.push_back(hbox( - { - text(musicIcon) | color(iconColor), - text("Playing") | color(labelColor), - text(" "), - filler(), - paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, 30), - text(" "), - } - )); + content.push_back(hbox({ + text(musicIcon) | color(iconColor), + text("Playing") | color(labelColor), + text(" "), + filler(), + paragraph(npText) | color(Color::Magenta) | size(WIDTH, LESS_THAN, 30), + text(" "), + })); } else { const NowPlayingError& error = nowPlayingResult.error(); @@ -295,6 +281,11 @@ namespace { case NowPlayingCode::NoActivePlayer: DEBUG_LOG("No active player found"); break; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcovered-switch-default" + default: + std::unreachable(); +#pragma clang diagnostic pop } #ifdef __linux__ diff --git a/src/util/macros.h b/src/util/macros.h index d016989..526ebb1 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -1,6 +1,7 @@ #pragma once // probably stupid but it fixes the issue with windows.h defining ERROR +#include #undef ERROR #include @@ -35,6 +36,11 @@ void LogImpl(const LogLevel level, const std::source_location& loc, fmt::format_ return std::make_pair(log_colors::warn, "WARN "); case LogLevel::ERROR: return std::make_pair(log_colors::error, "ERROR"); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcovered-switch-default" + default: + std::unreachable(); +#pragma clang diagnostic pop } }(); @@ -45,7 +51,7 @@ void LogImpl(const LogLevel level, const std::source_location& loc, fmt::format_ if (localtime_s(&time, &now) != 0) throw std::runtime_error("localtime_s failed"); #else - if (localtime_r(&now, &localTime) == nullptr) + if (localtime_r(&now, &time) == nullptr) throw std::runtime_error("localtime_r failed"); #endif