Skip to content

Commit

Permalink
initial implementation of vc4 cross-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverca22 committed Nov 20, 2019
1 parent 91b02cd commit 4aa1ffa
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rec {
else if final.isAndroid then "bionic"
else if final.isLinux /* default */ then "glibc"
else if final.isMsp430 then "newlib"
else if final.isVc4 then "newlib"
else if final.isAvr then "avrlibc"
else if final.isNetBSD then "nblibc"
# TODO(@Ericson2314) think more about other operating systems
Expand Down
3 changes: 2 additions & 1 deletion lib/systems/doubles.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let

"riscv32-linux" "riscv64-linux"

"aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none"
"aarch64-none" "avr-none" "arm-none" "i686-none" "x86_64-none" "powerpc-none" "msp430-none" "riscv64-none" "riscv32-none" "vc4-none"
];

allParsed = map parse.mkSystemFromString all;
Expand All @@ -45,6 +45,7 @@ in {
x86_64 = filterDoubles predicates.isx86_64;
mips = filterDoubles predicates.isMips;
riscv = filterDoubles predicates.isRiscV;
vc4 = filterDoubles predicates.isVc4;

cygwin = filterDoubles predicates.isCygwin;
darwin = filterDoubles predicates.isDarwin;
Expand Down
6 changes: 6 additions & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ rec {
config = "avr";
};

vc4 = {
config = "vc4-elf";
libc = "newlib";
platform = {};
};

arm-embedded = {
config = "arm-none-eabi";
libc = "newlib";
Expand Down
1 change: 1 addition & 0 deletions lib/systems/inspect.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rec {
isSparc = { cpu = { family = "sparc"; }; };
isWasm = { cpu = { family = "wasm"; }; };
isMsp430 = { cpu = { family = "msp430"; }; };
isVc4 = { cpu = { family = "vc4"; }; };
isAvr = { cpu = { family = "avr"; }; };
isAlpha = { cpu = { family = "alpha"; }; };
isJavaScript = { cpu = cpuTypes.js; };
Expand Down
2 changes: 2 additions & 0 deletions lib/systems/parse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ rec {
msp430 = { bits = 16; significantByte = littleEndian; family = "msp430"; };
avr = { bits = 8; family = "avr"; };

vc4 = { bits = 32; significantByte = littleEndian; family = "vc4"; };

js = { bits = 32; significantByte = littleEndian; family = "js"; };
};

Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ stdenv.mkDerivation {
else if targetPlatform.isMsp430 then "msp430"
else if targetPlatform.isAvr then "avr"
else if targetPlatform.isAlpha then "alpha"
else if targetPlatform.isVc4 then "vc4"
else throw "unknown emulation for platform: ${targetPlatform.config}";
in if targetPlatform.useLLVM or false then ""
else targetPlatform.platform.bfdEmulation or (fmt + sep + arch);
Expand Down
13 changes: 10 additions & 3 deletions pkgs/development/compilers/gcc/6/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
{ stdenv, targetPackages, fetchurl, fetchpatch, fetchFromGitHub, noSysDirs
, langC ? true, langCC ? true, langFortran ? false
, langObjC ? stdenv.targetPlatform.isDarwin
, langObjCpp ? stdenv.targetPlatform.isDarwin
Expand All @@ -9,6 +9,7 @@
, enableShared ? true
, enableLTO ? true
, texinfo ? null
, flex
, perl ? null # optional, for texi2pod (then pod2man); required for Java
, gmp, mpfr, libmpc, gettext, which
, libelf # optional, for link-time optimizations (LTO)
Expand Down Expand Up @@ -107,7 +108,12 @@ stdenv.mkDerivation ({

builder = ../builder.sh;

src = fetchurl {
src = if stdenv.targetPlatform.isVc4 then fetchFromGitHub {
owner = "itszor";
repo = "gcc-vc4";
rev = "e90ff43f9671c760cf0d1dd62f569a0fb9bf8918";
sha256 = "0gxf66hwqk26h8f853sybphqa5ca0cva2kmrw5jsiv6139g0qnp8";
} else fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
sha256 = "0i89fksfp6wr1xg9l8296aslcymv2idn60ip31wr9s4pwin7kwby";
};
Expand Down Expand Up @@ -172,7 +178,8 @@ stdenv.mkDerivation ({
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ texinfo which gettext ]
++ (optional (perl != null) perl)
++ (optional javaAwtGtk pkgconfig);
++ (optional javaAwtGtk pkgconfig)
++ (optional (stdenv.targetPlatform.isVc4) flex);

# For building runtime libs
depsBuildTarget =
Expand Down
28 changes: 28 additions & 0 deletions pkgs/development/misc/vc4/newlib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ stdenv, texinfo, flex, bison, fetchFromGitHub, crossLibcStdenv, buildPackages }:

crossLibcStdenv.mkDerivation {
name = "newlib";
src = fetchFromGitHub {
owner = "itszor";
repo = "newlib-vc4";
rev = "89abe4a5263d216e923fbbc80495743ff269a510";
sha256 = "131r4v0nn68flnqibjcvhsrys3hs89bn0i4vwmrzgjd7v1rbgqav";
};
dontUpdateAutotoolsGnuConfigScripts = true;
configurePlatforms = [ "target" ];
enableParallelBuilding = true;

nativeBuildInputs = [ texinfo flex bison ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
# newlib expects CC to build for build platform, not host platform
preConfigure = ''
export CC=cc
'';

dontStrip = true;

passthru = {
incdir = "/${stdenv.targetPlatform.config}/include";
libdir = "/${stdenv.targetPlatform.config}/lib";
};
}
27 changes: 19 additions & 8 deletions pkgs/development/tools/misc/binutils/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{ stdenv, lib, buildPackages
, fetchurl, zlib, autoreconfHook, gettext
, fetchFromGitHub, fetchurl, zlib, autoreconfHook, gettext
# Enabling all targets increases output size to a multiple.
, withAllTargets ? false, libbfd, libopcodes
, enableShared ? true
, noSysDirs
, gold ? !stdenv.buildPlatform.isDarwin || stdenv.hostPlatform == stdenv.targetPlatform
, bison ? null
, flex
, texinfo
}:

let
Expand All @@ -20,16 +22,23 @@ let
# PATH to both be usable.
targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
"${stdenv.targetPlatform.config}-";
vc4-binutils-src = fetchFromGitHub {
owner = "itszor";
repo = "binutils-vc4";
rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36";
sha256 = "1kdrz6fki55lm15rwwamn74fnqpy0zlafsida2zymk76n3656c63";
};
# HACK to ensure that we preserve source from bootstrap binutils to not rebuild LLVM
normal-src = stdenv.__bootPackages.binutils-unwrapped.src or (fetchurl {
url = "mirror://gnu/binutils/${basename}.tar.bz2";
sha256 = "1l34hn1zkmhr1wcrgf0d4z7r3najxnw3cx2y2fk7v55zjlk3ik7z";
});
in

stdenv.mkDerivation {
name = targetPrefix + basename;

# HACK to ensure that we preserve source from bootstrap binutils to not rebuild LLVM
src = stdenv.__bootPackages.binutils-unwrapped.src or (fetchurl {
url = "mirror://gnu/binutils/${basename}.tar.bz2";
sha256 = "1l34hn1zkmhr1wcrgf0d4z7r3najxnw3cx2y2fk7v55zjlk3ik7z";
});
src = if stdenv.targetPlatform.isVc4 then vc4-binutils-src else normal-src;

patches = [
# Make binutils output deterministic by default.
Expand All @@ -54,6 +63,8 @@ stdenv.mkDerivation {
# cross-compiling.
./always-search-rpath.patch

] ++ lib.optionals (!stdenv.targetPlatform.isVc4)
[
# https://sourceware.org/bugzilla/show_bug.cgi?id=22868
./gold-symbol-visibility.patch

Expand All @@ -69,9 +80,9 @@ stdenv.mkDerivation {
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [
bison
] ++ lib.optionals stdenv.targetPlatform.isiOS [
] ++ (lib.optionals stdenv.targetPlatform.isiOS [
autoreconfHook
];
]) ++ lib.optionals stdenv.targetPlatform.isVc4 [ texinfo flex ];
buildInputs = [ zlib gettext ];

inherit noSysDirs;
Expand Down
18 changes: 18 additions & 0 deletions pkgs/misc/emulators/resim/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ fetchFromGitHub, stdenv, cmake, qt4 }:

stdenv.mkDerivation {
name = "resim";
src = fetchFromGitHub {
owner = "itszor";
repo = "resim";
rev = "cdc7808ceb7ba4ac00d0d08ca646b58615059150";
sha256 = "1743lngqxd7ai4k6cd4d1cf9h60z2pnvr2iynfs1zlpcj3w1hx0c";
};
nativeBuildInputs = [ cmake ];
buildInputs = [ qt4 ];
installPhase = ''
mkdir -pv $out/{lib,bin}
cp -v libresim/libarmsim.so $out/lib/libarmsim.so
cp -v vc4emul/vc4emul $out/bin/vc4emul
'';
}
8 changes: 6 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7765,8 +7765,8 @@ in
gerbil = callPackage ../development/compilers/gerbil { stdenv = gccStdenv; };
gerbil-unstable = callPackage ../development/compilers/gerbil/unstable.nix { stdenv = gccStdenv; };

gccFun = callPackage ../development/compilers/gcc/8;
gcc = gcc8;
gccFun = callPackage (if stdenv.targetPlatform.isVc4 then ../development/compilers/gcc/6 else ../development/compilers/gcc/8);
gcc = if stdenv.targetPlatform.isVc4 then gcc6 else gcc8;
gcc-unwrapped = gcc.cc;

gccStdenv = if stdenv.cc.isGNU then stdenv else stdenv.override {
Expand Down Expand Up @@ -9390,6 +9390,9 @@ in

mspdebug = callPackage ../development/misc/msp430/mspdebug.nix { };

vc4-newlib = callPackage ../development/misc/vc4/newlib.nix {};
resim = callPackage ../misc/emulators/resim {};

rappel = callPackage ../development/misc/rappel/default.nix { };

pharo-vms = callPackage ../development/pharo/vm { };
Expand Down Expand Up @@ -11336,6 +11339,7 @@ in
else if name == "uclibc" then targetPackages.uclibcCross or uclibcCross
else if name == "avrlibc" then targetPackages.avrlibcCross or avrlibcCross
else if name == "newlib" && stdenv.targetPlatform.isMsp430 then targetPackages.msp430NewlibCross or msp430NewlibCross
else if name == "newlib" && stdenv.targetPlatform.isVc4 then targetPackages.vc4-newlib or vc4-newlib
else if name == "newlib" then targetPackages.newlibCross or newlibCross
else if name == "musl" then targetPackages.muslCross or muslCross
else if name == "msvcrt" then targetPackages.windows.mingw_w64 or windows.mingw_w64
Expand Down

0 comments on commit 4aa1ffa

Please sign in to comment.