From 0cd0adf313cc7920ac28ffdcc4b6aba54c69bd21 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 13 Apr 2025 20:44:53 +0000 Subject: [PATCH 1/5] edgetx: migrate to by-name This is a zero rebuild refactor. --- .../default.nix => by-name/ed/edgetx/package.nix} | 15 +++++++-------- pkgs/top-level/all-packages.nix | 2 -- 2 files changed, 7 insertions(+), 10 deletions(-) rename pkgs/{applications/misc/edgetx/default.nix => by-name/ed/edgetx/package.nix} (90%) diff --git a/pkgs/applications/misc/edgetx/default.nix b/pkgs/by-name/ed/edgetx/package.nix similarity index 90% rename from pkgs/applications/misc/edgetx/default.nix rename to pkgs/by-name/ed/edgetx/package.nix index e4b4e3f3b385..7f72d3833b26 100644 --- a/pkgs/applications/misc/edgetx/default.nix +++ b/pkgs/by-name/ed/edgetx/package.nix @@ -1,19 +1,17 @@ { lib, - mkDerivation, + stdenv, fetchFromGitHub, cmake, gcc-arm-embedded, python3Packages, - qtbase, - qtmultimedia, - qttools, + libsForQt5, SDL, gtest, dfu-util, }: -mkDerivation rec { +stdenv.mkDerivation rec { pname = "edgetx"; version = "2.7.2"; @@ -29,12 +27,13 @@ mkDerivation rec { cmake gcc-arm-embedded python3Packages.pillow - qttools + libsForQt5.qttools + libsForQt5.wrapQtAppsHook ]; buildInputs = [ - qtbase - qtmultimedia + libsForQt5.qtbase + libsForQt5.qtmultimedia SDL ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b811f4842f5d..3a812310e5f8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15360,8 +15360,6 @@ with pkgs; mopidy-ytmusic ; - edgetx = libsForQt5.callPackage ../applications/misc/edgetx { }; - mpg123 = callPackage ../applications/audio/mpg123 { inherit (darwin.apple_sdk.frameworks) AudioUnit AudioToolbox; jack = libjack2; From 7ab6179a39aaf019cf37d8f8ef199233f7af0da1 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 13 Apr 2025 20:47:28 +0000 Subject: [PATCH 2/5] edgetx: refactor src attribute - Remove repo = pname - Migrate `rev` -> `tag` --- pkgs/by-name/ed/edgetx/package.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/ed/edgetx/package.nix b/pkgs/by-name/ed/edgetx/package.nix index 7f72d3833b26..9bb99677cabe 100644 --- a/pkgs/by-name/ed/edgetx/package.nix +++ b/pkgs/by-name/ed/edgetx/package.nix @@ -17,8 +17,8 @@ stdenv.mkDerivation rec { src = fetchFromGitHub { owner = "EdgeTX"; - repo = pname; - rev = "v${version}"; + repo = "edgetx"; + tag = "v${version}"; fetchSubmodules = true; hash = "sha256-bKMAyONy1Udd+2nDVEMrtIsnfqrNuBVMWU7nCqvZ+3E="; }; From 6b917b1564620ea7358693adc5d66fb97c354aba Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 14 Apr 2025 22:44:15 +0000 Subject: [PATCH 3/5] edgetx: 2.7.2 -> 2.11.0-rc3, expand build for all targets Previously the companion was built only for a single default target. This is very unexpected. Upstream build system is a huge pain, so our build will also look very hacky. For reference [1] is how upstream builds their repo. I've tried to make the derivation not very cringeworthy, but there's a lot of complexity piled on. Some specific problems to keep an eye out for: - All targets have to be enumerated by hand. I've put it into a separate file to improve readability. - libclang shenanigans. Upstream uses python bindings for `libclang` to generate code at compile time. To make it find C/C++ standard library headers we have to patch the scripts and read nix-support/{libc,libcxx}-cflags to extract the necessary compiler flags that cc-wrapper usually handles for us. [1]: https://github.com/EdgeTX/edgetx/blob/v2.11.0-rc3/tools/build-companion.sh --- .../ed/edgetx/0001-libclang-paths.patch | 38 +++++ pkgs/by-name/ed/edgetx/package.nix | 144 +++++++++++++++--- pkgs/by-name/ed/edgetx/targets.nix | 46 ++++++ 3 files changed, 210 insertions(+), 18 deletions(-) create mode 100644 pkgs/by-name/ed/edgetx/0001-libclang-paths.patch create mode 100644 pkgs/by-name/ed/edgetx/targets.nix diff --git a/pkgs/by-name/ed/edgetx/0001-libclang-paths.patch b/pkgs/by-name/ed/edgetx/0001-libclang-paths.patch new file mode 100644 index 000000000000..ca40b2a69628 --- /dev/null +++ b/pkgs/by-name/ed/edgetx/0001-libclang-paths.patch @@ -0,0 +1,38 @@ +diff --git a/radio/util/find_clang.py b/radio/util/find_clang.py +index d9cdbb083..f78f87717 100644 +--- a/radio/util/find_clang.py ++++ b/radio/util/find_clang.py +@@ -59,6 +59,7 @@ def getBuiltinHeaderPath(library_path): + return None + + def findLibClang(): ++ return "@libclang@" + if sys.platform == "darwin": + knownPaths = [ + "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib", +diff --git a/radio/util/generate_datacopy.py b/radio/util/generate_datacopy.py +index a92b0c3e2..6385b2ff6 100755 +--- a/radio/util/generate_datacopy.py ++++ b/radio/util/generate_datacopy.py +@@ -5,7 +5,8 @@ import sys + import clang.cindex + import time + import os +- ++from pathlib import Path ++import re + + structs = [] + extrastructs = [] +@@ -102,6 +103,11 @@ def main(): + if find_clang.builtin_hdr_path: + args.append("-I" + find_clang.builtin_hdr_path) + ++ args.append("-resource-dir") ++ args.append("@resourceDir@") ++ for path in ["@libc-cflags@", "@libcxx-cflags@"]: ++ args.extend([flag.strip() for flag in re.split(r'\s+', Path(path).read_text()) if flag.strip()]) ++ + translation_unit = index.parse(sys.argv[1], args) + + if translation_unit.diagnostics: diff --git a/pkgs/by-name/ed/edgetx/package.nix b/pkgs/by-name/ed/edgetx/package.nix index 9bb99677cabe..be347cdae9fe 100644 --- a/pkgs/by-name/ed/edgetx/package.nix +++ b/pkgs/by-name/ed/edgetx/package.nix @@ -2,31 +2,57 @@ lib, stdenv, fetchFromGitHub, + python3, cmake, - gcc-arm-embedded, - python3Packages, + ninja, libsForQt5, - SDL, - gtest, + SDL2, + fox_1_6, + replaceVars, + llvmPackages, dfu-util, + gtest, + miniz, + yaml-cpp, + # List of targets to build simulators for + targetsToBuild ? import ./targets.nix, }: -stdenv.mkDerivation rec { +let + # Keep in sync with `cmake/FetchMaxLibQt.cmake`. + maxlibqt = fetchFromGitHub { + owner = "edgetx"; + repo = "maxLibQt"; + rev = "ac1988ffd005cd15a8449b92150ce6c08574a4f1"; + hash = "sha256-u8e4qseU0+BJyZkV0JE4sUiXaFeIYvadkMTGXXiE2Kg="; + }; + + pythonEnv = python3.withPackages ( + pyPkgs: with pyPkgs; [ + pillow + lz4 + jinja2 + libclang + ] + ); +in + +stdenv.mkDerivation (finalAttrs: { pname = "edgetx"; - version = "2.7.2"; + version = "2.11.0-rc3"; src = fetchFromGitHub { owner = "EdgeTX"; repo = "edgetx"; - tag = "v${version}"; + tag = "v${finalAttrs.version}"; fetchSubmodules = true; - hash = "sha256-bKMAyONy1Udd+2nDVEMrtIsnfqrNuBVMWU7nCqvZ+3E="; + hash = "sha256-ipiGkc+R7/itmnRRrlrc4iXn+fLWm4OKc227NfevFhI="; }; nativeBuildInputs = [ cmake - gcc-arm-embedded - python3Packages.pillow + ninja + pythonEnv libsForQt5.qttools libsForQt5.wrapQtAppsHook ]; @@ -34,21 +60,104 @@ stdenv.mkDerivation rec { buildInputs = [ libsForQt5.qtbase libsForQt5.qtmultimedia - SDL + libsForQt5.qtserialport + SDL2 + fox_1_6 + ]; + + patches = [ + (replaceVars ./0001-libclang-paths.patch ( + let + llvmMajor = lib.versions.major llvmPackages.llvm.version; + in + { + resourceDir = "${llvmPackages.clang.cc.lib}/lib/clang/${llvmMajor}"; + libclang = "${lib.getLib llvmPackages.libclang}/lib/libclang.so"; + libc-cflags = "${llvmPackages.clang}/nix-support/libc-cflags"; + libcxx-cflags = "${llvmPackages.clang}/nix-support/libcxx-cxxflags"; + } + )) ]; postPatch = '' sed -i companion/src/burnconfigdialog.cpp \ -e 's|/usr/.*bin/dfu-util|${dfu-util}/bin/dfu-util|' + patchShebangs companion/util radio/util ''; cmakeFlags = [ - "-DGTEST_ROOT=${gtest.src}/googletest" - "-DDFU_UTIL_PATH=${dfu-util}/bin/dfu-util" - # file RPATH_CHANGE could not write new RPATH - "-DCMAKE_SKIP_BUILD_RPATH=ON" + # Unvendoring these libraries is infeasible. At least lets reuse the same sources. + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_GOOGLETEST" "${gtest.src}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MINIZ" "${miniz.src}") + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_YAML-CPP" "${yaml-cpp.src}") + # Custom library https://github.com/edgetx/maxLibQt. + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MAXLIBQT" "${maxlibqt}") + (lib.cmakeFeature "DFU_UTIL_ROOT_DIR" "${lib.getBin dfu-util}/bin") + # Superbuild machinery is only getting in the way. + (lib.cmakeBool "EdgeTX_SUPERBUILD" false) + # COMMON_OPTIONS from tools/build-companion.sh. + (lib.cmakeBool "GVARS" true) + (lib.cmakeBool "HELI" true) + (lib.cmakeBool "LUA" true) + # Build companion and not the firmware. + (lib.cmakeBool "NATIVE_BUILD" true) + # file RPATH_CHANGE could not write new RPATH. + (lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true) ]; + env = { + EDGETX_VERSION_SUFFIX = "nixpkgs"; + }; + + dontUseCmakeConfigure = true; + # We invoke cmakeConfigurePhase multiple times, but only need this once. + dontFixCmake = true; + inherit targetsToBuild; + __structuredAttrs = true; # To pass targetsToBuild as an array. + + configurePhase = '' + runHook preConfigure + prependToVar cmakeFlags "-GNinja" + fixCmakeFiles . + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + cmakeCommonFlags="$''\{cmakeFlags[@]}" + # This is the most sensible way to convert target name -> cmake options + # aside from manually extracting bash variables from upstream's CI scripts + # and converting that to nix expressions. Let's hope upstream doesn't break + # this file too often. + source $src/tools/build-common.sh + + # Yes, this is really how upstream expects packaging to look like ¯\_(ツ)_/¯. + # https://github.com/EdgeTX/edgetx/wiki/Build-Instructions-under-Ubuntu-20.04#building-companion-simulator-and-radio-simulator-libraries + for plugin in "$''\{targetsToBuild[@]''\}" + do + # Variable modified by `get_target_build_options` from build-common.sh. + local BUILD_OPTIONS="" + get_target_build_options "$plugin" + # With each invocation of `cmakeConfigurePhase` `cmakeFlags` gets + # prepended to, so it has to be reset. + cmakeFlags=() + appendToVar cmakeFlags $cmakeCommonFlags $BUILD_OPTIONS + pushd . + cmakeConfigurePhase + ninjaFlags=("libsimulator") + ninjaBuildPhase + rm CMakeCache.txt + popd + done + + cmakeConfigurePhase + ninjaFlags=() + ninjaBuildPhase + + runHook postBuild + ''; + meta = with lib; { description = "EdgeTX Companion transmitter support software"; longDescription = '' @@ -56,7 +165,7 @@ stdenv.mkDerivation rec { firmware to the radio, backing up model settings, editing settings and running radio simulators. ''; - mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion version)); + mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion finalAttrs.version)); homepage = "https://edgetx.org/"; license = licenses.gpl2Only; platforms = [ @@ -70,5 +179,4 @@ stdenv.mkDerivation rec { wucke13 ]; }; - -} +}) diff --git a/pkgs/by-name/ed/edgetx/targets.nix b/pkgs/by-name/ed/edgetx/targets.nix new file mode 100644 index 000000000000..d835799ff0b7 --- /dev/null +++ b/pkgs/by-name/ed/edgetx/targets.nix @@ -0,0 +1,46 @@ +# Keep in sync with tools/build-companion.sh +[ + "x9lite" + "x9lites" + "x7" + "x7access" + "t8" + "t12" + "t12max" + "tx12" + "tx12mk2" + "zorro" + "commando8" + "boxer" + "pocket" + "mt12" + "gx12" + "tlite" + "tpro" + "tprov2" + "tpros" + "bumblebee" + "lr3pro" + "t14" + "x9d" + "x9dp" + "x9dp2019" + "x9e" + "xlite" + "xlites" + "nv14" + "el18" + "pl18" + "pl18ev" + "x10" + "x10express" + "x12s" + "t15" + "t16" + "t18" + "t20" + "t20v2" + "tx16s" + "f16" + "v16" +] From f273becb99669f43b2f841acf037efc93853bf1b Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 14 Apr 2025 22:44:39 +0000 Subject: [PATCH 4/5] edgetx: remove with lib --- pkgs/by-name/ed/edgetx/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ed/edgetx/package.nix b/pkgs/by-name/ed/edgetx/package.nix index be347cdae9fe..8083589d3f06 100644 --- a/pkgs/by-name/ed/edgetx/package.nix +++ b/pkgs/by-name/ed/edgetx/package.nix @@ -158,7 +158,7 @@ stdenv.mkDerivation (finalAttrs: { runHook postBuild ''; - meta = with lib; { + meta = { description = "EdgeTX Companion transmitter support software"; longDescription = '' EdgeTX Companion is used for many different tasks like loading EdgeTX @@ -167,13 +167,13 @@ stdenv.mkDerivation (finalAttrs: { ''; mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion finalAttrs.version)); homepage = "https://edgetx.org/"; - license = licenses.gpl2Only; + license = lib.licenses.gpl2Only; platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" ]; - maintainers = with maintainers; [ + maintainers = with lib.maintainers; [ elitak lopsided98 wucke13 From a5b9b780605aeb81d6feb1b7b718ae5f2e2f1c92 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 14 Apr 2025 22:45:16 +0000 Subject: [PATCH 5/5] edgetx: add myself as maintainer --- pkgs/by-name/ed/edgetx/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/ed/edgetx/package.nix b/pkgs/by-name/ed/edgetx/package.nix index 8083589d3f06..12f6516b0186 100644 --- a/pkgs/by-name/ed/edgetx/package.nix +++ b/pkgs/by-name/ed/edgetx/package.nix @@ -177,6 +177,7 @@ stdenv.mkDerivation (finalAttrs: { elitak lopsided98 wucke13 + xokdvium ]; }; })