Skip to content

Commit 77a650c

Browse files
dkulpclaude
andcommitted
Add a "nocc + mdns" distributed compile mode
nocc gained mDNS discovery, so it can now match what "distcc + zeroconf" does: pick a mode in Settings -> Developer and the board finds its compile helpers on the LAN instead of being handed a host list. setup_nocc_host.sh turns advertising on when it sets a box up as a helper. The nocc package ships with it off -- a server that answers anything on the network should be a decision rather than a default -- and running that script IS the decision, since it is what makes the box a helper in the first place. NOCC_MDNS=0 opts out, and re-running with it takes advertising back off. That script now always restarts nocc-server rather than using "enable --now". On a host where the helper was already running, --now is a no-op, so the options it had just edited (the port, and now the mDNS flag) would sit in the env file while the running server kept serving with its old ones. The nocc package has the same trap on upgrade, which is why an upgraded helper needs an explicit restart to actually be running the new binary. DiscoverNoccHosts asks nocc itself ("nocc-daemon -print-discovered-servers") instead of browsing with avahi-browse the way the distcc path does. A helper with more than one interface announces more than one address: a raw browse lists it twice, which hands that machine a double share of the build (nocc shards files across the server list by index), and it may pick the address on a subnet the board cannot reach. Both helpers here announce on two subnets, so that is the normal case. nocc already resolves each helper to one routable address. Verified on real boards: a 32-bit client discovered both helpers, sized -j from them, and compiled through them, producing a correct 32-bit object with no local fallback. A client whose nocc predates the flag falls back to a local build with a clear message rather than misparsing anything. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6ecdcd2 commit 77a650c

3 files changed

Lines changed: 86 additions & 13 deletions

File tree

scripts/functions

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,33 @@ function DiscoverDistccHosts() {
315315
echo "${out# }"
316316
}
317317

