[PATCH] build: zig-build-system: Add CPU option

  • Done
  • quality assurance status badge
Details
2 participants
  • Efraim Flashner
  • Ekaitz Zarraga
Owner
unassigned
Submitted by
Ekaitz Zarraga
Severity
normal
E
E
Ekaitz Zarraga wrote on 11 Nov 2023 14:09
(name . guix-patches@gnu.org)(address . guix-patches@gnu.org)
WqKhVsnCWxUfZxvdoFcRDtlW88FnHPZ5QqzSVDUYUOipndmdsfAe3XLPXTPookk6OgqJ8bFaOVCOVAlGWOR3-hs4TD-EtBWBlmm_tAvS75s=@elenq.tech
From a647a8ee689022cafef4bab05784b32b1c97bee7 Mon Sep 17 00:00:00 2001
Message-ID: <a647a8ee689022cafef4bab05784b32b1c97bee7.1699708101.git.ekaitz@elenq.tech>
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Sat, 11 Nov 2023 14:05:23 +0100
Subject: [PATCH] build: zig-build-system: Add CPU option

Zig packages are optimized by default, adding `-Dcpu=baseline` to the
build command builds them for an standard cpu that should work in every
machine.

This change sets that by default but also allows users to choose their
cpu by the `#:zig-cpu` argument.

* guix/build-system/zig.scm (build): add zig-cpu
* guix/build/zig-build-system.scm (zig-build) add zig-cpu

Change-Id: Ib4b2124179e7b5492e7c77c64e1f8336832032ea
---
guix/build-system/zig.scm | 2 ++
guix/build/zig-build-system.scm | 2 ++
2 files changed, 4 insertions(+)

