Nix: source code filtering

This commit is contained in:
Emery Hemingway 2020-01-13 11:12:36 +01:00
parent 955e95272c
commit b8e25c82da
23 changed files with 68 additions and 82 deletions

View File

@ -13,11 +13,11 @@ DEV_DIR = $(TUP_CWD)/dev
DEV_LIB_DIR = $(DEV_DIR)/lib
ifdef IS_GCC
include tup-genode/gcc.tup
include Tuprules.gcc
endif
ifdef IS_LLVM
include tup-genode/llvm.tup
include Tuprules.llvm
endif
ifeq ($(TOOLCHAIN_CONFIGURED),)

View File

@ -24,9 +24,6 @@ let
nixpkgs'.stdenvAdapters.overrideCC nixpkgs'.stdenv sourceForgeToolchain;
in assert env.cc.isGNU; env;
src = self.outPath or (builtins.fetchGit ./.);
version = self.lastModified or "unstable";
inherit (stdenvLlvm) lib targetPlatform;
specs = with targetPlatform;
[ ]
@ -123,7 +120,6 @@ let
IS_GCC = "";
LINUX_HEADERS = buildPackages.glibc.dev;
VERSION = version;
};
in toTupConfig stdenvGcc (f stdenvGcc);
@ -148,16 +144,17 @@ let
llvmPackages.libunwind.override { isBaremetal = true; };
LIBUNWIND = llvmPackages.libunwind;
LINUX_HEADERS = buildPackages.glibc.dev;
VERSION = version;
};
in toTupConfig stdenvLlvm (f stdenvLlvm);
buildRepo = { env, repo, repoInputs }:
buildRepo = { env, repo, repoInputs, filter }:
let
in env.mkDerivation {
pname = "genode-" + repo;
inherit src repo specs version;
name = "genode-" + repo;
inherit repo specs;
src = builtins.filterSource filter ./.;
nativeBuildInputs = repoInputs;
# This is wrong, why does pkg-config not collect buildInputs?
@ -233,6 +230,8 @@ let
maintainers = [ maintainers.ehmry ];
};
} // {
version = self.lastModified;
};
buildRepo' = { ... }@args: buildRepo ({ env = stdenvGcc; } // args);
@ -240,33 +239,88 @@ let
#builtins.throw "create the tup config file in the stdenv environment, replacing CC/CXX with environmental variables"
in rec {
packages = rec {
packages = let
hasPrefix = pre:
with builtins;
let
pre' = "${toString ./.}/${pre}";
preLen = stringLength pre';
in path:
let pathLen = stringLength path;
in substring 0 preLen path == substring 0 pathLen pre';
hasSuffix = suf:
with builtins;
let sufLen = stringLength suf;
in path:
let pathLen = stringLength path;
in substring (pathLen - sufLen) pathLen path == suf;
filterBaseRepo = name:
with builtins;
let
match = [
(hasPrefix "Tup")
(hasPrefix "repos/Tup")
(hasPrefix "repos/base/")
(hasPrefix "repos/base-${name}")
];
skip = [
(hasSuffix "/run")
(hasSuffix "/recipes")
(hasSuffix ".gitignore")
];
in path: type: let f = f': f' path; in any f match && !any f skip;
filterRepo = repo:
with builtins;
let
reposDir = toString ./repos;
skip = [
(hasSuffix "/run")
(hasSuffix "/recipes")
(hasSuffix ".gitignore")
];
match = [
(hasPrefix "Tup")
(hasPrefix "repos/Tup")
(hasPrefix "repos/${repo}")
(hasPrefix "repos/base/src/ld")
];
in path: type: let f = f': f' path; in any f match && !any f skip;
in rec {
NOVA = nixpkgs.callPackage ./NOVA { };
base = buildRepo' {
repo = "base";
repoInputs = [ ];
filter = filterBaseRepo "-";
};
base-linux = buildRepo' {
repo = "base-linux";
repoInputs = [ base ];
filter = filterBaseRepo "linux";
};
base-nova = buildRepo' {
repo = "base-nova";
repoInputs = [ base ];
filter = filterBaseRepo "nova";
};
os = buildRepo' {
repo = "os";
repoInputs = [ base ];
filter = filterRepo "os";
};
gems = buildRepo' {
repo = "gems";
repoInputs = [ base os ];
filter = filterRepo "gems";
};
inherit stdenvGcc stdenvLlvm tupConfigGcc tupConfigLlvm;

View File

@ -1,6 +1,6 @@
#! /bin/sh
set -e
nix build .#packages.x86_64-linux-x86_64-genode.tupConfigGcc -o tup.config
nix build .#packages.x86_64-linux-x86_64-genode.tupConfigGcc -o build-gcc/tup.config
export SHELL=bash
exec nix dev-shell

View File

@ -26,7 +26,7 @@ endif
LDFLAGS += -z max-page-size=0x1000
LDFLAGS += -T$(BASE_DIR)/src/ld/genode_rel.ld
LDFLAGS += -L$(DEV_DIR)/lib
PKG_LIBS = -L$(DEV_DIR)/lib `$(PKG_CONFIG) --libs alarm cxx ldso-startup timeout`
: {obj} | \
$(DEV_DIR)/<lib> \
@ -35,7 +35,7 @@ LDFLAGS += -L$(DEV_DIR)/lib
$(REP_DIR)/<base-nova> \
$(REP_DIR)/<startup> \
symbol.map \
|> $(LD) -o %o $(LD_MARCH) $(LDFLAGS) --whole-archive --start-group -l:alarm.a %<base-common> %<base-nova> -l:cxx.a %<startup> -l:timeout.a %f --end-group --no-whole-archive $(LIBGCC) \
|> $(LD) -o %o $(LD_MARCH) $(LDFLAGS) --whole-archive --start-group $(PKG_LIBS) %<base-common> %<base-nova> %<startup> %f --end-group --no-whole-archive $(LIBGCC) \
|> ld-nova.lib.so $(REP_DIR)/<ld> {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>

View File

@ -1,4 +0,0 @@
include_rules
: foreach *.cc |> !cxx |> %B.o {obj}
: {obj} | |> !prg |> test-%d {bin}
: {bin} |> !collect_bin |>