Able to build zephyr toolchains

This commit is contained in:
Artemis Tosini 2023-11-12 01:16:34 +00:00
parent bfd6338ec6
commit cdd6ddad6f
Signed by: artemist
GPG key ID: EE5227935FE3FF18
3 changed files with 58 additions and 13 deletions

View file

@ -1,21 +1,18 @@
{ {
description = "artemist's NixOS packages and shells for development"; description = "artemist's NixOS packages and shells for development";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: outputs = { self, nixpkgs, utils }:
let utils.lib.eachDefaultSystem (system:
pkgs = import nixpkgs { inherit system; }; let pkgs = import nixpkgs { inherit system; };
in in {
{ packages = { zephyr = pkgs.callPackage ./packages/zephyr { }; };
packages = {
zephyr = pkgs.callPackage ./packages/zephyr { };
};
formatter = pkgs.nixfmt; formatter = pkgs.nixfmt;
}); });
} }

View file

@ -1,8 +1,14 @@
{ callPackage, stdenv, lib }: { callPackage, stdenv, lib }:
let assets = lib.importJSON ./assets.json; let assets = lib.importJSON ./assets.json;
in { in rec {
host-tools = callPackage ./host-tools.nix { host-tools = callPackage ./host-tools.nix {
inherit (assets) version hosts; inherit (assets) version hosts;
sources = assets.host_tools; sources = assets.host_tools;
}; };
toolchains = lib.mapAttrs (target: sources:
callPackage ./toolchain.nix {
inherit target sources;
inherit (assets) version hosts;
}) assets.toolchains;
} }

View file

@ -0,0 +1,42 @@
{ stdenv, lib, fetchurl, autoPatchelfHook, target, sources, version, hosts }:
stdenv.mkDerivation {
pname = "zephyr-toolchain-${target}";
inherit version;
src = fetchurl (sources."${stdenv.hostPlatform.system}");
dontConfigure = true;
dontUnpack = true;
dontBuild = true;
# If we're building the same architecture as the target it will mess with files like
# crt1.o, so use autopatchelf and only some files
dontPatchELF = true;
dontAutoPatchelf = true;
nativeBuildInputs = [ autoPatchelfHook ];
autoPatchelfIgnoreMissingDeps = [ "libpython*" ];
installPhase = ''
runHook preInstall
mkdir -p "$out"
tar -C "$out" -xvf "$src"
runHook postInstall
'';
preFixup = ''
autoPatchelf ${target}/bin
autoPatchelf ${target}/${target}/bin
autoPatchelf ${target}/lib/bfd-plugins
autoPatchelf ${target}/lib/gcc/${target}/*/plugin ${target}/libexec/gcc/${target}
echo "done with my autopatchelf"
'';
meta = with lib; {
homepage = "https://www.zephyrproject.org/";
description =
"Toolchain for building Zephyr for the ${target} architecture";
license = licenses.asl20;
platforms = hosts;
maintainers = with maintainers; [ artemist ];
};
}