feat: apply platform to deps inside submodules

This commit is contained in:
Jake Hamilton 2024-07-04 17:32:59 -07:00
parent b315ae81f6
commit fd9b85f29e
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
6 changed files with 153 additions and 92 deletions

View file

@ -23,7 +23,7 @@ in {
# })) # }))
# .config; # .config;
foundation-gcc = config.packages.foundation.gcc; foundation-gcc = config.packages.foundation.gcc;
# foundation-binutils = config.packages.foundation.binutils; foundation-binutils = config.packages.foundation.binutils;
# foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend { # foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend {
# platform.host = lib.modules.overrides.force "x86_64-linux"; # platform.host = lib.modules.overrides.force "x86_64-linux";
# }; # };

View file

@ -13,6 +13,10 @@ in {
); );
in in
builtins.map (dependency: dependency.package) available; builtins.map (dependency: dependency.package) available;
build = build': host': target':
builtins.mapAttrs
(name: dep: lib'.packages.build dep build' host' target');
}; };
getLatest = alias: let getLatest = alias: let
@ -34,7 +38,13 @@ in {
buildDependencies = build': host': target': buildDependencies = build': host': target':
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
result = lib.modules.run { platform = {
build = lib.modules.overrides.force build;
host = lib.modules.overrides.force host;
target = lib.modules.overrides.force target;
};
withPlatform = lib.modules.run {
modules = modules =
package.__modules__ package.__modules__
++ [ ++ [
@ -44,11 +54,7 @@ in {
config = { config = {
__modules__ = package.__modules__; __modules__ = package.__modules__;
platform = { inherit platform;
build = lib.modules.overrides.force build;
host = lib.modules.overrides.force host;
target = lib.modules.overrides.force target;
};
}; };
} }
) )
@ -58,33 +64,50 @@ in {
# Not all platform information can be effectively handled via submodules. To handle # Not all platform information can be effectively handled via submodules. To handle
# the case where a user copies the resolved config over we need to ensure that # the case where a user copies the resolved config over we need to ensure that
# dependencies are appropriately updated. # dependencies are appropriately updated.
resolved = withDeps =
result.config withPlatform.config
// { // {
deps = { deps = {
build = { build = {
only = buildDependencies build build build package.deps.build.only; only = buildDependencies build build build withPlatform.config.deps.build.only;
build = buildDependencies build build target package.deps.build.build; build = buildDependencies build build target withPlatform.config.deps.build.build;
host = buildDependencies build host target package.deps.build.host; host = buildDependencies build host target withPlatform.config.deps.build.host;
target = buildDependencies build target target package.deps.build.target; target = buildDependencies build target target withPlatform.config.deps.build.target;
}; };
host = { host = {
only = buildDependencies host host host package.deps.host.only; only = buildDependencies host host host withPlatform.config.deps.host.only;
host = buildDependencies host host target package.deps.host.host; host = buildDependencies host host target withPlatform.config.deps.host.host;
target = buildDependencies host target target package.deps.host.target; target = buildDependencies host target target withPlatform.config.deps.host.target;
}; };
target = { target = {
only = buildDependencies target target target package.deps.target.only; only = buildDependencies target target target withPlatform.config.deps.target.only;
target = buildDependencies target target target package.deps.target.target; target = buildDependencies target target target withPlatform.config.deps.target.target;
}; };
}; };
}; };
in withPackage = lib.modules.run {
resolved modules =
// { package.__modules__
package = resolved.builder.build resolved; ++ [
lib'.types.package.children.submodule
(
{config}: {
config = {
__modules__ = package.__modules__;
inherit platform;
deps = lib.modules.overrides.force withDeps.deps;
package = lib.modules.overrides.force (withDeps.builder.build withDeps);
}; };
}
)
];
};
in
withPackage.config;
}; };
}; };
} }

View file

