Skip to content

Commit

Permalink
πŸ› Fix cross-compilation setup for C/C++
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
abbec committed Dec 13, 2024
1 parent d5af691 commit 17c88a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions c/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ platformOverrides:
, pkgs
, lib
, buildPackages
, pkgsBuildBuild
, substitute
, writeShellScriptBin
, components
Expand All @@ -29,7 +30,7 @@ let
replacements = [
"--subst-var-by"
"name"
attrs.name
attrs.name or attrs.pname
"--subst-var-by"
"version"
attrs.version
Expand Down Expand Up @@ -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 [ ]
Expand All @@ -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
Expand All @@ -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.";
Expand Down

0 comments on commit 17c88a5

Please sign in to comment.