openwrt/scripts
Daniel Golle 32f1c26eb6 build: add Rust package build helpers
Add rust-package.mk for target packages written in Rust. The Cargo
environment carries the target triple, CPU flags, the C and C++ flags
for cc-rs, the linker and the ABI-specific sysroot of libstd-rust,
while native build scripts and proc macros keep the host sysroot and
linker. Builds run in the crate's working directory with an explicit
target and offline from the vendor tarball; with a source tree override
(git-src, USE_SOURCE_DIR), which has none, Cargo fetches the locked
crates. Target packages depend on libstd-rust at build time and track
its configuration inputs for rebuilds.

rustc runs the linker with arguments of its own, without TARGET_LDFLAGS.
The linker selection and the -z options that hardening.mk and
package.mk set for every package are passed to rustc, for packages and
for libstd-rust.

When the target triple is the build host's, cc-rs takes the host
compiler for target C code as well. For that triple the C and C++
compiler of cc-rs is scripts/rust-cc-wrapper.sh, linked into
$(STAGING_DIR_HOST)/bin by tools/rust. It runs the target compiler with
the target flags for build scripts whose OUT_DIR lies in the target
triple's directory, and the host compiler for the others.

RUST_PREFER_DYNAMIC is available with any Rust toolchain, controls the
default userspace standard-library linkage and defaults to shared
linking. Packages can override it. Release builds use LTO either way;
rustc runs LTO next to -Cprefer-dynamic only with the unstable
-Zdylib-lto. RUST_PKG_DEPENDS carries the architecture dependencies
and, with shared linking, the libstd-rust runtime dependency. For
packages that keep the default, that dependency is conditional on
RUST_PREFER_DYNAMIC, as .config is not read while package metadata is
collected.

Release builds emit no unwind tables and take the size options of
unstable rustc that libstd-rust is built with: panics without location,
derived Debug output reduced to type names and, with
RUST_PANIC_IMMEDIATE_ABORT, -Cpanic=immediate-abort. Permitting unstable
options for every crate with RUSTC_BOOTSTRAP=1 changes the code of
dependencies: the build scripts of anyhow, thiserror and proc-macro2
then detect unstable features and use them.
scripts/rust-target-wrapper.sh, the RUSTC_WRAPPER of package builds,
adds the options, and -Zdylib-lto with a shared libstd, only to the
target crates cargo compiles, recognised by --target, -C metadata and
--error-format=json, and permits unstable options for that crate alone.
Build scripts and their probes see neither. A package keeps panic
locations with RUST_PKG_LOCATION_DETAIL:=1 and selects the Debug output
with RUST_PKG_FMT_DEBUG. None of this applies with CONFIG_DEBUG.
Packages build the release profile, as maturin, CMake and autotools
projects do, and CONFIG_DEBUG gives it the settings of the dev profile,
ahead of the profile settings of the package. Build paths are mapped out
of packages as out of libstd-rust.

Without a Rust toolchain of the build system, Rust packages build with
rust/host of the packages feed, which installs to $(STAGING_DIR)/host,
so that packages can move from the Rust support of the packages feed
one at a time. RUSTC and CARGO point there, there is neither a sysroot
of libstd-rust nor a shared libstd, the mips64 triples are those its
std is built for, and on the build host's triple the target linker is
set through the Cargo variable. The build dependencies, on libstd-rust
or rust/host, follow USE_RUST_TOOLCHAIN in the package metadata, also
for host builds through rust-host-build.mk. After a switch from None to
a Rust toolchain, the cargo of rust/host still comes first in PATH, so
the help of the toolchain choice names its clean-up.

The file is derived from lang/rust in the packages feed by Luca Barbato
and Donald Hoskins.

Reported-by: Andre Heider <a.heider@gmail.com>
Co-developed-by: Brian Redbeard <redbeard@dead-city.org>
Signed-off-by: Brian Redbeard <redbeard@dead-city.org>
Co-developed-by: Aditya Nugraha <vortexilation@gmail.com>
Signed-off-by: Aditya Nugraha <vortexilation@gmail.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2026-10-30 12:06:08 +02:00
..
config
…
flashing scripts: eva_ramboot: make memory addresses configurable 2026-10-18 13:14:19 +02:00
aruba-header.py ipq806x: add support for Aruba AP-32x 2026-06-16 16:08:08 +02:00
belkin-header.py realtek: take the Belkin header time from SOURCE_DATE_EPOCH 2026-09-24 13:36:49 +02:00
brcmImage.pl
…
build-time-log.sh build: add per stage build time profiling 2026-09-22 18:18:58 +02:00
build-time-report.pl build: add per stage build time profiling 2026-09-22 18:18:58 +02:00
bundle-libraries.sh
…
cache-run.sh build: reuse the output of slow compression steps 2026-09-22 18:18:58 +02:00
cameo-imghdr.py
…
cameo-tag.py
…
cfe-bin-header.py
…
cfe-partition-tag.py
…
cfe-wfi-tag.py
…
check-toolchain-clean.sh
…
checkpatch.pl
…
clean-package.sh
…
cleanfile
…
cleanpatch
…
combined-ext-image.sh
…
combined-image.sh
…
command_all.sh
…
config.guess
…
config.rpath
…
config.sub
…
const_structs.checkpatch
…
deptest.sh
…
diffconfig.sh
…
dl_cleanup.py
…
dl_github_archive.py scripts: dl_github_archive: fix zstd args passed to tar 2026-07-28 09:30:22 +02:00
download-check-artifact.sh
…
download.pl scripts/download.pl: delete local file with hash mismatch 2026-09-22 18:18:58 +02:00
dump-target-info.pl
…
env
…
ext-toolchain.sh ext-toolchain: fix wrapper for gcc-ar, gcc-nm, gcc-ranlib 2026-02-06 17:32:06 +01:00
ext-tools.sh scripts/ext-tools.sh: refresh the stamps with a sub-second timestamp 2026-10-06 02:05:39 +02:00
feeds scripts: feeds: don't refresh .config upon update 2026-07-07 09:03:33 +02:00
fit-add-avm-header.sh qualcommax: ipq50xx: add AVM FRITZ!Box 4050 2026-10-18 13:14:19 +02:00
fixup-makefile.pl
…
functions.sh
…
gen-cargo-vendor-tarball.sh build: add cargo vendor download methods 2026-10-30 12:06:08 +02:00
gen-dependencies.sh
…
gen_image_generic.sh
…
gen_netgear_rootfs_node.sh filogic: add support for Netgear EAX17 2025-11-24 00:57:19 +01:00
get_source_date_epoch.sh
…
getver.sh
…
ipkg-build build: derive PKG_SOURCE_DATE_EPOCH from the unpacked source tree 2026-06-02 11:51:00 +02:00
ipkg-make-index.sh
…
ipkg-remove
…
json_add_image_info.py
…
json_overview_image_info.py scripts: add git_commit to profiles.json 2026-04-21 19:47:58 +08:00
kconfig-reorder.sh
…
kconfig.pl
…
kernel_bump.sh scripts/kernel_bump: adjust commit messages 2025-12-09 00:06:07 +01:00
linksys-image.sh image: create the archive images with fixed metadata 2026-09-22 18:46:30 +02:00
make-index-json.py scripts/make-index-json: ensure that manifest output is in opkg format 2025-11-01 19:42:20 +01:00
make-ipkg-dir.sh
…
make-sbom.py build: create reproducible CycloneDX SBOMs 2026-09-22 18:46:30 +02:00
md5sum
…
mercusys-fwup.py scripts: add Mercusys fwup image generator 2026-10-02 11:09:30 +02:00
metadata.pm build: allow packages to build their variants in parallel 2026-09-22 18:18:58 +02:00
mkhash.c
…
mkits-avm-container.sh qualcommax: ipq50xx: add AVM FRITZ!Box 4050 2026-10-18 13:14:19 +02:00
mkits-qsdk-ipq-image.sh scripts: mkits-qsdk-ipq-image: strip path from description 2026-10-27 06:19:26 +00:00
mkits-zyxel-fit-filogic.sh
…
mkits-zyxel-fit.sh
…
mkits.sh scripts/mkits.sh: move out .pagesync generation for RootFS blob 2025-10-23 18:14:01 +02:00
moxa-encode-fw.py
…
nand-fwupgradecfg-gen.sh ramips: add support for Plasma Cloud PAX1800-Lite 2025-10-04 20:30:36 +02:00
netgear-encrypted-factory.py
…
noop.sh
…
om-fwupgradecfg-gen.sh
…
package-metadata.pl package-metadata: drop self-referencing rank from depends-on gates 2026-10-02 14:13:40 +01:00
pad_image
…
patch-kernel.sh
…
patch-specs.sh
…
portable_date.sh
…
projectsmirrors.json projectsmirrors: remove GNOME mirrors mirror.csclub.uwaterloo.ca 2026-08-02 15:02:33 +02:00
qemustart scripts: add --user-network to qemustart 2026-05-21 16:06:25 +02:00
redboot-script.pl
…
relink-lib.sh
…
remote-gdb
…
rstrip.sh
…
rust-cc-wrapper.sh build: add Rust package build helpers 2026-10-30 12:06:08 +02:00
rust-target-wrapper.sh build: add Rust package build helpers 2026-10-30 12:06:08 +02:00
sercomm-crypto.py
…
sercomm-kernel-header.py
…
sercomm-partition-tag.py
…
sercomm-payload.py
…
sercomm-pid.py
…
sign_images.sh
…
size_compare.sh
…
slugimage.pl
…
spelling.txt
…
srecimage.pl
…
strip-kmod.sh
…
symlink-tree.sh
…
sysupgrade-tar.sh
…
target-metadata.pl build: remove the AUDIO_SUPPORT and DISPLAY_SUPPORT symbols 2026-09-29 15:29:43 +01:00
time.pl
…
timestamp.pl build: let find answer the rebuild question 2026-09-22 18:18:58 +02:00
tplink-mkimage-2022.py
…
tplink-re700x-factory.py qualcommax: add support for TP-Link RE700X 2026-10-03 20:17:43 +02:00
ubinize-image.sh
…
xxdi.pl
…