Skip to content

Commit 6b917b1

Browse files
committed
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
1 parent 7ab6179 commit 6b917b1

File tree

3 files changed

+210
-18
lines changed

3 files changed

+210
-18
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
diff --git a/radio/util/find_clang.py b/radio/util/find_clang.py
2+
index d9cdbb083..f78f87717 100644
3+
--- a/radio/util/find_clang.py
4+
+++ b/radio/util/find_clang.py
5+
@@ -59,6 +59,7 @@ def getBuiltinHeaderPath(library_path):
6+
return None
7+
8+
def findLibClang():
9+
+ return "@libclang@"
10+
if sys.platform == "darwin":
11+
knownPaths = [
12+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib",
13+
diff --git a/radio/util/generate_datacopy.py b/radio/util/generate_datacopy.py
14+
index a92b0c3e2..6385b2ff6 100755
15+
--- a/radio/util/generate_datacopy.py
16+
+++ b/radio/util/generate_datacopy.py
17+
@@ -5,7 +5,8 @@ import sys
18+
import clang.cindex
19+
import time
20+
import os
21+
-
22+
+from pathlib import Path
23+
+import re
24+
25+
structs = []
26+
extrastructs = []
27+
@@ -102,6 +103,11 @@ def main():
28+
if find_clang.builtin_hdr_path:
29+
args.append("-I" + find_clang.builtin_hdr_path)
30+
31+
+ args.append("-resource-dir")
32+
+ args.append("@resourceDir@")
33+
+ for path in ["@libc-cflags@", "@libcxx-cflags@"]:
34+
+ args.extend([flag.strip() for flag in re.split(r'\s+', Path(path).read_text()) if flag.strip()])
35+
+
36+
translation_unit = index.parse(sys.argv[1], args)
37+
38+
if translation_unit.diagnostics:

pkgs/by-name/ed/edgetx/package.nix

Lines changed: 126 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,170 @@
22
lib,
33
stdenv,
44
fetchFromGitHub,
5+
python3,
56
cmake,
6-
gcc-arm-embedded,
7-
python3Packages,
7+
ninja,
88
libsForQt5,
9-
SDL,
10-
gtest,
9+
SDL2,
10+
fox_1_6,
11+
replaceVars,
12+
llvmPackages,
1113
dfu-util,
14+
gtest,
15+
miniz,
16+
yaml-cpp,
17+
# List of targets to build simulators for
18+
targetsToBuild ? import ./targets.nix,
1219
}:
1320