@ -75,13 +75,17 @@ in {
packages = lib.types.attrs.of (lib.types.attrs.of lib'.types.alias); packages = lib.types.attrs.of (lib.types.attrs.of lib'.types.alias);
dependencies = build: host: target: let dependencies = build: host: target: let
initial = lib.types.attrs.any; initial = lib.types.raw;
transform = value: let transform = value: let
package = lib'.packages.resolve value; package = lib'.packages.resolve value;
in in
(builtins.trace "building dependency ${package.name}: build=${build.triple} host=${host.triple} target=${target.triple}") (builtins.trace "building dependency ${package.name}: build=${build.triple} host=${host.triple} target=${target.triple}")
lib'.packages.build package build host target; lib'.packages.build
package
build
host
target;
in in
lib.types.attrs.of (lib.types.coerce initial transform lib'.types.package); lib.types.attrs.of (lib.types.coerce initial transform lib'.types.package);
@ -142,7 +146,79 @@ in {
in in
result.config; result.config;
final = lib.types.attrs.any; final = lib.types.raw;
deps = build: host: target:
lib.types.submodule {
options = {
build = {
only = lib.options.create {
description = "Dependencies which are only used in the build environment.";
type = lib'.types.dependencies build build build;
default.value = {};
};
build = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the build environment.";
type = lib'.types.dependencies build build target;
default.value = {};
};
host = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the host environment.";
type = lib'.types.dependencies build host target;
default.value = {};
# apply = value:
# if value ? b then
# (builtins.trace value.b.platform.build.triple)
# (builtins.trace config.platform.build.triple)
# value
# else
# value;
};
target = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the target environment.";
type = lib'.types.dependencies build target target;
default.value = {};
};
};
host = {
only = lib.options.create {
description = "Dependencies which are only used in the host environment.";
type = lib'.types.dependencies host host host;
default.value = {};
};
host = lib.options.create {
description = "Dependencies which are executed in the host environment.";
type = lib'.types.dependencies host host target;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the host environment which produces code for the target environment.";
type = lib'.types.dependencies host target target;
default.value = {};
};
};
target = {
only = lib.options.create {
description = "Dependencies which are only used in the target environment.";
type = lib'.types.dependencies target target target;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the target environment.";
type = lib'.types.dependencies target target target;
default.value = {};
};
};
};
};
submodule = {config}: let submodule = {config}: let
build = config.platform.build; build = config.platform.build;
@ -278,64 +354,25 @@ in {
default.value = config.builder.build config; default.value = config.builder.build config;
}; };
deps = { deps = lib.options.create {
description = "The dependencies for the package.";
type = deps build host target;
default.value = {};
apply = value: {
build = { build = {
only = lib.options.create { only = lib'.packages.dependencies.build build build build value.build.only;
description = "Dependencies which are only used in the build environment."; build = lib'.packages.dependencies.build build build target value.build.build;
type = lib'.types.dependencies build build build; host = lib'.packages.dependencies.build build host target value.build.host;
default.value = {}; target = lib'.packages.dependencies.build build target target value.build.target;
}; };
build = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the build environment.";
type = lib'.types.dependencies build build target;
default.value = {};
};
host = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the host environment.";
type = lib'.types.dependencies build host target;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the target environment.";
type = lib'.types.dependencies build target target;
default.value = {};
};
};
host = { host = {
only = lib.options.create { only = lib'.packages.dependencies.build host host host value.host.only;
description = "Dependencies which are only used in the host environment."; host = lib'.packages.dependencies.build host host target value.host.host;
type = lib'.types.dependencies host host host; target = lib'.packages.dependencies.build host target target value.host.target;
default.value = {};
}; };
host = lib.options.create {
description = "Dependencies which are executed in the host environment.";
type = lib'.types.dependencies host host target;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the host environment which produces code for the target environment.";
type = lib'.types.dependencies host target target;
default.value = {};
};
};
target = { target = {
only = lib.options.create { only = lib'.packages.dependencies.build target target target value.target.only;
description = "Dependencies which are only used in the target environment."; target = lib'.packages.dependencies.build target target target value.target.target;
type = lib'.types.dependencies target target target;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the target environment.";
type = lib'.types.dependencies target target target;
default.value = {};
}; };
}; };
}; };

View file

@ -25,7 +25,7 @@ in {
phases = { phases = {
install = '' install = ''
echo "a" > $out echo "a with b: ${config.deps.build.host.b.package.system}" > $out
''; '';
}; };
}; };

View file

@ -34,13 +34,13 @@ in {
builder = builders.basic; builder = builders.basic;
# deps = { deps = {
# build = { build = {
# host = { host = {
# inherit (packages.foundation) gcc; inherit (packages.foundation) gcc;
# }; };
# }; };
# }; };
env = { env = {
PATH = lib.paths.bin [ PATH = lib.paths.bin [

View file

@ -3,12 +3,13 @@
lib', lib',
config, config,
options, options,
}: }: {
{
includes = [ includes = [
./gcc ./gcc
./binutils ./binutils
./linux-headers ./linux-headers
./glibc
# ./xz
]; ];
config = { config = {