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,18 +7,22 @@
}; };
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
# 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;}); abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;});
yosys = pkgs.clangStdenv.mkDerivation { yosys = pkgs.clangStdenv.mkDerivation {
name = "yosys"; pname = "yosys";
src = ./. ; version = "0.23";
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream llvmPackages.bintools ]; src = ./.;
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-config llvmPackages.bintools ];
checkInputs = with pkgs; [ gtest ]; checkInputs = with pkgs; [ gtest ];
propagatedBuildInputs = [ abc-verifier ]; propagatedBuildInputs = [ abc-verifier ];
preConfigure = "make config-clang"; preConfigure = "make config-clang";
@ -28,20 +32,35 @@
ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc
''; '';
buildPhase = '' buildPhase = ''
make -j$(nproc) ABCEXTERNAL=yosys-abc make -j$NIX_BUILD_CORES 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;
defaultPackage = yosys; # Function to build for a specific system
devShell = pkgs.mkShell { buildForSystem = targetSystem:
buildInputs = with pkgs; [ clang llvmPackages.bintools bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ]; 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";
}; };
} }
); );