Skip to content
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

Is it possible to cross compile for a custom target? #66

Open
sbellem opened this issue Feb 17, 2022 · 1 comment
Open

Is it possible to cross compile for a custom target? #66

sbellem opened this issue Feb 17, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@sbellem
Copy link

sbellem commented Feb 17, 2022

Hi, wondering if it's possible to specify a target that is custom, similar to what is mentioned in https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#cross-compilation-cross-compilation:

To pass a completely custom target, define stdenv.hostPlatform.rustc.config with its name, and stdenv.hostPlatform.rustc.platform with the value. The value will be serialized to JSON in a file called ${stdenv.hostPlatform.rustc.config}.json, and the path of that file will be used instead.

For example:

import <nixpkgs> {
  crossSystem = (import <nixpkgs/lib>).systems.examples.armhf-embedded // {
    rustc.config = "thumb-crazy";
    rustc.platform = { foo = ""; bar = ""; };
  };

will result in:

--target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""}

In case that can help, the target I'm interested in is x86_64-fortanix-unknown-sgx

"x86_64-fortanix-unknown-sgx": {

@figsoda figsoda added the enhancement New feature or request label Aug 3, 2022
@figsoda
Copy link
Member

figsoda commented Aug 5, 2022

I'm ot familiar with nixpkgs's cross compiling, but this compiles

this is based on example "cross compiling with naersk", a different linker didn't seem to be needed when im on x86_64-unknown-linux so I removed the change

{
  inputs = {
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    flake-utils.url = "github:numtide/flake-utils";
    naersk = {
      url = "github:nmattia/naersk";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = { self, fenix, flake-utils, naersk, nixpkgs }:
    flake-utils.lib.eachDefaultSystem (system: {
      defaultPackage =
        let
          pkgs = nixpkgs.legacyPackages.${system};
          target = "x86_64-fortanix-unknown-sgx";
          toolchain = with fenix.packages.${system};
            combine [
              minimal.rustc
              minimal.cargo
              targets.${target}.latest.rust-std
            ];
        in
        (naersk.lib.${system}.override {
          cargo = toolchain;
          rustc = toolchain;
        }).buildPackage {
          src = ./.;
          CARGO_BUILD_TARGET = target;
        };
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@sbellem @figsoda and others