318+
# Discover nocc helpers advertised on the LAN via mDNS and emit a list of
319+
# "host:port" (space separated; SetupBuildEnv joins them with ';'). Helpers
320+
# advertise _nocc._tcp when set up with setup_nocc_host.sh.
321+
#
322+
# We ask nocc itself rather than browsing with avahi-browse as the distcc path
323+
# does. A helper with more than one interface announces more than one address,
324+
# and nocc resolves each helper to ONE address that is routable from here --
325+
# a raw browse would list that helper twice (handing it a double share of the
326+
# build, since nocc shards files across the server list by index) and might
327+
# pick the address on a subnet this board cannot reach. Empty if nocc is too
328+
# old to know the flag, or if no helper answers.
329+
function DiscoverNoccHosts() {
330+
command -v nocc-daemon >/dev/null 2>&1 || return 0
331+
local out="" line
332+
while read -r line; do
333+
# Accept only bare "host:port". An older nocc-daemon does not know the flag
334+
# and prints its whole usage text instead, which must not be parsed as hosts.
335+
case "${line}" in
336+
*[[:space:]]*) continue ;;
337+
*:[0-9]*) out="${out} ${line}" ;;
338+
esac
339+
done < <(timeout 10 nocc-daemon -print-discovered-servers 2>/dev/null)
340+
echo "${out# }"
341+
}
342+
318343
# Prepare the environment for a source rebuild based on the "Distributed Compile"
319-
# developer setting (off | distcc | distcc-zeroconf | nocc). MUST be called
344+
# developer setting (off | distcc | distcc-zeroconf | nocc | nocc-zeroconf). MUST be called
320345
# directly (not in a $(...) subshell) so the exports survive into the make that
321346
# follows. Sets these globals:
322347
# DISTCC_HOSTS / NOCC_SERVERS / NOCC_GO_EXECUTABLE / NOCC_LOG_FILENAME
@@ -369,8 +394,14 @@ function SetupBuildEnv() {
369394
BUILD_CPUS=$(ComputeMakeParallelism)
370395
fi
371396
;;
372-
nocc)
373-
hosts=$(getSetting DistccHosts)
397+
nocc|nocc-zeroconf)
398+
if [ "${mode}" = "nocc-zeroconf" ]; then
399+
# Ask nocc what is advertising itself on the LAN (see DiscoverNoccHosts).
400+
hosts=$(DiscoverNoccHosts)
401+
[ -z "${hosts}" ] && echo "nocc: mDNS enabled but no helpers were discovered on the network"
402+
else
403+
hosts=$(getSetting DistccHosts)
404+
fi
374405
if [ -n "${hosts}" ]; then
375406
# nocc wants a ';'-delimited list of host:port and REQUIRES the
376407
# port (unlike distcc's space-delimited host[:port][/jobs,opts]).
@@ -398,7 +429,11 @@ function SetupBuildEnv() {
398429
BUILD_CPUS=$(ComputeDistccParallelism "${hosts}" nocc)
399430
echo "Building with nocc: NOCC_SERVERS='${NOCC_SERVERS}', -j ${BUILD_CPUS} (PCH disabled; makefile selects the triplet compiler)"
400431
else
401-
echo "nocc selected but no Compile Hosts configured -- building locally"
432+
if [ "${mode}" = "nocc-zeroconf" ]; then
433+
echo "nocc + mdns selected but no helpers were discovered -- building locally"
434+
else
435+
echo "nocc selected but no Compile Hosts configured -- building locally"
436+
fi
402437
BUILD_CPUS=$(ComputeMakeParallelism)
403438
fi
404439
;;

scripts/setup_nocc_host.sh

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# actually gets fed. Measured ~3x faster full builds on a BBB.
1414
#
1515
# This is OPT-IN. A client only uses the helper when its build env points at it
16-
# (NOCC_SERVERS=thishost:43210; FPP's makefiles then run nocc as the compiler
17-
# launcher directly). The nocc binaries and the (disabled) nocc-server unit come
18-
# from the FPP apt repo: apt-get install nocc
16+
# -- either explicitly (NOCC_SERVERS=thishost:43210) or by finding it on the LAN,
17+
# since this script makes the helper advertise itself over mDNS as _nocc._tcp
18+
# (clients pick "nocc + mdns" under Settings -> Developer). FPP's makefiles then
19+
# run nocc as the compiler launcher directly. The nocc binaries and the
20+
# (disabled) nocc-server unit come from the FPP apt repo: apt-get install nocc
1921
#
2022
# ---------------------------------------------------------------------------
2123
# Serving both 32-bit and 64-bit clients: YES, one host.
@@ -39,6 +41,7 @@
3941
# sudo PORT=43210 ./setup_nocc_host.sh # override port
4042
# sudo NOCC_FIREWALL=1 ./setup_nocc_host.sh # + LAN-only nftables rule
4143
# sudo NOCC_FIREWALL=1 ./setup_nocc_host.sh 192.168.7.0/24 # force LAN CIDR(s)
44+
# sudo NOCC_MDNS=0 ./setup_nocc_host.sh # do not advertise over mDNS
4245
# sudo ./setup_nocc_host.sh disable # stop & disable the helper
4346
#####################################
4447

@@ -94,6 +97,30 @@ if [ "$PORT" != "43210" ] && [ -f "$ENVF" ]; then
9497
sed -i -E "s/-port [0-9]+/-port ${PORT}/" "$ENVF"
9598
fi
9699

100+
# ---- advertise over mDNS so clients can find this helper --------------------
101+
# The nocc package ships with advertising OFF, because a server answering
102+
# anything on the LAN should be a decision, not a default. Running THIS script
103+
# is that decision: it is what turns a box into a helper. NOCC_MDNS=0 opts out.
104+
if [ -f "$ENVF" ]; then
105+
if [ "${NOCC_MDNS:-1}" = "1" ]; then
106+
if grep -q -- "-advertise-mdns" "$ENVF"; then
107+
echo "==> Already advertising over mDNS (_nocc._tcp)"
108+
elif nocc-server -help 2>&1 | grep -q -- "-advertise-mdns"; then
109+
echo "==> Enabling mDNS advertisement (_nocc._tcp) in ${ENVF}"
110+
sed -i -E 's/^(NOCC_SERVER_OPTS=")/\1-advertise-mdns /' "$ENVF"
111+
else
112+
echo "NOTE: this nocc-server predates -advertise-mdns; upgrade the nocc package"
113+
echo " to let clients discover this helper automatically."
114+
fi
115+
else
116+
# NOCC_MDNS=0 on a host that was advertising: take it back off
117+
if grep -q -- "-advertise-mdns" "$ENVF"; then
118+
echo "==> Disabling mDNS advertisement in ${ENVF}"
119+
sed -i -E 's/ ?-advertise-mdns//' "$ENVF"
120+
fi
121+
fi
122+
fi
123+
97124
# ---- optional LAN-only firewall (nocc-server has no ACL of its own) ----------
98125
if [ "${NOCC_FIREWALL:-0}" = "1" ]; then
99126
if command -v nft >/dev/null 2>&1; then
@@ -120,9 +147,13 @@ else
120147
fi
121148

122149
# ---- enable + (re)start -----------------------------------------------------
150+
# Always restart, never just "enable --now": on a host where the helper is
151+
# already running, --now is a no-op, so the options edited above (port, mDNS)
152+
# would sit in the env file while the running server kept its old ones.
123153
echo "==> Enabling and starting nocc-server"
124154
systemctl daemon-reload
125-
systemctl enable --now nocc-server
155+
systemctl enable nocc-server
156+
systemctl restart nocc-server
126157
sleep 1
127158

128159
echo
@@ -134,6 +165,9 @@ else
134165
fi
135166
ss -ltn 2>/dev/null | grep -q ":${PORT}" && echo "Listening on TCP ${PORT}." || \
136167
echo "NOTE: did not see a listener on ${PORT} yet."
168+
if grep -q -- "-advertise-mdns" "$ENVF" 2>/dev/null; then
169+
echo "Advertising over mDNS as _nocc._tcp (clients can select 'nocc + mdns')."
170+
fi
137171

138172
echo
139173
echo "Installed compilers on this host (clients MUST match the major version):"
@@ -160,8 +194,11 @@ CLIENT USAGE (on the SLOW board you want to speed up):
160194
cd /opt/fpp/src && make -j6 CXXCOMPILER=<triplet>-g++ ...
161195
162196
<triplet> is arm-linux-gnueabihf (32-bit) or aarch64-linux-gnu (64-bit).
163-
nocc has no host auto-discovery (unlike distcc's mDNS); list this helper
164-
explicitly in NOCC_SERVERS.
197+
198+
Or skip the host list entirely: in the FPP UI, Settings -> Developer ->
199+
Distributed Compile -> "nocc + mdns" finds this helper on the LAN by itself.
200+
Outside FPP, that is NOCC_DISCOVER_MDNS=1 (and 'nocc -print-discovered-servers'
201+
prints what is out there).
165202
166203
To turn the helper back off: sudo $0 disable
167204
============================================================

www/settings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@
17141714
"DistributedCompile": {
17151715
"name": "DistributedCompile",
17161716
"description": "Distributed Compile",
1717-
"tip": "Distribute FPP source compiles to a helper host to speed up full rebuilds (e.g. after a branch switch or a header change that invalidates ccache). Set up the helper with scripts/setup_distcc_host.sh (distcc) or scripts/setup_nocc_host.sh (nocc), running the same compiler major version. Any distributed mode disables the precompiled header. 'nocc' does NOT preprocess locally, so it is far faster on slow single-core boards (BeagleBone Black, Pi Zero); 'distcc' preprocesses locally then compiles on the helper; 'distcc + zeroconf' auto-discovers distcc helpers on the LAN via mDNS.",
1717+
"tip": "Distribute FPP source compiles to a helper host to speed up full rebuilds (e.g. after a branch switch or a header change that invalidates ccache). Set up the helper with scripts/setup_distcc_host.sh (distcc) or scripts/setup_nocc_host.sh (nocc), running the same compiler major version. Any distributed mode disables the precompiled header. 'nocc' does NOT preprocess locally, so it is far faster on slow single-core boards (BeagleBone Black, Pi Zero); 'distcc' preprocesses locally then compiles on the helper; 'distcc + zeroconf' auto-discovers distcc helpers on the LAN via mDNS, and 'nocc + mdns' does the same for nocc helpers (set one up with 'sudo scripts/setup_nocc_host.sh', which makes it advertise itself).",
17181718
"level": 3,
17191719
"restart": 0,
17201720
"reboot": 0,
@@ -1724,7 +1724,8 @@
17241724
"Off": "off",
17251725
"distcc": "distcc",
17261726
"distcc + zeroconf": "distcc-zeroconf",
1727-
"nocc": "nocc"
1727+
"nocc": "nocc",
1728+
"nocc + mdns": "nocc-zeroconf"
17281729
},
17291730
"children": {
17301731
"distcc": [
@@ -1738,7 +1739,7 @@
17381739
"DistccHosts": {
17391740
"name": "DistccHosts",
17401741
"description": "Compile Hosts",
1741-
"tip": "Space separated list of helper hosts. distcc: host[:port][/jobs][,options], e.g. 'fpppi5:3632/6,lzo'. nocc: host[:port] (default port 43210), e.g. 'fpppi5'. Not used for 'distcc + zeroconf' (helpers are discovered via mDNS).",
1742+
"tip": "Space separated list of helper hosts. distcc: host[:port][/jobs][,options], e.g. 'fpppi5:3632/6,lzo'. nocc: host[:port] (default port 43210), e.g. 'fpppi5'. Not used for 'distcc + zeroconf' or 'nocc + mdns' (helpers are discovered via mDNS).",
17421743
"level": 3,
17431744
"restart": 0,
17441745
"reboot": 0,

0 commit comments

Comments
 (0)