14-
stdenv.mkDerivation rec {
21+
let
22+
# Keep in sync with `cmake/FetchMaxLibQt.cmake`.
23+
maxlibqt = fetchFromGitHub {
24+
owner = "edgetx";
25+
repo = "maxLibQt";
26+
rev = "ac1988ffd005cd15a8449b92150ce6c08574a4f1";
27+
hash = "sha256-u8e4qseU0+BJyZkV0JE4sUiXaFeIYvadkMTGXXiE2Kg=";
28+
};
29+
30+
pythonEnv = python3.withPackages (
31+
pyPkgs: with pyPkgs; [
32+
pillow
33+
lz4
34+
jinja2
35+
libclang
36+
]
37+
);
38+
in
39+
40+
stdenv.mkDerivation (finalAttrs: {
1541
pname = "edgetx";
16-
version = "2.7.2";
42+
version = "2.11.0-rc3";
1743

1844
src = fetchFromGitHub {
1945
owner = "EdgeTX";
2046
repo = "edgetx";
21-
tag = "v${version}";
47+
tag = "v${finalAttrs.version}";
2248
fetchSubmodules = true;
23-
hash = "sha256-bKMAyONy1Udd+2nDVEMrtIsnfqrNuBVMWU7nCqvZ+3E=";
49+
hash = "sha256-ipiGkc+R7/itmnRRrlrc4iXn+fLWm4OKc227NfevFhI=";
2450
};
2551

2652
nativeBuildInputs = [
2753
cmake
28-
gcc-arm-embedded
29-
python3Packages.pillow
54+
ninja
55+
pythonEnv
3056
libsForQt5.qttools
3157
libsForQt5.wrapQtAppsHook
3258
];
3359

3460
buildInputs = [
3561
libsForQt5.qtbase
3662
libsForQt5.qtmultimedia
37-
SDL
63+
libsForQt5.qtserialport
64+
SDL2
65+
fox_1_6
66+
];
67+
68+
patches = [
69+
(replaceVars ./0001-libclang-paths.patch (
70+
let
71+
llvmMajor = lib.versions.major llvmPackages.llvm.version;
72+
in
73+
{
74+
resourceDir = "${llvmPackages.clang.cc.lib}/lib/clang/${llvmMajor}";
75+
libclang = "${lib.getLib llvmPackages.libclang}/lib/libclang.so";
76+
libc-cflags = "${llvmPackages.clang}/nix-support/libc-cflags";
77+
libcxx-cflags = "${llvmPackages.clang}/nix-support/libcxx-cxxflags";
78+
}
79+
))
3880
];
3981

4082
postPatch = ''
4183
sed -i companion/src/burnconfigdialog.cpp \
4284
-e 's|/usr/.*bin/dfu-util|${dfu-util}/bin/dfu-util|'
85+
patchShebangs companion/util radio/util
4386
'';
4487

4588
cmakeFlags = [
46-
"-DGTEST_ROOT=${gtest.src}/googletest"
47-
"-DDFU_UTIL_PATH=${dfu-util}/bin/dfu-util"
48-
# file RPATH_CHANGE could not write new RPATH
49-
"-DCMAKE_SKIP_BUILD_RPATH=ON"
89+
# Unvendoring these libraries is infeasible. At least lets reuse the same sources.
90+
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_GOOGLETEST" "${gtest.src}")
91+
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MINIZ" "${miniz.src}")
92+
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_YAML-CPP" "${yaml-cpp.src}")
93+
# Custom library https://github.com/edgetx/maxLibQt.
94+
(lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MAXLIBQT" "${maxlibqt}")
95+
(lib.cmakeFeature "DFU_UTIL_ROOT_DIR" "${lib.getBin dfu-util}/bin")
96+
# Superbuild machinery is only getting in the way.
97+
(lib.cmakeBool "EdgeTX_SUPERBUILD" false)
98+
# COMMON_OPTIONS from tools/build-companion.sh.
99+
(lib.cmakeBool "GVARS" true)
100+
(lib.cmakeBool "HELI" true)
101+
(lib.cmakeBool "LUA" true)
102+
# Build companion and not the firmware.
103+
(lib.cmakeBool "NATIVE_BUILD" true)
104+
# file RPATH_CHANGE could not write new RPATH.
105+
(lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
50106
];
51107

108+
env = {
109+
EDGETX_VERSION_SUFFIX = "nixpkgs";
110+
};
111+
112+
dontUseCmakeConfigure = true;
113+
# We invoke cmakeConfigurePhase multiple times, but only need this once.
114+
dontFixCmake = true;
115+
inherit targetsToBuild;
116+
__structuredAttrs = true; # To pass targetsToBuild as an array.
117+
118+
configurePhase = ''
119+
runHook preConfigure
120+
prependToVar cmakeFlags "-GNinja"
121+
fixCmakeFiles .
122+
runHook postConfigure
123+
'';
124+
125+
buildPhase = ''
126+
runHook preBuild
127+
128+
cmakeCommonFlags="$''\{cmakeFlags[@]}"
129+
# This is the most sensible way to convert target name -> cmake options
130+
# aside from manually extracting bash variables from upstream's CI scripts
131+
# and converting that to nix expressions. Let's hope upstream doesn't break
132+
# this file too often.
133+
source $src/tools/build-common.sh
134+
135+
# Yes, this is really how upstream expects packaging to look like ¯\_(ツ)_/¯.
136+
# https://github.com/EdgeTX/edgetx/wiki/Build-Instructions-under-Ubuntu-20.04#building-companion-simulator-and-radio-simulator-libraries
137+
for plugin in "$''\{targetsToBuild[@]''\}"
138+
do
139+
# Variable modified by `get_target_build_options` from build-common.sh.
140+
local BUILD_OPTIONS=""
141+
get_target_build_options "$plugin"
142+
# With each invocation of `cmakeConfigurePhase` `cmakeFlags` gets
143+
# prepended to, so it has to be reset.
144+
cmakeFlags=()
145+
appendToVar cmakeFlags $cmakeCommonFlags $BUILD_OPTIONS
146+
pushd .
147+
cmakeConfigurePhase
148+
ninjaFlags=("libsimulator")
149+
ninjaBuildPhase
150+
rm CMakeCache.txt
151+
popd
152+
done
153+
154+
cmakeConfigurePhase
155+
ninjaFlags=()
156+
ninjaBuildPhase
157+
158+
runHook postBuild
159+
'';
160+
52161
meta = with lib; {
53162
description = "EdgeTX Companion transmitter support software";
54163
longDescription = ''
55164
EdgeTX Companion is used for many different tasks like loading EdgeTX
56165
firmware to the radio, backing up model settings, editing settings and
57166
running radio simulators.
58167
'';
59-
mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion version));
168+
mainProgram = "companion" + lib.concatStrings (lib.take 2 (lib.splitVersion finalAttrs.version));
60169
homepage = "https://edgetx.org/";
61170
license = licenses.gpl2Only;
62171
platforms = [
@@ -70,5 +179,4 @@ stdenv.mkDerivation rec {
70179
wucke13
71180
];
72181
};
73-
74-
}
182+
})

pkgs/by-name/ed/edgetx/targets.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Keep in sync with tools/build-companion.sh
2+
[
3+
"x9lite"
4+
"x9lites"
5+
"x7"
6+
"x7access"
7+
"t8"
8+
"t12"
9+
"t12max"
10+
"tx12"
11+
"tx12mk2"
12+
"zorro"
13+
"commando8"
14+
"boxer"
15+
"pocket"
16+
"mt12"
17+
"gx12"
18+
"tlite"
19+
"tpro"
20+
"tprov2"
21+
"tpros"
22+
"bumblebee"
23+
"lr3pro"
24+
"t14"
25+
"x9d"
26+
"x9dp"
27+
"x9dp2019"
28+
"x9e"
29+
"xlite"
30+
"xlites"
31+
"nv14"
32+
"el18"
33+
"pl18"
34+
"pl18ev"
35+
"x10"
36+
"x10express"
37+
"x12s"
38+
"t15"
39+
"t16"
40+
"t18"
41+
"t20"
42+
"t20v2"
43+
"tx16s"
44+
"f16"
45+
"v16"
46+
]

0 commit comments

Comments
 (0)