[PATCH] gnu: zig: make zig build for a baseline cpu

  • Done
  • quality assurance status badge
Details
3 participants
  • Ekaitz Zarraga
  • Ekaitz Zarraga
  • pukkamustard
Owner
unassigned
Submitted by
Ekaitz Zarraga
Severity
normal

Debbugs page

Ekaitz Zarraga wrote 2 years ago
(name . guix-patches@gnu.org)(address . guix-patches@gnu.org)
p6IABBvdY4_SnsvsI-2ozXIgqJMjTtJ3wrf6OqqiC5farcCvbjxUDdiaBYGljH5k4rJ0bWFzrYNUTDkvyNO9KlU2JuVZLzBmehTDpAO3C98=@elenq.tech
This patch fixes a `Illegal instruction` issue when running Zig.
It happens because Zig compiles with optimizations for the current
machine, which may add instructions that are not compatible with
some target machines. This flag makes it build for a baseline cpu.

Tested with:

qemu-x86_64 -cpu Broadwell-v2 /gnu/store/zzi23y4mab8zl58hdd740xz3814vy24w-zig-0.10.1/bin/zig build

And:
qemu-x86_64 -cpu Broadwell-v4 /gnu/store/zzi23y4mab8zl58hdd740xz3814vy24w-zig-0.10.1/bin/zig build

It worked.
It follows what Arch does:
And NixOS:

Hope this helps.
Best,
Ekaitz


---

From 8dbb801ba7df6cc64c003e8f1739117c8dda6a75 Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Fri, 10 Mar 2023 22:52:19 +0100
Subject: [PATCH] gnu: zig: make zig build for a baseline cpu

* gnu/packages/zig.scm(zig-0.10): Add -DZIG_TARGET_MCPU=baseline
configure flag.
---
gnu/packages/zig.scm | 1 +
1 file changed, 1 insertion(+)

Toggle diff (12 lines)
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 5414b5ba6e..2c89343cb1 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -56,6 +56,7 @@ (define-public zig-0.10
'(string-append "-DZIG_TARGET_TRIPLE="
(%current-target-system))
'())
+ (string-append "-DZIG_TARGET_MCPU=baseline")
(string-append "-DZIG_LIB_DIR=" (assoc-ref %outputs "out")
"/lib/zig"))
#:validate-runpath? #f ; TODO: zig binary can't find ld-linux.
--
2.39.1
pukkamustard wrote 2 years ago
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(address . 62105@debbugs.gnu.org)
865yb7k325.fsf@posteo.net
I managed to build Zig with your patch applied. From what I understand
this is a good fix to the issue.

lgtm and thanks!

-pukkamustard


Ekaitz Zarraga <ekaitz@elenq.tech> writes:

