2
0
Fork 0
genodepkgs/packages/genodelabs/default.nix

254 lines
7.1 KiB
Nix
Raw Normal View History

# SPDX-License-Identifier: CC0-1.0
{ buildPackages, targetPackages }:
with buildPackages;
let
version = "20.02";
genodeSources = let
platform = targetPackages.targetPlatform;
arch = with platform;
if isx86_64 then
"x86_64"
else
throw "unknown Genode arch for platform ${platform.system}";
toolPrefix = if platform.isx86 then
"genode-x86-"
else
throw "unknown tool prefix for Genode arch ${arch}";
in stdenvNoCC.mkDerivation {
pname = "genode-sources";
inherit version;
src = fetchurl {
url = "https://github.com/genodelabs/genode/archive/${version}.tar.gz";
hash = "sha256-ZY9ND6vDA9u127TAv87uOjPuLzRzBPyp5PzD6iM7uNI=";
};
nativeBuildInputs = [ expect gnumake tcl ];
2020-04-03 19:01:19 +02:00
patches =
[ ./init.xsd.patch ./openssl.patch ./svn-trust-server-cert.patch ];
configurePhase = ''
patchShebangs ./tool
substituteInPlace repos/base/etc/tools.conf \
--replace "/usr/local/genode/tool/19.05/bin/" ""
substituteInPlace tool/check_abi \
--replace "exec nm" "exec ${toolPrefix}nm"
'';
dontBuild = true;
installPhase = "cp -a . $out";
};
toolchain = callPackage ./toolchain.nix { };
stdenv' =
targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain;
platform = stdenv'.targetPlatform;
arch = with platform;
if isx86_64 then
"x86_64"
else
throw "unknown Genode arch for platform ${platform.system}";
preparePort = name:
{ hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", ... }@args:
stdenvNoCC.mkDerivation (args // {
outputHashMode = "recursive";
outputHash = hash;
pname = name;
inherit (genodeSources) version;
GENODE_DIR = genodeSources;
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
VERBOSE = "";
# need to build in verbose mode because errors are hidden
impureEnvVars = stdenv'.lib.fetchers.proxyImpureEnvVars
++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
dontUnpack = true;
dontConfigure = true;
nativeBuildInputs =
2020-04-03 19:01:19 +02:00
[ bison flex gitMinimal glibc glibcLocales wget which ]
++ (args.nativeBuildInputs or [ ]);
2020-04-03 19:01:19 +02:00
buildPhase =
# ignore the port hash, its only for the inputs
''
runHook preBuild
export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
mkdir $CONTRIB_DIR
$GENODE_DIR/tool/ports/prepare_port $pname CHECK_HASH=no
runHook postBuild
'';
installPhase =
# strip non-deterministic and extra artifacts
2020-04-03 19:01:19 +02:00
''
runHook preInstall
chmod -R +w $CONTRIB_DIR/*
find $CONTRIB_DIR/* -name .git -exec rm -rf {} \; || true
find $CONTRIB_DIR/* -name .svn -exec rm -rf {} \; || true
find $CONTRIB_DIR/* -name '*.t?z' -exec rm -rf {} \; || true
find $CONTRIB_DIR/* -name '*.tar.*' -exec rm -rf {} \; || true
mkdir $out
cp -a $CONTRIB_DIR/* $out/
runHook postInstall
'';
});
ports = stdenv.lib.mapAttrs preparePort
(import ./ports.nix { inherit buildPackages; });
buildUpstream = { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ]
, enableParallelBuilding ? true, ... }@extraAttrs:
stdenv'.mkDerivation (extraAttrs // {
pname = name;
inherit (genodeSources) version;
inherit targets enableParallelBuilding;
dontUnpack = true;
GENODE_DIR = genodeSources;
nativeBuildInputs = [ binutils bison flex stdenv.cc tcl which ]
++ nativeBuildInputs;
configurePhase = let
linkPorts = toString
(builtins.map (drv: " ln -sv ${drv}/* $CONTRIB_DIR/;") portInputs);
in ''
runHook preConfigure
export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
export BUILD_DIR=$NIX_BUILD_TOP/build
$GENODE_DIR/tool/create_builddir ${arch}
substituteInPlace build/etc/build.conf \
--replace "#REPOSITORIES" "REPOSITORIES"
mkdir $CONTRIB_DIR; ${linkPorts}
runHook postConfigure
'';
makeFlags = [ "-C build" ] ++ targets;
installPhase = ''
runHook preInstall
find build/bin -name '*.xsd' -delete
find build/bin -follow -type f -exec install -Dt $out '{}' \;
runHook postInstall
'';
});
buildDepot = { name, portInputs ? [ ], nativeBuildInputs ? [ ]
, enableParallelBuilding ? true, ... }@extraAttrs:
stdenv'.mkDerivation (extraAttrs // {
pname = name;
inherit (genodeSources) version;
inherit enableParallelBuilding;
nativeBuildInputs = [ binutils bison flex stdenv.cc tcl which ]
++ nativeBuildInputs;
src = genodeSources;
# The genode source tree must be copied to the build directory
# because the depot tool must modify the source tree as it runs.
configurePhase = let
copyPorts = # wasteful copy
toString
(builtins.map (drv: " cp -r ${drv}/* $CONTRIB_DIR/;") portInputs);
in ''
runHook preConfigure
export GENODE_DIR=$(pwd)
export CONTRIB_DIR=$GENODE_DIR/contrib
export DEPOT_DIR=$GENODE_DIR/depot
mkdir -p $CONTRIB_DIR; ${copyPorts}
chmod +rwX -R .
runHook postConfigure
'';
makefile = "tool/depot/create";
makeFlags = [
"genodelabs/bin/${arch}/${name}"
# by default the build system will refuse to be useful
"FORCE=1"
"UPDATE_VERSIONS=1"
"VERBOSE="
];
installPhase = ''
runHook preInstall
find depot/genodelabs/bin -type f -exec install -Dt $out {} \;
runHook postInstall
'';
});
buildOverrides = callPackage ./targets.nix { inherit ports; };
specs = with platform;
[ ]
++ lib.optional is32bit "32bit"
++ lib.optional is64bit "64bit"
++ lib.optional isAarch32 "arm"
++ lib.optional isAarch64 "arm_64"
++ lib.optional isRiscV "riscv"
++ lib.optional isx86 "x86"
++ lib.optional isx86_32 "x86_32"
++ lib.optional isx86_64 "x86_64";
genodeBase = buildUpstream {
name = "base";
targets = [ "LIB=vfs" ];
postInstall =
# The actual ld.lib.so is kernel specific
# so ship the stubbed library for linking
''
cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so
mkdir -p $out/include
cp -r --no-preserve=mode \
$GENODE_DIR/repos/base/include/* \
$GENODE_DIR/repos/os/include/* \
$GENODE_DIR/repos/demo/include/* \
$GENODE_DIR/repos/gems/include/* \
$out/include/
for spec in ${toString specs}; do
dir=$out/include/spec/$spec
if [ -d $dir ]; then
cp -r $dir/* $out/include/
fi
done
rm -rf $out/include/spec
cp -r $GENODE_DIR/repos/base/src/ld $out/ld
'';
};
in genodeSources // {
inherit buildUpstream buildDepot ports specs toolchain genodeBase;
make = target:
buildUpstream {
name = builtins.replaceStrings [ "/" ] [ "-" ] target;
targets = [ target ];
};
depot = name:
let attrs = buildOverrides.${name} or { };
in buildDepot ({ inherit name; } // attrs);
}