Subject: bug#65486: closed (Re: bug#65486: [PATCH] syscalls: Add support for musl libc)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 17 Sep 2023 10:15:02 +0000

Your bug report

#65486: [PATCH] syscalls: Add support for musl libc

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
65486: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65486
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#65486: [PATCH] syscalls: Add support for musl libc
From: Ludovic Courtès <[email-masked]>
To: Sören Tempel <[email-masked]>
Cc: [email-masked]
Date: Sun, 17 Sep 2023 12:14:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

Sören Tempel <[email-masked]> skribis:

> From b1d478defc7f3e794974be2b9665cd4a58030569 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <[email-masked]>
> Date: Thu, 14 Sep 2023 12:35:38 +0000
> Subject: [PATCH] syscalls: Add support for musl libc
>
> This commit allows using Guix on a foreign distro which uses musl libc,
> for example, Alpine Linux. Usage of musl libc is detected via a new
> musl-libc? variable using the Guile %host-type.
>
> Using the new musl-libc? variable, we can now implement musl-specific
> quirks. The two compatibility problems I encountered in this regard are
> that musl dose not export a readdir64 and statfs64 symbol. On musl,
> these two functions are implemented as CPP macros that expand to
> readdir/statfs. To workaround that, a case-distinction was added.
>
> The existing linux? variable has been modified to return true if the
> %host-system contains "linux-" in order to ensure it is true for both
> linux-gnu as well as linux-musl host systems.
>
> The patch has been tested on Alpine Linux and is already used for the
> downstream Guix package shipped in Alpine Linux's package repository.
>
> * guix/build/syscalls.scm (musl-libc?): New variable.
> * guix/build/syscalls.scm (linux?): Truth value on any linux system.
> * guix/build/syscalls.scm (readdir-procedure): Support musl libc.
> * guix/build/syscalls.scm (statfs): Support musl libc.

This version LGTM.  Applied, thanks!

Ludo’.

Subject: [PATCH] syscalls: Add support for musl libc
From: [email-masked]
To: [email-masked]
Date: Thu, 24 Aug 2023 08:33:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

From: Sören Tempel <[email-masked]>

This commit allows using Guix on a foreign distro which uses musl libc,
for example, Alpine Linux. Such a distro is detected via the new
linux-musl? variable based on the %host-type.

Using the new linux-musl? variable, we can now implement musl-specific
quirks. The only problem I encountered in this regard so far is that
musl does not export a readdir64 symbol. On musl, readdir64 is a CPP
macro that expands to readdir. For this reason, readdir-procedure now
uses readdir over readdir64 if the host-system uses musl libc.

The existing linux? variable is now set to a truth value if the
host-system is either a linux-gnu or a linux-musl. A new linux-gnu?
variable can be used to detect linux-gnu systems.

The patch has been tested on Alpine Linux and is already used for the
downstream Guix package shipped in Alpine Linux's package repository.

* guix/build/syscalls.scm (linux-gnu?): New variable.
* guix/build/syscalls.scm (linux-musl?): New variable.
* guix/build/syscalls.scm (linux?): Truth value on musl or GNU Linux.
* guix/build/syscalls.scm (readdir-procedure): Support musl libc.

Signed-off-by: Sören Tempel <[email-masked]>
---
 guix/build/syscalls.scm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index d947b010d3..a690e8da0b 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -836,7 +836,9 @@ (define-record-type <file-system>
 (define-syntax fsword                             ;fsword_t
   (identifier-syntax long))
 
-(define linux? (string-contains %host-type "linux-gnu"))
+(define linux-gnu?  (string-contains %host-type "linux-gnu"))
+(define linux-musl? (string-contains %host-type "linux-musl"))
+(define linux?      (or linux-gnu? linux-musl?))
 
 (define-syntax define-statfs-flags
   (syntax-rules (linux hurd)
@@ -1232,7 +1234,12 @@ (define closedir*
 
 (define (readdir-procedure name-field-offset sizeof-dirent-header
                            read-dirent-header)
-  (let ((proc (syscall->procedure '* "readdir64" '(*))))
+  (let ((proc (syscall->procedure '*
+                                  (cond
+                                    (linux-gnu?  "readdir64")
+                                    (linux-musl? "readdir")
+                                    (else (error "unknown linux variant")))
+                                  '(*))))
     (lambda* (directory #:optional (pointer->string pointer->string/utf-8))
       (let ((ptr (proc directory)))
         (and (not (null-pointer? ptr))