From 330fdc9943c58341b92f3cf515251bf682c92479 Mon Sep 17 00:00:00 2001 From: aleksana Date: Fri, 2 May 2025 13:18:40 +0800 Subject: [PATCH 1/2] lib.systems.architectures: add hasInferior and canExecute function --- lib/systems/architectures.nix | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/lib/systems/architectures.nix b/lib/systems/architectures.nix index 615e5f6af56f..51d3b7a7a5a2 100644 --- a/lib/systems/architectures.nix +++ b/lib/systems/architectures.nix @@ -494,6 +494,70 @@ rec { loongson2f = [ ]; }; + /** + Check whether one GCC architecture has the the other inferior architecture. + + # Inputs + + `arch1` + : GCC architecture in string + + `arch2` + : GCC architecture in string + + # Type + + ``` + hasInferior :: string -> string -> bool + ``` + + # Examples + ::: {.example} + ## `lib.systems.architectures.hasInferior` usage example + + ```nix + hasInferior "x86-64-v3" "x86-64" + => true + hasInferior "x86-64" "x86-64-v3" + => false + hasInferior "x86-64" "x86-64" + => false + ``` + */ + hasInferior = arch1: arch2: inferiors ? ${arch1} && lib.elem arch2 inferiors.${arch1}; + + /** + Check whether one GCC architecture can execute the other. + + # Inputs + + `arch1` + : GCC architecture in string + + `arch2` + : GCC architecture in string + + # Type + + ``` + canExecute :: string -> string -> bool + ``` + + # Examples + ::: {.example} + ## `lib.systems.architectures.canExecute` usage example + + ```nix + canExecute "x86-64" "x86-64-v3" + => false + canExecute "x86-64-v3" "x86-64" + => true + canExecute "x86-64" "x86-64" + => true + ``` + */ + canExecute = arch1: arch2: arch1 == arch2 || hasInferior arch1 arch2; + predicates = let featureSupport = feature: x: builtins.elem feature features.${x} or [ ]; From 1802f697e4b448e3d31aeeb54205e915afe02f16 Mon Sep 17 00:00:00 2001 From: aleksana Date: Fri, 2 May 2025 13:45:27 +0800 Subject: [PATCH 2/2] lib.systems.elaborate.canExecute: handle different gcc.arch --- lib/systems/default.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index ce257d5307b6..02f6f91da670 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -97,7 +97,21 @@ let platform: final.isAndroid == platform.isAndroid && parse.isCompatible final.parsed.cpu platform.parsed.cpu - && final.parsed.kernel == platform.parsed.kernel; + && final.parsed.kernel == platform.parsed.kernel + && ( + # Only perform this check when cpus have the same type; + # assume compatible cpu have all the instructions included + final.parsed.cpu == platform.parsed.cpu + -> + # if both have gcc.arch defined, check whether final can execute the given platform + ( + (final ? gcc.arch && platform ? gcc.arch) + -> architectures.canExecute final.gcc.arch platform.gcc.arch + ) + # if platform has gcc.arch defined but final doesn't, don't assume it can be executed + || (platform ? gcc.arch -> !(final ? gcc.arch)) + ); + isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";