New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross-compilers should be supported better/more available #24899

Closed
nagisa opened this Issue Apr 14, 2017 · 7 comments

Comments

Projects
None yet
3 participants
@nagisa

nagisa commented Apr 14, 2017

Currently there’s close to none support for crosscompilation from nixos. It is very inconvenient.

I feel like Nix has a lot of potential here. Adding cross-compilers could be as simple as:

let myCrossTargets =  ["x86_64-pc-windows-gnu" "mips-unknown-linux-gnu" ...] in
  pkgs = { 
    gcc.crossTargets = myCrossTargets;
    rustNightly.rustc.crossTargets = myCrossTargets;
    clang.crossTargets = myCrossTargets;
    etc etc
  };

especially painful are the gcc crosscompilation toolchains, so if nix supported this use-case, it would be hella awesome.

@vcunat

This comment has been minimized.

Show comment
Hide comment
@vcunat

vcunat Apr 14, 2017

Member

I don't think it's too bad, really. Some targets work a bit, even if it's not that well documented. In my experience it's often about finding patches to individual packages to make them cross-compile, and I think there's still very few nixpkgs users/contributors of cross-compiling stuff. We do CI of a few examples: http://hydra.nixos.org/jobset/nixpkgs/cross-trunk#tabs-jobs

Member

vcunat commented Apr 14, 2017

I don't think it's too bad, really. Some targets work a bit, even if it's not that well documented. In my experience it's often about finding patches to individual packages to make them cross-compile, and I think there's still very few nixpkgs users/contributors of cross-compiling stuff. We do CI of a few examples: http://hydra.nixos.org/jobset/nixpkgs/cross-trunk#tabs-jobs

@nagisa

This comment has been minimized.

Show comment
Hide comment
@nagisa

nagisa Apr 14, 2017

@vcunat maybe you’re misunderstanding? I want cross compilers to be available, not cross-compiled packages or cross-compilation of packages themselves.

nagisa commented Apr 14, 2017

@vcunat maybe you’re misunderstanding? I want cross compilers to be available, not cross-compiled packages or cross-compilation of packages themselves.

@nagisa nagisa changed the title from cross-compilation should be supported better to cross-compilers should be supported better/more available Apr 14, 2017

@vcunat

This comment has been minimized.

Show comment
Hide comment
@vcunat

vcunat Apr 14, 2017

Member

Well, the toolchain is the first thing you need for each cross-platform. When you have that, you just "evaluate all packages with it", though most packages won't compile without changing their expressions. I think all I've written applies to compilers as well.

Member

vcunat commented Apr 14, 2017

Well, the toolchain is the first thing you need for each cross-platform. When you have that, you just "evaluate all packages with it", though most packages won't compile without changing their expressions. I think all I've written applies to compilers as well.

@nagisa

This comment has been minimized.

Show comment
Hide comment
@nagisa

nagisa May 2, 2017

So, turns out cross-compilers (C ones, at least) are pretty easy to make by doing something like this:

let
  pkgs = import <nixpkgs> {
    config = {
      packageOverrides = super: {
        gcc = super.gcc6;
      };
    };
    crossSystem = rec {
      config = "powerpc64-linux-gnu";
      bigEndian = true;
      arch = "powerpc64";
      float = "hard";
      withTLS = true;
      libc = "glibc";
      platform = {
        kernelMajor = "2.6";
        kernelArch = "powerpc";
        kernelHeadersBaseConfig = "pseries_defconfig";
        kernelBaseConfig = "pseries_defconfig";
        gcc = {
          cpu_64 = "power8";
          cpu_32 = "power8";
        };
      };
      openssl.system = "linux-generic32";
      inherit (platform) gcc;
    };
  };
in pkgs.stdenv.mkDerivation {
  name = "shell";
}

This could at least be documented better.

nagisa commented May 2, 2017

So, turns out cross-compilers (C ones, at least) are pretty easy to make by doing something like this:

let
  pkgs = import <nixpkgs> {
    config = {
      packageOverrides = super: {
        gcc = super.gcc6;
      };
    };
    crossSystem = rec {
      config = "powerpc64-linux-gnu";
      bigEndian = true;
      arch = "powerpc64";
      float = "hard";
      withTLS = true;
      libc = "glibc";
      platform = {
        kernelMajor = "2.6";
        kernelArch = "powerpc";
        kernelHeadersBaseConfig = "pseries_defconfig";
        kernelBaseConfig = "pseries_defconfig";
        gcc = {
          cpu_64 = "power8";
          cpu_32 = "power8";
        };
      };
      openssl.system = "linux-generic32";
      inherit (platform) gcc;
    };
  };
in pkgs.stdenv.mkDerivation {
  name = "shell";
}

This could at least be documented better.

@Ericson2314

This comment has been minimized.

Show comment
Hide comment
@Ericson2314

Ericson2314 May 18, 2017

Member

@nagisa I've been doing a ton of work on cross compilation lately. I've also tried to document things in a new cross compilation section of the manual. I would like rust to eventually leverage this (mozilla/nixpkgs-mozilla#26 for example). Any feedback would be much appreciated.

I do agree that being able to get some tools without reevaluating all of nixpkgs would be nice, but not sure how to support both ideoms well without greatly complicating things. Turning targetPlatform into targetPlatforms might move things in the right direction.

Member

Ericson2314 commented May 18, 2017

@nagisa I've been doing a ton of work on cross compilation lately. I've also tried to document things in a new cross compilation section of the manual. I would like rust to eventually leverage this (mozilla/nixpkgs-mozilla#26 for example). Any feedback would be much appreciated.

I do agree that being able to get some tools without reevaluating all of nixpkgs would be nice, but not sure how to support both ideoms well without greatly complicating things. Turning targetPlatform into targetPlatforms might move things in the right direction.

@nagisa

This comment has been minimized.

Show comment
Hide comment
@nagisa

nagisa May 18, 2017

@Ericson2314 My greatest problem with the two ways to get crosscompilers in nixos (expression above, AFAICT, is the legacy method) lies within the lack of examples, rather than documentation of the primitives.

It took me a long while to get the expression above going, and even then I could not make it work alongside the rust compiler. Getting a rust with both host libraries and target libraries into the expression above would strip the host libraries (no matter what I did), breaking them in the process and by extension breaking compilation of libraries that depend on build scripts.

I would gladly try the alternatives, but I do not want to spend hours fiddling with nix either.

nagisa commented May 18, 2017

@Ericson2314 My greatest problem with the two ways to get crosscompilers in nixos (expression above, AFAICT, is the legacy method) lies within the lack of examples, rather than documentation of the primitives.

It took me a long while to get the expression above going, and even then I could not make it work alongside the rust compiler. Getting a rust with both host libraries and target libraries into the expression above would strip the host libraries (no matter what I did), breaking them in the process and by extension breaking compilation of libraries that depend on build scripts.

I would gladly try the alternatives, but I do not want to spend hours fiddling with nix either.

@Ericson2314

This comment has been minimized.

Show comment
Hide comment
@Ericson2314

Ericson2314 Aug 20, 2018

Member

The new pkgsCross short-hand should make this stuff easy enough to stumble upon. CC @matthewbauer

Member

Ericson2314 commented Aug 20, 2018

The new pkgsCross short-hand should make this stuff easy enough to stumble upon. CC @matthewbauer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment