Advantages of external toolchain for builds

I have always built my own toolchain but I see there is an option to use an external one. Besides not needing the CPU time to compile the toolchain, are there other advantages to using the external one?

No, you just free up some cpu time. Depending on how often you build and how often the toolchain is changing (its not that often). You would give away some flexibility: Like choosing gcc13 over gcc12 or glibc over musl if you use the OpenWrt pre-built toolchains. But in this regard you could add/link your own built toolchain as external toolchain for other builds also.

Things would be different if you build quite often and on different host system architectures/platforms (like x86, x86-64, arm, ppc, aarch64, etc.).

2 Likes

+1 for @pwned response.

Edit: if you normally run make clean before a build, your toolchain will remain.

1 Like

I tried building with the toolchain but I found that it starting building lots of host programs. I thought all of these would be provided by the zst file? What am I doing wrong?

 make[1] world
 make[2] tools/compile
 make[2] package/cleanup
 make[3] -C tools/libdeflate compile
 make[3] -C tools/flock compile
 make[3] -C tools/zstd compile
 make[3] -C tools/sed compile
 make[3] -C tools/tar compile
 make[3] -C tools/patch compile
 make[3] -C tools/m4 compile
 make[3] -C tools/expat compile
 make[3] -C tools/xz compile
 make[3] -C tools/autoconf-archive compile
 make[3] -C tools/ninja compile

Nothing.

If you have selected Package the OpenWrt-based Toolchain it’s going to run through a full build as normal and place it in your bin/targets/. . . when it’s done.

FWIW, you can save yourself some time and download a pre-compiled Toolchain for your target/release from downloads.openwrt.org

See the wiki

If you call make world it's doing everything. Tools are needed as basis. They are used e. g. for packaging also. Then the toolchain is made (if not linked static within config to skip it). After it the kernel and packages. If you want to build certain things only you could do make toolchain/install (which would trigger make tools/install before also). You could also make just the kernel/modules or some packages only. Which triggers tools and toolchain also (if not already built).

I’ve also seen host stuff getting built when using the external toolchain. Is that expected?

I think I am not doing something right because many tools are built when I use the external toolchain.

I started with a clean clone and make this .config

CONFIG_TARGET_x86=y
CONFIG_TARGET_x86_64=y
CONFIG_TARGET_x86_64_DEVICE_generic=y

Now I do

./scripts/feeds update -a ; ./scripts/feeds install -a
...

./scripts/ext-toolchain.sh --toolchain /opt/cross/toolchain-x86_64_gcc-13.2.0_musl --overwrite-config --config x86/64
There already is a .config file, trying to overwrite!
make: Entering directory '/home/openwrt'
Collecting package info: done
.config:4:warning: override: TARGET_x86 changes choice state
.config:5:warning: override: TARGET_x86_64 changes choice state
#
# configuration written to .config
#
make: Leaving directory '/home/openwrt'

Now I run make and lots of GB gets compiled in build_dir and staging_dir

make defconfig && make
 make[1] world
 make[2] tools/compile
 make[2] package/cleanup
 make[3] -C tools/libdeflate compile
 make[3] -C tools/flock compile
 make[3] -C tools/zstd compile
 make[3] -C tools/sed compile
 make[3] -C tools/patch compile
 make[3] -C tools/tar compile
 make[3] -C tools/m4 compile
 make[3] -C tools/ninja compile
 make[3] -C tools/autoconf-archive compile
 make[3] -C tools/xz compile
 make[3] -C tools/gnulib compile
 make[3] -C tools/expat compile
 make[3] -C tools/zlib compile
 make[3] -C tools/cpio compile
 make[3] -C tools/lzma compile
 make[3] -C tools/mtools compile
 make[3] -C tools/patch-image compile
 make[3] -C tools/sstrip compile
 make[3] -C tools/zip compile
 make[3] -C tools/make-ext4fs compile
 make[3] -C tools/squashfs4 compile
 make[3] -C tools/meson compile
 make[3] -C tools/pkgconf compile
 make[3] -C tools/libressl compile
 make[3] -C tools/autoconf compile
 make[3] -C tools/automake compile
 make[3] -C tools/missing-macros compile
 make[3] -C tools/libtool compile
 make[3] -C tools/dosfstools compile
 make[3] -C tools/cmake compile
 make[3] -C tools/elfutils compile
 make[3] -C tools/flex compile
 make[3] -C tools/e2fsprogs compile
 make[3] -C tools/fakeroot compile
 make[3] -C tools/gengetopt compile
 make[3] -C tools/patchelf compile
 make[3] -C tools/mklibs compile
 make[3] -C tools/mtd-utils compile
 make[3] -C tools/bison compile
 make[3] -C tools/firmware-utils compile
 make[3] -C tools/bc compile
 make[3] -C tools/findutils compile
 make[3] -C tools/mkimage compile
 make[3] -C tools/util-linux compile
 make[3] -C tools/padjffs2 compile
 make[3] -C tools/quilt compile
 make[2] toolchain/compile
 make[3] -C toolchain/wrapper compile
 make[3] -C toolchain/nasm compile
 make[2] target/compile
 make[3] -C target/linux compile
 make[2] buildinfo
 make[2] package/compile
 make[3] diffconfig buildversion feedsversion
 make[3] -C package/libs/toolchain compile
 make[3] -C package/libs/libjson-c host-compile
 make[3] -C package/kernel/gpio-button-hotplug compile
 make[3] -C package/libs/ncurses host-compile
 make[3] -C package/system/fwtool host-compile
 make[3] -C package/system/usign host-compile
 make[3] -C package/boot/grub2 host-compile
 make[3] -C package/utils/e2fsprogs host-compile
 make[3] -C package/libs/libnl-tiny compile
 make[3] -C package/libs/libjson-c compile
 make[3] -C package/utils/lua compile
 make[3] -C package/libs/zlib compile
 make[3] -C package/firmware/linux-firmware compile
 make[3] -C package/system/fwtool compile
 make[3] -C package/system/openwrt-keyring compile
 make[3] -C package/libs/jansson compile
 make[3] -C package/libs/libmnl compile
 make[3] -C package/libs/mbedtls compile
 make[3] -C package/network/services/dropbear compile
 make[3] -C package/libs/libpcap compile
 make[3] -C package/network/utils/linux-atm compile
 make[3] -C package/network/utils/resolveip compile
 make[3] -C package/system/ca-certificates compile
 make[3] -C package/libs/libsepol compile
 make[3] -C package/libs/musl-fts compile
 make[4] scripts/config/conf
 make[3] -C package/libs/pcre2 compile
 make[3] -C package/libs/libubox host-compile
 make[3] -C package/libs/libubox compile
 make[3] -C package/system/opkg host-compile
 make[3] -C package/system/ucert host-compile
 make[3] -C package/system/ubus compile
 make[3] -C package/system/uci compile
 make[3] -C package/utils/jsonfilter compile
 make[3] -C package/system/usign compile
 make[3] -C package/libs/ustream-ssl compile
 make[3] -C package/network/ipv6/odhcp6c compile
 make[3] -C package/system/mtd compile
 make[3] -C package/system/urngd compile
 make[3] -C package/utils/ucode compile
 make[3] -C package/network/services/dnsmasq compile
 make[3] -C package/network/services/odhcpd compile
 make[3] -C package/libs/udebug compile
 make[3] -C package/libs/uclient compile
 make[3] -C package/network/config/netifd compile
 make[3] -C package/system/ubox compile
 make[3] -C package/system/opkg compile
 make[3] -C package/system/urandom-seed compile
 make[3] -C package/libs/libnftnl compile
 make[3] -C package/kernel/linux compile
 make[3] -C package/libs/libselinux compile
 make[3] -C package/boot/grub2 compile
 make[3] -C package/network/utils/nftables compile
 make[3] -C package/kernel/button-hotplug compile
 make[3] -C package/network/services/ppp compile
 make[3] -C package/utils/busybox compile
 make[3] -C package/libs/ncurses compile
 make[3] -C package/utils/util-linux compile
 make[3] -C package/network/config/firewall4 compile
 make[3] -C package/system/fstools compile
 make[3] -C package/utils/e2fsprogs compile
 make[3] -C package/utils/f2fs-tools compile
 make[3] -C package/base-files compile
 make[3] -C package/system/procd compile
 make[3] -C package/utils/f2fs-tools compile
 make[3] -C package/boot/grub2 compile
 make[3] -C package/boot/grub2 compile
 make[2] package/install
 make[2] target/install
 make[3] -C target/linux install
 make[2] package/index
 make[2] json_overview_image_info
 make[2] checksum

Here you see the size of staging_dir

du -h -d1 | sort -h
4.0K	./.devcontainer
56K	./LICENSES
76K	./.github
88K	./config
532K	./include
1.4M	./toolchain
1.6M	./tools
2.2M	./scripts
17M	./package
61M	./target
72M	./bin
76M	./tmp
191M	./feeds
211M	./.git
380M	./staging_dir
645M	./dl
5.8G	./build_dir
7.4G	.

I think that's normal. If you were building toolchain components I believe your output will show lines like:

 make[3] -C toolchain/gdb compile
 make[3] -C toolchain/binutils compile
 make[3] -C toolchain/gcc/initial compile
 make[3] -C toolchain/kernel-headers compile