Toggle quote (48 lines)
> This patch fixes a `Illegal instruction` issue when running Zig.
> It happens because Zig compiles with optimizations for the current
> machine, which may add instructions that are not compatible with
> some target machines. This flag makes it build for a baseline cpu.
>
> Tested with:
>
> qemu-x86_64 -cpu Broadwell-v2 /gnu/store/zzi23y4mab8zl58hdd740xz3814vy24w-zig-0.10.1/bin/zig build
>
> And:
> qemu-x86_64 -cpu Broadwell-v4 /gnu/store/zzi23y4mab8zl58hdd740xz3814vy24w-zig-0.10.1/bin/zig build
>
> It worked.
> It follows what Arch does:
> https://github.com/archlinux/svntogit-community/blob/31055e6750a5672ebbd85114fe7a93163f8af575/trunk/PKGBUILD#L30
> And NixOS:
> https://github.com/NixOS/nixpkgs/pull/215994/commits/26b9a2f4a1a53e6763aa83590aad0fce5013a458
>
> Hope this helps.
> Best,
> Ekaitz
>
>
> ---
>
> From 8dbb801ba7df6cc64c003e8f1739117c8dda6a75 Mon Sep 17 00:00:00 2001
> From: Ekaitz Zarraga <ekaitz@elenq.tech>
> Date: Fri, 10 Mar 2023 22:52:19 +0100
> Subject: [PATCH] gnu: zig: make zig build for a baseline cpu
>
> * gnu/packages/zig.scm(zig-0.10): Add -DZIG_TARGET_MCPU=baseline
> configure flag.
> ---
> gnu/packages/zig.scm | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> index 5414b5ba6e..2c89343cb1 100644
> --- a/gnu/packages/zig.scm
> +++ b/gnu/packages/zig.scm
> @@ -56,6 +56,7 @@ (define-public zig-0.10
> '(string-append "-DZIG_TARGET_TRIPLE="
> (%current-target-system))
> '())
> + (string-append "-DZIG_TARGET_MCPU=baseline")
> (string-append "-DZIG_LIB_DIR=" (assoc-ref %outputs "out")
> "/lib/zig"))
> #:validate-runpath? #f ; TODO: zig binary can't find ld-linux.
Ekaitz Zarraga wrote 2 years ago
[PATCH v2] gnu: zig: Build against a baseline CPU.
(address . 62105@debbugs.gnu.org)(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)
d2a102e6f684c168fe60d4311efb938579e1c156.camel@elenq.tech
* gnu/packages/zig.scm (zig-0.10)[#:configure-flags]: Add
“-DZIG_TARGET_MCPU=baseline”.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
---
Hi Ekaitz,

Since this patch didn't cleanly apply with ‘git am’, I ran it through
format-patch once again and also edited the commit message.
If CI succeeds, I'll push it as-is on the 19th.

Cheers,
Liliana

gnu/packages/zig.scm | 1 +
1 file changed, 1 insertion(+)

Toggle diff (14 lines)
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 5414b5ba6e..2c89343cb1 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -56,6 +56,7 @@ (define-public zig-0.10
'(string-append "-DZIG_TARGET_TRIPLE="
(%current-target-system))
'())
+ (string-append "-DZIG_TARGET_MCPU=baseline")
(string-append "-DZIG_LIB_DIR=" (assoc-ref %outputs "out")
"/lib/zig"))
#:validate-runpath? #f ; TODO: zig binary can't find ld-linux.
--
2.39.1
Ekaitz Zarraga wrote 2 years ago
(name . Ekaitz Zarraga)(address . liliana.prikler@gmail.com)(address . 62105@debbugs.gnu.org)
irPFFZCXjP-1Xv_cJwwZDkeX0mMvVhzBxwPt4P_Bi_7N5X4d907SY-3Z80x7MzoXPPLgttWLzjhT_lzVemyaf8PZc5moKXTHfnd9U1lsteA=@elenq.tech
Thank you Liliana, and sorry for the inconvenience.



------- Original Message -------
On Friday, March 10th, 2023 at 9:52 PM, Ekaitz Zarraga <liliana.prikler@gmail.com> wrote:


Toggle quote (32 lines)
> * gnu/packages/zig.scm (zig-0.10)[#:configure-flags]: Add
> “-DZIG_TARGET_MCPU=baseline”.
>
> Signed-off-by: Liliana Marie Prikler liliana.prikler@gmail.com
>
> ---
> Hi Ekaitz,
>
> Since this patch didn't cleanly apply with ‘git am’, I ran it through
> format-patch once again and also edited the commit message.
> If CI succeeds, I'll push it as-is on the 19th.
>
> Cheers,
> Liliana
>
> gnu/packages/zig.scm | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> index 5414b5ba6e..2c89343cb1 100644
> --- a/gnu/packages/zig.scm
> +++ b/gnu/packages/zig.scm
> @@ -56,6 +56,7 @@ (define-public zig-0.10
> '(string-append "-DZIG_TARGET_TRIPLE="
> (%current-target-system))
> '())
> + (string-append "-DZIG_TARGET_MCPU=baseline")
> (string-append "-DZIG_LIB_DIR=" (assoc-ref %outputs "out")
> "/lib/zig"))
> #:validate-runpath? #f ; TODO: zig binary can't find ld-linux.
> --
> 2.39.1
Liliana Marie Prikler wrote 2 years ago
(name . Ekaitz Zarraga)(address . ekaitz@elenq.tech)(address . 62105-done@debbugs.gnu.org)
d419e18f738d55b38ed510e649910b627784af90.camel@gmail.com
Am Sonntag, dem 12.03.2023 um 10:01 +0000 schrieb Ekaitz Zarraga:
Toggle quote (1 lines)
> Thank you Liliana, and sorry for the inconvenience.
No problem.

Pushed.
Closed
?
Your comment

This issue is archived.

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

To respond to this issue using the mumi CLI, first switch to it
mumi current 62105
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
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help