3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-06 06:03:23 +00:00

WIP cross compile

This commit is contained in:
Emil J. Tywoniak 2024-08-18 18:44:04 +02:00
parent 1eaf4e0790
commit 6a3089c1aa

View file

@ -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 = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@ -7,42 +7,61 @@
}; };
outputs = { self, nixpkgs, flake-utils }: 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 let
pkgs = import nixpkgs { pkgs = nixpkgs.legacyPackages.${system};
inherit system;
}; build-yosys = (pkgs: rec {
# TODO: don't override src when ./abc is empty abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;});
# which happens when the command used is `nix build` and not `nix build ?submodules=1` yosys = pkgs.clangStdenv.mkDerivation {
abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;}); pname = "yosys";
yosys = pkgs.clangStdenv.mkDerivation { version = "0.23";
name = "yosys"; src = ./.;
src = ./. ; buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-config llvmPackages.bintools ];
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream llvmPackages.bintools ]; checkInputs = with pkgs; [ gtest ];
checkInputs = with pkgs; [ gtest ]; propagatedBuildInputs = [ abc-verifier ];
propagatedBuildInputs = [ abc-verifier ]; preConfigure = "make config-clang";
preConfigure = "make config-clang"; checkTarget = "test";
checkTarget = "test"; installPhase = ''
installPhase = '' make install PREFIX=$out ABCEXTERNAL=yosys-abc
make install PREFIX=$out ABCEXTERNAL=yosys-abc ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc
ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc '';
''; buildPhase = ''
buildPhase = '' make -j$NIX_BUILD_CORES ABCEXTERNAL=yosys-abc
make -j$(nproc) ABCEXTERNAL=yosys-abc '';
''; meta = with pkgs.lib; {
meta = with pkgs.lib; { description = "Yosys Open SYnthesis Suite";
description = "Yosys Open SYnthesis Suite"; homepage = "https://yosyshq.net/yosys/";
homepage = "https://yosyshq.net/yosys/"; license = licenses.isc;
license = licenses.isc; maintainers = with maintainers; [ ];
maintainers = with maintainers; [ ]; platforms = platforms.unix;
};
}; };
}; });
in {
packages.default = yosys; # Function to build for a specific system
defaultPackage = yosys; buildForSystem = targetSystem:
devShell = pkgs.mkShell { let
buildInputs = with pkgs; [ clang llvmPackages.bintools bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ]; 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";
}; };
} }
); );
} }