From 8ed3698ee3d7d74f385949233d04a36e614e0b85 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Fri, 13 Dec 2024 08:14:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20cross-compilation=20setup?= =?UTF-8?q?=20for=20C/C++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use tools from `pkgsBuildBuild` where appropriate. Many of these tools do not actually care about targetPlatform so getting them from pkgsBuildBuild makes sure that we do not need to rebuild them when cross compiling. - Fix doxygen output requiring `name`. `pname` is now also correctly accepted. --- CHANGELOG.md | 11 +++++++++++ c/make-derivation.nix | 37 +++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc85f0..a088666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## Fixed +- c/c++: Use more appropriate versions of clangd and clang-format when + cross-compiling since the target platform does not actually + matter. +- c/c++: Use a debugger for the shell that comes from buildPackages + to get the correct hostPlatform when cross-compiling. +- c/c++: Enabling doxygen required the `name` attribute. Now, + pname is enough as well. +- c/c++: Use a more appropriate variant of `fd`, since it + does not depend on the target platform when cross-compiling. + ## [5.1.0] - 2024-12-12 ### Added diff --git a/c/make-derivation.nix b/c/make-derivation.nix index a0a00b9..1cb278c 100644 --- a/c/make-derivation.nix +++ b/c/make-derivation.nix @@ -4,8 +4,8 @@ platformOverrides: , pkgs , lib , buildPackages +, pkgsBuildBuild , substitute -, writeShellScriptBin , components , targetName , doxygenOutputDir ? "doc" @@ -29,7 +29,7 @@ let replacements = [ "--subst-var-by" "name" - attrs.name + attrs.name or attrs.pname "--subst-var-by" "version" attrs.version @@ -40,7 +40,7 @@ let }; - wrappedDoxygen = outputDir: doxyfiles: writeShellScriptBin "doxygen" '' + wrappedDoxygen = outputDir: doxyfiles: pkgsBuildBuild.writeShellScriptBin "doxygen" '' set -euo pipefail doxyfiles=(${builtins.concatStringsSep " " doxyfiles}) : ''${componentDir=$PWD} @@ -48,7 +48,7 @@ let doxyfiles+=("$componentDir/Doxyfile") fi if [[ $@ =~ "--print-generated-config" ]]; then - ${buildPackages.bat}/bin/bat "''${doxyfiles[@]}" + ${pkgsBuildBuild.bat}/bin/bat "''${doxyfiles[@]}" exit 0 fi @@ -57,9 +57,9 @@ let cp --no-preserve=mode "${mathjax}" "${outputDir}"/html/mathjax/MathJax.js if [ $# -eq 0 ]; then - ${buildPackages.doxygen}/bin/doxygen <(cat "''${doxyfiles[@]}") + ${pkgsBuildBuild.doxygen}/bin/doxygen <(cat "''${doxyfiles[@]}") else - ${buildPackages.doxygen}/bin/doxygen "$@" + ${pkgsBuildBuild.doxygen}/bin/doxygen "$@" fi ''; @@ -85,7 +85,7 @@ let outputs = [ "out" ] ++ lib.optionals (attrs.enableDoxygen or enableDoxygen) [ "doc" "man" ]; } // attrs // { nativeBuildInputs = [ - buildPackages.clang-tools + pkgsBuildBuild.clang-tools buildPackages.valgrind ] ++ attrs.nativeBuildInputs or [ ] @@ -98,15 +98,25 @@ let ] ); - shellInputs = [ - pkgs.${attrs.debugger or "gdb"} - ] ++ attrs.shellInputs or [ ]; + shellInputs = [ buildPackages.${attrs.debugger or "gdb"} ] + ++ attrs.shellInputs or [ ]; lintPhase = attrs.lintPhase or '' runHook preLint + sourcePath="." + if [ -n "''${componentDir:-}" ]; then + sourcePath="$componentDir" + elif [ -n "''${sourceRoot:-}" ]; then + sourcePath="''${NIX_BUILD_TOP:-.}/$sourceRoot" + fi + if [ -z "''${dontCheckClangFormat:-}" ]; then echo "🏟 Checking format in C/C++ files..." - ${buildPackages.fd}/bin/fd --ignore-file=.gitignore --glob '*.{h,hpp,hh,cpp,cxx,cc,c}' --exec-batch clang-format -Werror -n --style=LLVM + ${pkgsBuildBuild.fd}/bin/fd \ + --ignore-file=.gitignore \ + --glob '*.{h,hpp,hh,cpp,cxx,cc,c}' \ + --exec-batch clang-format -Werror -n --style=LLVM --verbose \; \ + "$sourcePath" rc=$? if [ $rc -eq 0 ]; then @@ -129,7 +139,10 @@ let script = '' runHook preFormat echo "🏟️ Formatting C++ files..." - ${buildPackages.fd}/bin/fd --glob '*.{h,hpp,hh,cpp,cxx,cc,c}' --exec-batch clang-format --style=LLVM -i "$@" + ${pkgsBuildBuild.fd}/bin/fd \ + --glob '*.{h,hpp,hh,cpp,cxx,cc,c}' \ + --exec-batch clang-format --style=LLVM -i "$@" \; \ + "''${componentDir:-.}" runHook postFormat ''; description = "Format source code in the component.";