On Thu, May 15, 2025 at 06:13:56PM +0800, Congcong Kuo wrote:
> Hello Guix,
> 
> Currently guix-daemon is built using GCC 11 with -std=c++11. We are waiting 
> for guile-daemon [1], but we can have improvements on guix-daemon right now.
> 
> In nix/libutil/util.cc there are lots of functions related to copy/delete 
> files and manipulate file paths. In C++ 17 the standard library’s 
> <filesystem> provides the same functionality which is more reliable.
> 
> guix-daemon uses Boost.Format to generate formatted string. These code are 
> copied into nix/libformat directly and I think it is not a good practice. 
> With C++ 20 we can use <format> from C++’s standard library. I have done some 
> experiments on it [2]. In my code repo I replace all boost::format with 
> std::format in nix/libutil.
> 
> We can use <filesystem> if we upgrade from —std=c++11 to -std=c++17. For 
> <format> we need GCC 13 with -std=c++20.
> 
> WDYT?
> 
> Regards,
> Kuo
> 
> [1]: https://guix.gnu.org/en/blog/2023/a-build-daemon-in-guile/
> [2]: 
> https://codeberg.org/congcongkuo/guix-daemon-zig/commit/38b8722f53d17ae4c5826dab051f4fdb00da31db

We currently have gcc-11 as our default gcc in Guix, so let's see if
that's possible.  Quoting from the gcc-11.5.0 manual[3]:

By default, GCC also provides some additional extensions to the C++
language that on rare occasions conflict with the C++ standard. See
Options Controlling C++ Dialect. Use of the -std options listed above
disables these extensions where they they conflict with the C++ standard
version selected. You may also select an extended version of the C++
language explicitly with -std=gnu++98 (for C++98 with GNU extensions),
or -std=gnu++11 (for C++11 with GNU extensions), or -std=gnu++14 (for
C++14 with GNU extensions), or -std=gnu++17 (for C++17 with GNU
extensions), or -std=gnu++20 (for C++20 with GNU extensions).

The default, if no C++ language dialect options are given, is -std=gnu++17.

(It also mentions that you can use the c++ versions of these flags.)

In nix/local.mk we have the following:
 # Use '-std=c++11' for 'std::shared_ptr', 'auto', lambdas, and more.¬
 AM_CXXFLAGS = -Wall -std=c++11

(These lines are unchanged since May 2015.)

gcc-10.5.0 doesn't give any mention of c++20/gnu++20, so it sounds like
it would make gcc-11 the minimum version for building the daemon if we
ditched Boost.Format and used <format>.  I think overall it would be a
good idea to not vendor that library, and this would allow us to do
that.

As far as packaging Guix in a foreign distro, I don't think it would be
a problem to require such a "new" version of gcc.


[3] 
https://gcc.gnu.org/onlinedocs/gcc-11.5.0/gcc/Standards.html#C_002b_002b-Language

-- 
Efraim Flashner   <efr...@flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

Attachment: signature.asc
Description: PGP signature

Reply via email to