Skip to content
Snippets Groups Projects

cross/crossdirect: improve rust handling

Merged Imported Administrator requested to merge rust-improvements into master

I'm suggesting this as a temporary solution for the current issues with cross-compiling Rust programs. Most big Rust projects use proc-macro crates such as serde_derive, which currently make the rustc wrapper fall back to compiling everything in QEMU (resulting in a slow build).

These changes remove the need for the QEMU+rustc fallback in the wrapper. This works because Cargo's cross-compiling logic can be enabled even when using the same target architecture as the host architecture. Cargo will then pass a --target argument to rustc for all crates that are not going to be used on the host. If the library paths are adjusted accordingly, the native rustc will produce correct results with the arguments provided by Cargo, i.e. working native build scripts and macro crates when called without --target.

Please note that this also causes Cargo build scripts to be built for and run on the native architecture, which means that any libraries they require must be present in the native chroot. This might require a change in pmbootstrap such as this one:

--- a/pmb/build/init.py
+++ b/pmb/build/init.py
@@ -108,6 +108,6 @@ def init_compiler(args, depends, cross, arch):
     if cross == "crossdirect":
         cross_pkgs += ["crossdirect"]
         if "rust" in depends or "cargo" in depends:
-            cross_pkgs += ["rust"]
+            cross_pkgs += depends
 
     pmb.chroot.apk.install(args, cross_pkgs)

Merge request reports

Checking pipeline status.

Merged by AdministratorAdministrator 1 year ago (Jul 24, 2023 6:33am UTC)

Loading

Pipeline #207682 passed

Pipeline passed for f0286576 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Administrator added 1 commit · Imported

    added 1 commit

    • 4e367a6a - cross/crossdirect: improve rust handling

    Compare with previous version

    By Affe Null on 2023-07-06T13:41:04

  • Administrator added 1 commit · Imported

    added 1 commit

    • c1756787 - cross/crossdirect: improve rust handling

    Compare with previous version

    By Affe Null on 2023-07-06T13:48:34

  • Administrator marked this merge request as ready · Imported

    marked this merge request as ready

    By Affe Null on 2023-07-07T10:12:27

  • Administrator
  • Administrator
  • Administrator added 14 commits · Imported

    added 14 commits

    Compare with previous version

    By Affe Null on 2023-07-09T09:28:44

  • Administrator resolved all threads · Imported

    resolved all threads

    By Affe Null on 2023-07-09T09:34:54

  • Administrator
  • Administrator
    • Author Owner
      Resolved by Administrator

      @affenull2345, This is so great to see, thanks so much for working on these patches! I'd love to just have crossdirect working properly with rust!

      Please note that this also causes Cargo build scripts to be built for and run on the native architecture, which means that any libraries they require must be present in the native chroot. This might require a change in pmbootstrap such as this one:

      Can you make the pmbootstrap adjustment, and also ensure that the rust related test cases in pmbootstrap still pass / get adjusted to work with this crossdirect change?

      By Oliver Smith on 2023-07-10T06:13:30

    • Author Owner
      Resolved by Administrator

      if you want to: it's probably worth adding a CROSSDIRECT_DEBUG env var, and if it is set, be more verbose in crossdirect so we see which path it takes. We could then set this in the APKBUILDs for debugging.

      maybe like this (untested):

      if [ -n "$CROSSDIRECT_DEBUG" ]; then
      	set -x
      fi

      But adding more debug output could also be done in a separate MR later on.

      By Oliver Smith on 2023-07-10T06:16:48

  • Administrator added 1 commit · Imported

    added 1 commit

    • 0551c6ef - cross/crossdirect: improve rust handling

    Compare with previous version

    By Affe Null on 2023-07-10T11:52:48

  • Administrator mentioned in commit pmbootstrap@122b9000 · Imported

    mentioned in commit pmbootstrap@122b9000

    By Affe Null on 2023-07-13T08:28:21

  • Administrator
  • Administrator added 2 commits · Imported

    added 2 commits

    • 763f75c9 - 1 commit from branch postmarketOS:master
    • abf42a8b - cross/crossdirect: improve rust handling

    Compare with previous version

    By Affe Null on 2023-07-16T10:08:49

  • Administrator added 16 commits · Imported

    added 16 commits

    Compare with previous version

    By Affe Null on 2023-07-16T10:09:52

  • Author Owner

    Thanks again! All feedback has been addressed and no more comments for a week already, so let's merge it! :rocket:

    By Oliver Smith on 2023-07-24T06:31:11

  • Administrator approved this merge request · Imported

    approved this merge request

    By Oliver Smith on 2023-07-24T06:31:11

  • Administrator added 58 commits · Imported

    added 58 commits

    Compare with previous version

    By Oliver Smith on 2023-07-24T06:32:28

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading