From patchwork Sun Sep 17 15:21:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Tempel?= X-Patchwork-Id: 53991 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E140927BBE2; Sun, 17 Sep 2023 16:23:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 49B6127BBE9 for ; Sun, 17 Sep 2023 16:23:13 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhtbw-0006FL-9T; Sun, 17 Sep 2023 11:23:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhtbs-0006Ed-QB for guix-patches@gnu.org; Sun, 17 Sep 2023 11:22:56 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhtbs-0003ps-Hp for guix-patches@gnu.org; Sun, 17 Sep 2023 11:22:56 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qhtc0-0000h8-67 for guix-patches@gnu.org; Sun, 17 Sep 2023 11:23:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65486] [PATCH v3] syscalls: Add support for musl libc Resent-From: soeren@soeren-tempel.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 17 Sep 2023 15:23:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65486 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 65486@debbugs.gnu.org Cc: ludo@gnu.org X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Cc: 65486@debbugs.gnu.org, ludo@gnu.org Received: via spool by 65486-submit@debbugs.gnu.org id=B65486.16949641422554 (code B ref 65486); Sun, 17 Sep 2023 15:23:04 +0000 Received: (at 65486) by debbugs.gnu.org; 17 Sep 2023 15:22:22 +0000 Received: from localhost ([127.0.0.1]:51173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhtbK-0000f7-FC for submit@debbugs.gnu.org; Sun, 17 Sep 2023 11:22:22 -0400 Received: from magnesium.8pit.net ([45.76.88.171]:22415) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhtbD-0000eA-P5; Sun, 17 Sep 2023 11:22:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=fp6dfzRq/g DQwuotX9I6Gg0Qbx07ZXvPoJC7op9GSNY=; h=references:in-reply-to:date: subject:cc:to:from; d=soeren-tempel.net; b=eRt7HdBoTKhChsmVgUrkYG2FLCx fo5r0JrT79aSqzMf5a9StKHP27qENvNcmOpy+CM+A4ZE5784/vx/soNhWKOmboDlMsHTsq Y/61IGX2Odk+LEu5bOTzFlTj1N2zYZY6/sj7fx3p0L3sdX+dsR01iIE1GmnwRsDGWxfc/K /Nog= Received: from localhost (ip-078-094-021-002.um19.pools.vodafone-ip.de [78.94.21.2]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 64276c78 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Sun, 17 Sep 2023 17:21:56 +0200 (CEST) From: soeren@soeren-tempel.net Date: Sun, 17 Sep 2023 17:21:49 +0200 Message-ID: <20230917152149.8587-2-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230917152149.8587-1-soeren@soeren-tempel.net> References: <87il89yugy.fsf@gnu.org> <20230917152149.8587-1-soeren@soeren-tempel.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Sören Tempel 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. Signed-off-by: Sören Tempel --- guix/build/syscalls.scm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index c9c0bf594d..b845b8aab9 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -836,7 +836,8 @@ (define-record-type (define-syntax fsword ;fsword_t (identifier-syntax long)) -(define linux? (string-contains %host-type "linux-gnu")) +(define musl-libc? (string-contains %host-type "linux-musl")) +(define linux? (string-contains %host-type "linux-")) (define-syntax define-statfs-flags (syntax-rules (linux hurd) @@ -905,7 +906,7 @@ (define-c-struct %statfs ; (spare (array fsword 4))) (define statfs - (let ((proc (syscall->procedure int "statfs64" '(* *)))) + (let ((proc (syscall->procedure int (if musl-libc? "statfs" "statfs64") '(* *)))) (lambda (file) "Return a data structure describing the file system mounted at FILE." @@ -1232,7 +1233,7 @@ (define closedir* (define (readdir-procedure name-field-offset sizeof-dirent-header read-dirent-header) - (let ((proc (syscall->procedure '* "readdir64" '(*)))) + (let ((proc (syscall->procedure '* (if musl-libc? "readdir" "readdir64") '(*)))) (lambda* (directory #:optional (pointer->string pointer->string/utf-8)) (let ((ptr (proc directory))) (and (not (null-pointer? ptr))