From patchwork Thu Aug 24 06:33:05 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: 53185 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 2AF1D27BBE9; Thu, 24 Aug 2023 07:35:14 +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 3106127BBE2 for ; Thu, 24 Aug 2023 07:35:12 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZ3vo-0000bT-9Y; Thu, 24 Aug 2023 02:35: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 1qZ3vn-0000bK-0F for guix-patches@gnu.org; Thu, 24 Aug 2023 02:34:59 -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 1qZ3vm-0000Lx-OD for guix-patches@gnu.org; Thu, 24 Aug 2023 02:34:58 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZ3vq-00007w-2R for guix-patches@gnu.org; Thu, 24 Aug 2023 02:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65486] [PATCH] syscalls: Add support for musl libc Resent-From: soeren@soeren-tempel.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 24 Aug 2023 06:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65486 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65486@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1692858856407 (code B ref -1); Thu, 24 Aug 2023 06:35:01 +0000 Received: (at submit) by debbugs.gnu.org; 24 Aug 2023 06:34:16 +0000 Received: from localhost ([127.0.0.1]:35980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZ3v5-00006S-Qo for submit@debbugs.gnu.org; Thu, 24 Aug 2023 02:34:16 -0400 Received: from lists.gnu.org ([2001:470:142::17]:41126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZ3uz-000068-VT for submit@debbugs.gnu.org; Thu, 24 Aug 2023 02:34:14 -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 1qZ3up-00072J-Gx for guix-patches@gnu.org; Thu, 24 Aug 2023 02:33:59 -0400 Received: from magnesium.8pit.net ([45.76.88.171]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZ3ul-0000Hn-ID; Thu, 24 Aug 2023 02:33:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=FTSMDA9n59 JCXXL4KvmHbSYBo8rWI/zoBNPQP45qVks=; h=date:subject:to:from; d=soeren-tempel.net; b=I8+UkETJejDlXgdQC0VkHdwis1ediBFxBraGolzC8PXkviO cPP2z4eX0YK0arN4Uz4OprLh1GNC4bI4efHh+K0m0ioe5EDjiGjIfqWwV4ripvOfU2Mw1i Cnt9x4OQXx1Lmo0+BV6pIQCHy9NmexYZSUfjuUqa+bfVin+h6ThS5Y= Received: from localhost (dynamic-2a02-3102-49da-001b-8471-2294-2cf4-4d1a.310.pool.telefonica.de [2a02:3102:49da:1b:8471:2294:2cf4:4d1a]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 7b3c79d8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Thu, 24 Aug 2023 08:33:44 +0200 (CEST) From: soeren@soeren-tempel.net Date: Thu, 24 Aug 2023 08:33:05 +0200 Message-ID: <20230824063303.7928-3-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Received-SPF: pass client-ip=45.76.88.171; envelope-from=soeren@soeren-tempel.net; helo=magnesium.8pit.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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. 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 --- 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 (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))