From 6a3089c1aaf8734b2d45d92ba84246f110ff8868 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Sun, 18 Aug 2024 18:44:04 +0200 Subject: [PATCH] WIP cross compile --- flake.nix | 89 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/flake.nix b/flake.nix index 90fa5328c..aa355e797 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A nix flake for the Yosys synthesis suite"; + description = "A nix flake for the Yosys synthesis suite with cross-compilation support"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -7,42 +7,61 @@ }; outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: + flake-utils.lib.eachSystem [ + flake-utils.lib.system.x86_64-linux + flake-utils.lib.system.aarch64-linux + flake-utils.lib.system.x86_64-darwin + flake-utils.lib.system.aarch64-darwin + ] (system: let - pkgs = import nixpkgs { - inherit system; - }; - # TODO: don't override src when ./abc is empty - # which happens when the command used is `nix build` and not `nix build ?submodules=1` - abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;}); - yosys = pkgs.clangStdenv.mkDerivation { - name = "yosys"; - src = ./. ; - buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream llvmPackages.bintools ]; - checkInputs = with pkgs; [ gtest ]; - propagatedBuildInputs = [ abc-verifier ]; - preConfigure = "make config-clang"; - checkTarget = "test"; - installPhase = '' - make install PREFIX=$out ABCEXTERNAL=yosys-abc - ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc - ''; - buildPhase = '' - make -j$(nproc) ABCEXTERNAL=yosys-abc - ''; - meta = with pkgs.lib; { - description = "Yosys Open SYnthesis Suite"; - homepage = "https://yosyshq.net/yosys/"; - license = licenses.isc; - maintainers = with maintainers; [ ]; + pkgs = nixpkgs.legacyPackages.${system}; + + build-yosys = (pkgs: rec { + abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;}); + yosys = pkgs.clangStdenv.mkDerivation { + pname = "yosys"; + version = "0.23"; + src = ./.; + buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-config llvmPackages.bintools ]; + checkInputs = with pkgs; [ gtest ]; + propagatedBuildInputs = [ abc-verifier ]; + preConfigure = "make config-clang"; + checkTarget = "test"; + installPhase = '' + make install PREFIX=$out ABCEXTERNAL=yosys-abc + ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc + ''; + buildPhase = '' + make -j$NIX_BUILD_CORES ABCEXTERNAL=yosys-abc + ''; + meta = with pkgs.lib; { + description = "Yosys Open SYnthesis Suite"; + homepage = "https://yosyshq.net/yosys/"; + license = licenses.isc; + maintainers = with maintainers; [ ]; + platforms = platforms.unix; + }; }; - }; - in { - packages.default = yosys; - defaultPackage = yosys; - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ clang llvmPackages.bintools bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ]; + }); + + # Function to build for a specific system + buildForSystem = targetSystem: + let + crossPkgs = import nixpkgs { + inherit system; + crossSystem = nixpkgs.lib.systems.examples.${targetSystem}; + }; + in + (build-yosys crossPkgs).yosys; + + in + { + packages = { + default = (build-yosys pkgs).yosys; + yosys = (build-yosys pkgs).yosys; + yosys-aarch64-linux = buildForSystem "aarch64-multiplatform"; + yosys-aarch64-darwin = buildForSystem "aarch64-darwin"; }; } ); -} +} \ No newline at end of file