Toggle diff (44 lines)
diff --git a/guix/build-system/zig.scm b/guix/build-system/zig.scm
index 16b8a712cc..f90e76104e 100644
--- a/guix/build-system/zig.scm
+++ b/guix/build-system/zig.scm
@@ -47,6 +47,7 @@ (define* (zig-build name inputs
source
(tests? #t)
(test-target #f)
+ (zig-cpu #f)
(zig-build-flags ''())
(zig-test-flags ''())
(zig-release-type #f)
@@ -67,6 +68,7 @@ (define* (zig-build name inputs
#:source #+source
#:system #$system
#:test-target #$test-target
+ #:zig-cpu #$zig-cpu
#:zig-build-flags #$zig-build-flags
#:zig-test-flags #$zig-test-flags
#:zig-release-type #$zig-release-type
diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
index d414ebfb17..99a81314d4 100644
--- a/guix/build/zig-build-system.scm
+++ b/guix/build/zig-build-system.scm
@@ -44,6 +44,7 @@ (define* (set-zig-global-cache-dir #:rest args)
(setenv "ZIG_GLOBAL_CACHE_DIR" global-cache-dir))
(define* (build #:key
+ zig-cpu
zig-build-flags
zig-release-type ;; "safe", "fast" or "small" empty for a
;; debug build"
@@ -59,6 +60,7 @@ (define* (build #:key
,@(if zig-release-type
(list (string-append "-Drelease-" zig-release-type))
'())
+ ,(string-append "-Dcpu=" (or zig-cpu "baseline"))
,@zig-build-flags)))
(format #t "running: ~s~%" call)
(apply invoke call)))

base-commit: af6105afc67a15a491a0a4fd18a28c9f801a0b94
--
2.41.0
E
E
Efraim Flashner wrote on 12 Nov 2023 15:38
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(address . 67075@debbugs.gnu.org)
ZVDjgqABjiAuWaoZ@3900XT
What are the values that the compiler can take for this flag? Also,
this seems like something that can be addressed with the tuning
mechanism, so we can run 'guix build foo --tune' and it'll do The Right
Thing™.

Alternatively, if we do go this route, you still need to update the
documentation.

On Sat, Nov 11, 2023 at 01:09:07PM +0000, Ekaitz Zarraga wrote:
Toggle quote (72 lines)
> From a647a8ee689022cafef4bab05784b32b1c97bee7 Mon Sep 17 00:00:00 2001
> Message-ID: <a647a8ee689022cafef4bab05784b32b1c97bee7.1699708101.git.ekaitz@elenq.tech>
> From: Ekaitz Zarraga <ekaitz@elenq.tech>
> Date: Sat, 11 Nov 2023 14:05:23 +0100
> Subject: [PATCH] build: zig-build-system: Add CPU option
>
> Zig packages are optimized by default, adding `-Dcpu=baseline` to the
> build command builds them for an standard cpu that should work in every
> machine.
>
> This change sets that by default but also allows users to choose their
> cpu by the `#:zig-cpu` argument.
>
> * guix/build-system/zig.scm (build): add zig-cpu
> * guix/build/zig-build-system.scm (zig-build) add zig-cpu
>
> Change-Id: Ib4b2124179e7b5492e7c77c64e1f8336832032ea
> ---
> guix/build-system/zig.scm | 2 ++
> guix/build/zig-build-system.scm | 2 ++
> 2 files changed, 4 insertions(+)
>
> diff --git a/guix/build-system/zig.scm b/guix/build-system/zig.scm
> index 16b8a712cc..f90e76104e 100644
> --- a/guix/build-system/zig.scm
> +++ b/guix/build-system/zig.scm
> @@ -47,6 +47,7 @@ (define* (zig-build name inputs
> source
> (tests? #t)
> (test-target #f)
> + (zig-cpu #f)
> (zig-build-flags ''())
> (zig-test-flags ''())
> (zig-release-type #f)
> @@ -67,6 +68,7 @@ (define* (zig-build name inputs
> #:source #+source
> #:system #$system
> #:test-target #$test-target
> + #:zig-cpu #$zig-cpu
> #:zig-build-flags #$zig-build-flags
> #:zig-test-flags #$zig-test-flags
> #:zig-release-type #$zig-release-type
> diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
> index d414ebfb17..99a81314d4 100644
> --- a/guix/build/zig-build-system.scm
> +++ b/guix/build/zig-build-system.scm
> @@ -44,6 +44,7 @@ (define* (set-zig-global-cache-dir #:rest args)
> (setenv "ZIG_GLOBAL_CACHE_DIR" global-cache-dir))
>
> (define* (build #:key
> + zig-cpu
> zig-build-flags
> zig-release-type ;; "safe", "fast" or "small" empty for a
> ;; debug build"
> @@ -59,6 +60,7 @@ (define* (build #:key
> ,@(if zig-release-type
> (list (string-append "-Drelease-" zig-release-type))
> '())
> + ,(string-append "-Dcpu=" (or zig-cpu "baseline"))
> ,@zig-build-flags)))
> (format #t "running: ~s~%" call)
> (apply invoke call)))
>
> base-commit: af6105afc67a15a491a0a4fd18a28c9f801a0b94
> --
> 2.41.0
>
>
>
>
>

--
Efraim Flashner <efraim@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
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmVQ44IACgkQQarn3Mo9
g1H87w/+LE72UpunFTnaIl6aUxH1CNZDEUEyhslZhxQO4fRcUDc74irHeMEaRZH7
9uMOjJdYWzrz1YcwmlPt6tlevWSyeYmlnITaxUv8kE95363Pe3tA7vb4fDj+sA7B
3eN1sE1aPJ18DoXBZNHCOiBS6qaHrr0RITqMk0IxeTgZVEfaxziE6ZdhiYKMycHg
MkgQqgjHMr+A/5CeY6TKYSqNSWhCFejU417OS41Rw0345zbcRW4R37M3ULgW0Sf4
Mk4XtKSllQOdlW3648J+338M15D8bVkjW+NXlYg9qefglWcWt6bWMgO3SUmhKWku
7yvRglStWGzFIMwUdmemi4+SqDC6/x3fsATWGkhhVZ+flZiA6NUOK2zcDn4pEEup
gjBoRY+dikda5FNn2vqVwF8CHkvqfHz8skuPol7Y7FvJjQn30lX/aRZXN4fqFN4H
cWXNqMbaqXrnS97RlWzhdwXv+fZXwVmu3rXIFbqLEep62o+C2fyYk1EDYbr2s4B2
HqXHwA6u6lyQCJJxUgcEKhZxrGLYPxV7A0q2GktPsnXO6heRCQ/k2r8Gszyjz1oR
GaDUxkA9mKo9DYW/IUjwJCpOJi14ixVkicCZRUddLwG7CeNKSeF0/HF80BIvNrtE
Y0o1xieOPfKBykvqwxE17Y4ob5AN8PACCEmMWv4/qkvl/gNXHQk=
=x2rU
-----END PGP SIGNATURE-----


E
E
Ekaitz Zarraga wrote on 12 Nov 2023 17:38
(name . Efraim Flashner)(address . efraim@flashner.co.il)(address . 67075@debbugs.gnu.org)
9H9-d5-fHPyPl1K4orVOGtBJD1l-IkO3i_PliKpymBR4abn8CwidP7hNlaqafHnHBu54egehC0wYtVc-R4azbkd1sjEMPITj9dbUHl8W6dM=@elenq.tech
Hi Efraim,

On Sunday, November 12th, 2023 at 15:38, Efraim Flashner <efraim@flashner.co.il> wrote:

Toggle quote (5 lines)
> What are the values that the compiler can take for this flag? Also,
> this seems like something that can be addressed with the tuning
> mechanism, so we can run 'guix build foo --tune' and it'll do The Right
> Thing™.

It's not that simple. I talked with Andrew Kelley and he told me the values
are obtained from LLVM and they have some patching. I checked the list and
they are similar to those we use in the -march field:

The full list is accessible in `zig targets` and it's very extensive.

I don't know if we can just rely on that mechanism...

Toggle quote (3 lines)
> Alternatively, if we do go this route, you still need to update the
> documentation.

That's very true. I will.

Toggle quote (75 lines)
> On Sat, Nov 11, 2023 at 01:09:07PM +0000, Ekaitz Zarraga wrote:
>
> > From a647a8ee689022cafef4bab05784b32b1c97bee7 Mon Sep 17 00:00:00 2001
> > Message-ID: a647a8ee689022cafef4bab05784b32b1c97bee7.1699708101.git.ekaitz@elenq.tech
> > From: Ekaitz Zarraga ekaitz@elenq.tech
> > Date: Sat, 11 Nov 2023 14:05:23 +0100
> > Subject: [PATCH] build: zig-build-system: Add CPU option
> >
> > Zig packages are optimized by default, adding `-Dcpu=baseline` to the
> > build command builds them for an standard cpu that should work in every
> > machine.
> >
> > This change sets that by default but also allows users to choose their
> > cpu by the `#:zig-cpu` argument.
> >
> > * guix/build-system/zig.scm (build): add zig-cpu
> > * guix/build/zig-build-system.scm (zig-build) add zig-cpu
> >
> > Change-Id: Ib4b2124179e7b5492e7c77c64e1f8336832032ea
> > ---
> > guix/build-system/zig.scm | 2 ++
> > guix/build/zig-build-system.scm | 2 ++
> > 2 files changed, 4 insertions(+)
> >
> > diff --git a/guix/build-system/zig.scm b/guix/build-system/zig.scm
> > index 16b8a712cc..f90e76104e 100644
> > --- a/guix/build-system/zig.scm
> > +++ b/guix/build-system/zig.scm
> > @@ -47,6 +47,7 @@ (define* (zig-build name inputs
> > source
> > (tests? #t)
> > (test-target #f)
> > + (zig-cpu #f)
> > (zig-build-flags ''())
> > (zig-test-flags ''())
> > (zig-release-type #f)
> > @@ -67,6 +68,7 @@ (define* (zig-build name inputs
> > #:source #+source
> > #:system #$system
> > #:test-target #$test-target
> > + #:zig-cpu #$zig-cpu
> > #:zig-build-flags #$zig-build-flags
> > #:zig-test-flags #$zig-test-flags
> > #:zig-release-type #$zig-release-type
> > diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
> > index d414ebfb17..99a81314d4 100644
> > --- a/guix/build/zig-build-system.scm
> > +++ b/guix/build/zig-build-system.scm
> > @@ -44,6 +44,7 @@ (define* (set-zig-global-cache-dir #:rest args)
> > (setenv "ZIG_GLOBAL_CACHE_DIR" global-cache-dir))
> >
> > (define* (build #:key
> > + zig-cpu
> > zig-build-flags
> > zig-release-type ;; "safe", "fast" or "small" empty for a
> > ;; debug build"
> > @@ -59,6 +60,7 @@ (define* (build #:key
> > ,@(if zig-release-type
> > (list (string-append "-Drelease-" zig-release-type))
> > '())
> > + ,(string-append "-Dcpu=" (or zig-cpu "baseline"))
> > ,@zig-build-flags)))
> > (format #t "running: ~s~%" call)
> > (apply invoke call)))
> >
> > base-commit: af6105afc67a15a491a0a4fd18a28c9f801a0b94
> > --
> > 2.41.0
>
>
> --
> Efraim Flashner efraim@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
E
E
Ekaitz Zarraga wrote on 12 Nov 2023 17:41
(name . Efraim Flashner)(address . efraim@flashner.co.il)(address . 67075@debbugs.gnu.org)
INjlEW0mXjuyv9Qgssgy6_XT6kD88YtADzJbFJVYMpQv6AxY8LsovpTUidxL4yCOIHrj787i04b3pbrbjbVyyY4uUfVdmwtbpV1nbql9WsY=@elenq.tech
Extra information I missed in the previous email:

Toggle quote (2 lines)
> andrewrk: there is close to a 1-1 correspondence. zig uses underscores instead of dashes for naming these

So we can use a translation function from the tuning capabilites we already have and see how it goes.

Cheers
E
E
Ekaitz Zarraga wrote on 18 Nov 2023 17:52
[PATCH] build: zig-build-system: Add CPU option
(address . 67075@debbugs.gnu.org)
85988d3d-2099-ee38-ca5d-b8fcc55dc88c@elenq.tech
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
E
E
Efraim Flashner wrote on 3 Dec 2023 09:09
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(address . 67075-done@debbugs.gnu.org)
ZWw31W3IepgP7Z9m@3900XT
Attachment: file
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmVsN9MACgkQQarn3Mo9
g1FmJg//XYv0thJ4Txr3AlGN8OgfcW3Ov/spWXgNvVavtkDDvSAwcIICfKVKip8C
vlYfr0HjmNAdIvKXpdjFF8BRJTSehYDyqATVHL+nhY3etPcxbaY1Yvmw9WBiFOq3
mHxi+GXscAIARCuoXtJqgLc7ikKWJvc3vHUn7LGaX6PJL88FJhGSyW68QgSKgFIG
Eu2u1+TtxLk1IdyEepPPck8NCX1SHACirKpNxdxGpTB0im3/AlZCOuT+gUVJa4LY
NoQOcn8lZFaYmeW7sbIurpSysBDXUpXHTL1K0W39FDwAd/y0UV1i5QEbwpcsXYSr
fcvUrrW2Bnypo9ZmlJDGH36WJQIKBhJosyUTTa6vMyMd1cmVpyeh+gCBsFQZSZrP
mvNkhA9PLT20xSD5P76CbI9y0Ige7bgBE3EnHOqJeH1lCg8bUpZEXHDu9wiqIEdV
tBhgCHAN/FzsNK5pHYiBksYOUdAkFJgFrtavpopKxvt7ITQ+VH4TxWKxTBhutEYM
R+wK/Tz/5Rc7vGQ3id/+CsW54OqskJWnCjj/TNePUVFmdhiNsbWBXoJhUtNXxoz+
cRKYgNeLCYUWzUgyAvn4Xg1uQJX94BesT31oIiOA9JusRVlv7jGoTFQt7qbcNRly
k6oNatI7yfKLAZudiER1eAIb+6k1sbg3RuWVOaLgD0qC+5UEyts=
=wF2x
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 67075@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 67075
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch