Bug 274202 - devel/wasmer: Try to fix aarch64 build issues
Summary: devel/wasmer: Try to fix aarch64 build issues
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Robert Clausecker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-01 18:59 UTC by Krešimir Jozić
Modified: 2023-10-04 20:08 UTC (History)
1 user (show)

See Also:
fuz: merge-quarterly?


Attachments
Try to fix aarch64 build issues (3.07 KB, patch)
2023-10-01 18:59 UTC, Krešimir Jozić
kjozic: maintainer-approval-
Details | Diff
Builds on rpi4 (3.11 KB, patch)
2023-10-02 20:35 UTC, Krešimir Jozić
kjozic: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Krešimir Jozić 2023-10-01 18:59:31 UTC
Created attachment 245359 [details]
Try to fix aarch64 build issues
Comment 1 Robert Clausecker freebsd_committer freebsd_triage 2023-10-01 23:06:43 UTC
Thank you for having a look at this.

riscv64 seems to be supported by the project, it's merely broken on FreeBSD right now.  Why did you remove the BROKEN_riscv64 line?

Unfortunately your patch does not fix the build.  It now fails with this error message on arm64 FreeBSD 13.2:

  --> lib/vm/src/trap/traphandlers.rs:63:25         
   |                                                                                                                   
63 |       uc_link: *mut libc::ucontext_t,
   |                           ^^^^^^^^^^ help: a struct with a similar name exists: `mcontext_t`
   |           
  ::: /wrkdirs/usr/ports/devel/wasmer/work/wasmer-4.2.1/cargo-crates/libc-0.2.148/src/unix/bsd/freebsdlike/freebsd/aarch64.rs:9:1
   |
9  | / s_no_extra_traits! {
10 | |     pub struct gpregs {          
11 | |         pub gp_x: [::register_t; 30],                                                                           
12 | |         pub gp_lr: ::register_t,
...  |                                                                                                                 
33 | |     }                                       
34 | | }                                                                                                               
   | |_- similarly named struct `mcontext_t` defined here                                                              

error[E0425]: cannot find value `pc` in this scope                                                                     
   --> lib/vm/src/trap/traphandlers.rs:451:60
    |
451 |                     context.uc_mcontext.mc_gpregs.gp_elr = pc as libc::register_t;
    |                                                            ^^ not found in this scope
                                                                                                                       
error[E0425]: cannot find value `sp` in this scope                                                                     
   --> lib/vm/src/trap/traphandlers.rs:452:59
    |                                                                                                                  
452 |                     context.uc_mcontext.mc_gpregs.gp_sp = sp as libc::register_t;
    |                                                           ^^ not found in this scope

error[E0425]: cannot find value `x0` in this scope
   --> lib/vm/src/trap/traphandlers.rs:453:61
    |
453 |                     context.uc_mcontext.mc_gpregs.gp_x[0] = x0 as libc::register_t;
    |                                                             ^^ not found in this scope

error[E0425]: cannot find value `x1` in this scope
   --> lib/vm/src/trap/traphandlers.rs:454:61
    |
454 |                     context.uc_mcontext.mc_gpregs.gp_x[1] = x1 as libc::register_t;
    |                                                             ^^ not found in this scope

error[E0425]: cannot find value `x29` in this scope
   --> lib/vm/src/trap/traphandlers.rs:455:62
    |
455 |                     context.uc_mcontext.mc_gpregs.gp_x[29] = x29 as libc::register_t;
    |                                                              ^^^ not found in this scope

error[E0425]: cannot find value `lr` in this scope
   --> lib/vm/src/trap/traphandlers.rs:456:62
    |
456 |                     context.uc_mcontext.mc_gpregs.gp_x[30] = lr as libc::register_t;
    |                                                              ^^ not found in this scope

Please check and resubmit as appropriate.
Comment 2 Krešimir Jozić 2023-10-02 04:28:40 UTC
In /lib/vm/src/trap/traphandlers.rs only x86_64, x86 and aarch64 are mentioned in combination with FreeBSD, so I am not sure that riscv64 is supported.

Compile issue is linked with Rust libc implementation which is not 100% complete. Wasmer project did some patches for macOS so I tried to do it in a similar manner for FreeBSD.

Unfortunately, poudriere doesn't work well with rust under qemu simulation so I can't test the patch before I submit it.

I'll investigate further.
Comment 3 Robert Clausecker freebsd_committer freebsd_triage 2023-10-02 04:31:03 UTC
(In reply to Krešimir Jozić from comment #2)

Very unfortunate.  I'll note that riscv64 is not supported.  But perhaps it can be made to work in the future.

QEMU indeed doesn't work right for Rust ports.  I recommend testing on a native arm64 system if possible.  You can e.g. run FreeBSD on a Raspberry Pi 4.  I used to do this for ports development until last year, when I switched to a Microsoft 2023 Dev Kit.
Comment 4 Krešimir Jozić 2023-10-02 20:35:26 UTC
Created attachment 245392 [details]
Builds on rpi4
Comment 5 Krešimir Jozić 2023-10-02 20:38:42 UTC
(In reply to Robert Clausecker from comment #3)

New patch builds on Raspberry Pi 4.
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-10-04 20:04:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5631aa7d069993d7be49c516eaec772630437436

commit 5631aa7d069993d7be49c516eaec772630437436
Author:     Kresimir Jozic <kjozic@gmail.com>
AuthorDate: 2023-10-02 20:28:14 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-10-04 19:59:57 +0000

    devel/wasmer: fix build on aarch64

    Handle differences between ucontext_t and mcontext_t
    pertaining to aarch64 FreeBSD.

    PR:             274202

 devel/wasmer/Makefile                              |  7 ++---
 .../patch-lib_vm_src_trap_traphandlers.rs (new)    | 35 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)