From 17c88a57d634d4b3f670bec8f01f38cec7d6aad7 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 | 14 +++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc85f0..e721e81 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 +- Use more appropriate versions of clangd and clang-format when + cross-compiling since the target platform does not actually + matter. +- Use a debugger for the shell that comes from buildPackages + to get the correct hostPlatform when cross-compiling. +- Enabling doxygen required the `name` attribute. Now, + pname is enough as well. +- 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..1380997 100644 --- a/c/make-derivation.nix +++ b/c/make-derivation.nix @@ -4,6 +4,7 @@ platformOverrides: , pkgs , lib , buildPackages +, pkgsBuildBuild , substitute , writeShellScriptBin , components @@ -29,7 +30,7 @@ let replacements = [ "--subst-var-by" "name" - attrs.name + attrs.name or attrs.pname "--subst-var-by" "version" attrs.version @@ -85,7 +86,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 +99,14 @@ 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 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 rc=$? if [ $rc -eq 0 ]; then @@ -129,7 +129,7 @@ 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 "$@" runHook postFormat ''; description = "Format source code in the component.";