From patchwork Sat Nov 18 16:52:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekaitz Zarraga X-Patchwork-Id: 56610 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 EA38727BBE2; Sat, 18 Nov 2023 16:53:30 +0000 (GMT) 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 38CDD27BBE9 for ; Sat, 18 Nov 2023 16:53:29 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4OZH-0007Hc-DL; Sat, 18 Nov 2023 11:53:16 -0500 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 1r4OZ3-0007Ei-Tb for guix-patches@gnu.org; Sat, 18 Nov 2023 11:53:06 -0500 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 1r4OZ3-0007qj-JZ for guix-patches@gnu.org; Sat, 18 Nov 2023 11:53:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r4OZ4-0005fN-FS for guix-patches@gnu.org; Sat, 18 Nov 2023 11:53:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67075] [PATCH] build: zig-build-system: Add CPU option References: In-Reply-To: Resent-From: Ekaitz Zarraga Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 18 Nov 2023 16:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67075 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 67075@debbugs.gnu.org Received: via spool by 67075-submit@debbugs.gnu.org id=B67075.170032638121773 (code B ref 67075); Sat, 18 Nov 2023 16:53:02 +0000 Received: (at 67075) by debbugs.gnu.org; 18 Nov 2023 16:53:01 +0000 Received: from localhost ([127.0.0.1]:49423 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4OZ2-0005f7-J6 for submit@debbugs.gnu.org; Sat, 18 Nov 2023 11:53:01 -0500 Received: from dane.soverin.net ([2a10:de80:1:4092:b9e9:2294:0:1]:57363) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4OYy-0005er-LG for 67075@debbugs.gnu.org; Sat, 18 Nov 2023 11:52:59 -0500 Received: from smtp.soverin.net (unknown [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4SXfw135fWz2xFP for <67075@debbugs.gnu.org>; Sat, 18 Nov 2023 16:52:49 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.99]) by soverin.net (Postfix) with ESMTPSA id 4SXfw04wgHz3v for <67075@debbugs.gnu.org>; Sat, 18 Nov 2023 16:52:48 +0000 (UTC) Authentication-Results: smtp.soverin.net; dkim=pass (2048-bit key; unprotected) header.d=elenq.tech header.i=@elenq.tech header.a=rsa-sha256 header.s=soverin1 header.b=EBPGCsWR; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elenq.tech; s=soverin1; t=1700326368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=SgqBz4J4jx5Wk7X8iUc7hDBdsVHLzqkwaNkvhFJ3GXQ=; b=EBPGCsWRom1u5BD4kOAF6LdopXwg6yWXF/RfKcuK0/MhmTfdSVecSzIAn37Pm0nrMgMUJe 4n2kRWwL2Zczerk4SpOo/HhiQh9peK5hWxJAVvBpIlGKAU3O+8eh9z7xL2fOi6ijKjFnHW 8uJ26mkvQNmA/fP9vzemaM4YYnV7+XgqbYewG6trvn3YPVam2BxaDy5Nvl2ZIxaTR9Wdih Qfsp+iudUUjuFhSuNEUVL5mYu0ONRuVnWhhHeSP/KXE/+TEFWAIoAY3JIQl/A8fYysPAqi X7NqJvTTpZuKUbr4B/chuJ7Yw0+FrWFvRFgRbnRPLFj7CbdtB/Mfu4Z4B1pGiQ== Message-ID: <85988d3d-2099-ee38-ca5d-b8fcc55dc88c@elenq.tech> Date: Sat, 18 Nov 2023 17:52:48 +0100 MIME-Version: 1.0 From: Ekaitz Zarraga Content-Language: en-US, es-ES, eu 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 Hi, Following Efraim's suggestion I arranged a new patch around the tuning option. I needed to patch Zig itself to use baseline cpu by default, which is safer in general for us. If anyone need a more specific cpu, can use the tuning option to choose it. Maybe I should split the changes in Zig and the tuning system, but if I do they wont appear together, and they mostly only make sense if applied at once. Please let me know if you like this one better. Hope it's cool. Cheers, Ekaitz From 03616b9764278e05d74f8e8bf5d65b043603a437 Mon Sep 17 00:00:00 2001 Message-ID: <03616b9764278e05d74f8e8bf5d65b043603a437.1700325640.git.ekaitz@elenq.tech> From: Ekaitz Zarraga Date: Sat, 18 Nov 2023 17:29:07 +0100 Subject: [PATCH] gnu: zig: Make compiler tunable. In order to make Zig tunable, we have to make sure by default it does the right thing, that is use the `baseline` CPU instead of the `native` one because the tuning system only adds an extra flag to the compiler command line execution. * gnu/packages/patches/zig-use-baseline-cpu-by-default.patch: Add file. * gnu/packages/zig.scm(zig-0.10.1): Apply patch above. * guix/transformations.scm(tuning-compiler): Add support for zig. Change-Id: I40bd28071c97c0dd0a907c704072b52b26d2de28 --- .../zig-use-baseline-cpu-by-default.patch | 36 +++++++++++++++++++ gnu/packages/zig.scm | 3 +- guix/transformations.scm | 22 ++++++++---- 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 gnu/packages/patches/zig-use-baseline-cpu-by-default.patch diff --git a/gnu/packages/patches/zig-use-baseline-cpu-by-default.patch b/gnu/packages/patches/zig-use-baseline-cpu-by-default.patch new file mode 100644 index 0000000000..be78d9c6c7 --- /dev/null +++ b/gnu/packages/patches/zig-use-baseline-cpu-by-default.patch @@ -0,0 +1,36 @@ +From 1dc188129950031243c5a0c80ec2562fab8ec549 Mon Sep 17 00:00:00 2001 +From: Ekaitz Zarraga +Date: Sat, 18 Nov 2023 15:04:16 +0100 +Subject: [PATCH] Use `baseline` cpu by default. + +This helps Guix tune the package later. Tunning will only add +`-Dcpu=whatever` which should override the standard behaviour. + +Zig by default uses `native`, which interferes with our build process. +In our previous zig-build-system we chose to add `-Dcpu=baseline` flag +in each `zig build` execution, but that doesn't allow us to tune the +package later. Tunning is only designed to add extra flags in the +command line call, and we already had one set for the baseline case. +With this patch we set the standard behavior to `baseline` so we don't +need to add the `-Dcpu=baseline` flag in the zig-build-system and we can +tune with no issues. +--- + lib/std/zig/CrossTarget.zig | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/std/zig/CrossTarget.zig b/lib/std/zig/CrossTarget.zig +index 6c59a4a3a..f5ec065fe 100644 +--- a/lib/std/zig/CrossTarget.zig ++++ b/lib/std/zig/CrossTarget.zig +@@ -12,7 +12,7 @@ const mem = std.mem; + /// `null` means native. + cpu_arch: ?Target.Cpu.Arch = null, + +-cpu_model: CpuModel = CpuModel.determined_by_cpu_arch, ++cpu_model: CpuModel = CpuModel.baseline, + + /// Sparse set of CPU features to add to the set from `cpu_model`. + cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, +-- +2.41.0 + diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm index dcca9a1121..82b83f44c2 100644 --- a/gnu/packages/zig.scm +++ b/gnu/packages/zig.scm @@ -42,7 +42,8 @@ (define-public zig-0.10 (file-name (git-file-name name version)) (sha256 (base32 "1sh5xjsksl52i4cfv1qj36sz5h0ln7cq4pdhgs3960mk8a90im7b")) - (patches (search-patches "zig-do-not-link-against-librt.patch")))) + (patches (search-patches "zig-do-not-link-against-librt.patch" + "zig-use-Dcpu-baseline-by-default.patch")))) (build-system cmake-build-system) (inputs (list clang-15 ; Clang propagates llvm. diff --git a/guix/transformations.scm b/guix/transformations.scm index 9cba6bedab..8964feb046 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -439,7 +439,8 @@ (define tuning-compiler actual compiler." (define wrapper #~(begin - (use-modules (ice-9 match)) + (use-modules (ice-9 match) + (ice-9 string-fun)) (define psabi #$(gcc-architecture->micro-architecture-level micro-architecture)) @@ -486,11 +487,20 @@ (define tuning-compiler (apply execl next (append (cons next arguments) - (if (and (search-next "go") + (cond + ((and (search-next "go") (string=? next (search-next "go"))) - '() - (list (string-append "-march=" - #$micro-architecture))))))))))) + '()) + ((and (search-next "zig") + (string=? next (search-next "zig")) + (list (string-append + ;; https://issues.guix.gnu.org/67075#3 + "-Dcpu=" + (string-replace-substring + #$micro-architecture "-" "_"))))) + (else + (list (string-append "-march=" + #$micro-architecture)))))))))))) (define program (program-file (string-append "tuning-compiler-wrapper-" micro-architecture) @@ -508,7 +518,7 @@ (define tuning-compiler (symlink #$program (string-append bin "/" program))) '("cc" "gcc" "clang" "g++" "c++" "clang++" - "go"))))))) + "go" "zig"))))))) (define (build-system-with-tuning-compiler bs micro-architecture) "Return a variant of BS, a build system, that ensures that the compiler that base-commit: a514973413dc8179100ef8f0fcf41f5ac38c982f -- 2.41.0