Cross Compiling: Difference between revisions

imported>Symphorien
add snippet using lib.systems.example
imported>Danbst
lazy cross compiling
Line 54: Line 54:
</syntaxhighlight>
</syntaxhighlight>
See also {{issue|49526}}.
See also {{issue|49526}}.
== Lazy cross-compiling ==
If you target "aarch64-unknown-linux-gnu", there is a nice way to reduce amount of cross-compiling and side-step journey to fix cross errors. The idea is to fetch non-essential dependencies from binary cache of regular aarch64 binaries.
Say we are building SDL2.
<syntaxhighlight lang="nix">
let
    # this will use aarch64 binaries from binary cache, so no need to build those
    pkgsArm = import <nixpkgs> {
        config = {};
        overlays = [];
        system = "aarch64-linux";
    };
    # these will be your cross packages
    pkgsCross = import <nixpkgs> {
      overlays = [(self: super: {
        # we want to hack on SDL, don't want to hack on those. Some even don't cross-compile
        inherit (pkgsArm)
          xorg libpulseaudio libGL guile systemd libxkbcommon
        ;
      })];
      crossSystem = {
        config = "aarch64-unknown-linux-gnu";
      };
    };
in pkgsCross.SDL2.override {
      # those shouldn't be neither pkgsCross, nor pkgsArm
      # because those trigger
      #    cannot execute binary file: Exec format error
      # in this case it was enough to just use buildPackages variants
      # but in general there may be problems
      inherit (pkgsCross.buildPackages)
        wayland wayland-protocols
      ;
  }
</syntaxhighlight>


== How to specify dependencies ==
== How to specify dependencies ==