From 2e38196ea5065999c69b1b2e4dd3bbf845e8da99 Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 5 Jul 2025 03:17:42 +0300 Subject: [PATCH] import std Signed-off-by: Slendi --- CMakeLists.txt | 7 +++-- flake.nix | 8 +++++- nix/cmake-importstd-patched/package.nix | 37 +++++++++++++++++++++++++ src/LunarWM.cppm | 4 +-- src/Math.cppm | 5 +--- src/main.cpp | 3 +- src/wl/Region.cppm | 5 ++-- src/wl/Shm.cppm | 11 ++++---- src/wl/Subsurface.cppm | 4 +-- 9 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 nix/cmake-importstd-patched/package.nix diff --git a/CMakeLists.txt b/CMakeLists.txt index eebf597..1bf4031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,12 @@ -cmake_minimum_required(VERSION 3.30) +cmake_minimum_required(VERSION 3.31) -project(LunarWM C CXX) +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + +project(LunarWM LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_MODULE_STD 1) find_package(PkgConfig) diff --git a/flake.nix b/flake.nix index faddd0c..0675844 100644 --- a/flake.nix +++ b/flake.nix @@ -23,11 +23,17 @@ in { devShells.default = pkgs.mkShell.override { stdenv = pkgs.llvmPackages_20.libcxxStdenv; } { + hardeningDisable = [ "fortify" ]; + packages = with pkgs; [ + (pkgs.callPackage ./nix/cmake-importstd-patched/package.nix { + libcxx = pkgs.llvmPackages_20.libcxx; + }) + pkg-config cmake ninja - clang-tools + (pkgs.llvmPackages_20.clang-tools.override { enableLibcxx = true; }) lldb # For wlroots diff --git a/nix/cmake-importstd-patched/package.nix b/nix/cmake-importstd-patched/package.nix new file mode 100644 index 0000000..aabc84e --- /dev/null +++ b/nix/cmake-importstd-patched/package.nix @@ -0,0 +1,37 @@ +# Dummy cmake package for replacing the ImportStd module. +# Symlink existing derivation to avoid rebuilding package from source. +# I.e. rather than using overlay or override(Attr) to add patch. +# +# Note this is actually a clang/llvm issue (`-print-file-name` flag not working), +# but it is much simpler to just patch the cmake module itself. Maybe fixed in llvm 19.1.7 +# +# See relevant issues: +# 1. https://github.com/NixOS/nixpkgs/issues/370217 +# 2. https://gitlab.kitware.com/cmake/cmake/-/issues/25965#note_1523575 +{ + lib, + cmake, + libcxx, + symlinkJoin, +}: +let + cmake-ver = "${lib.versions.majorMinor cmake.version}"; + module-path = "share/cmake-${cmake-ver}/Modules/Compiler/Clang-CXX-CXXImportStd.cmake"; +in +symlinkJoin { + name = "${cmake.name}-importstd-module-patched"; + paths = [ cmake ]; + postBuild = '' + # copy binaries to avoid using original derivation + for link in $(find $out/bin/ -type l); do + cp --remove-destination $(readlink $link) $out/bin/ + done; + + # replace symlink to existing module with copy for editing + cp --remove-destination $(readlink $out/${module-path}) $out/${module-path} + + # replace "libc++.modules.json" with full path + # to libc++ module json in new copied module file + sed -i 's#libc++.modules.json#${libcxx}/lib/libc++.modules.json#' $out/${module-path} + ''; +} diff --git a/src/LunarWM.cppm b/src/LunarWM.cppm index 018f138..304d7ed 100644 --- a/src/LunarWM.cppm +++ b/src/LunarWM.cppm @@ -1,8 +1,6 @@ module; -#include #include -#include #include #include @@ -11,6 +9,8 @@ module; export module LunarWM.LunarWM; +import std; + import LunarWM.wl.Subcompositor; import LunarWM.wl.Shm; diff --git a/src/Math.cppm b/src/Math.cppm index 6d82727..1b5d2b5 100644 --- a/src/Math.cppm +++ b/src/Math.cppm @@ -1,9 +1,6 @@ module; -#include -#include -#include -#include +import std; export module LunarWM.Math; diff --git a/src/main.cpp b/src/main.cpp index a481538..e9b1d8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include -#include + +import std; import LunarWM.LunarWM; diff --git a/src/wl/Region.cppm b/src/wl/Region.cppm index 3311e57..2fa0c25 100644 --- a/src/wl/Region.cppm +++ b/src/wl/Region.cppm @@ -1,14 +1,13 @@ module; -#include -#include - #include #include "util.h" export module LunarWM.wl.Region; +import std; + import LunarWM.Math; namespace LunarWM { diff --git a/src/wl/Shm.cppm b/src/wl/Shm.cppm index 46b92e0..1340a62 100644 --- a/src/wl/Shm.cppm +++ b/src/wl/Shm.cppm @@ -2,18 +2,17 @@ module; #include #include -#include - -#include - -#include - #include #include #include +#include +#include + export module LunarWM.wl.Shm; +import std; + namespace LunarWM { namespace wl { diff --git a/src/wl/Subsurface.cppm b/src/wl/Subsurface.cppm index d2168c9..29d100b 100644 --- a/src/wl/Subsurface.cppm +++ b/src/wl/Subsurface.cppm @@ -2,12 +2,12 @@ module; #include "util.h" -#include - #include export module LunarWM.wl.Subsurface; +import std; + namespace LunarWM { namespace wl {