fenix
fenix copied to clipboard
Is it possible to cross compile for a custom target?
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, andstdenv.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
https://github.com/nix-community/fenix/blob/1a1694cb7ae3708a90932e7a8a9a767c466a2976/data/nightly.json#L1693
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;
};
});
}