mirror of https://github.com/openwrt/openwrt.git
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> |
||
|---|---|---|
| .. | ||
| config | ||
| flashing | ||
| aruba-header.py | ||
| belkin-header.py | ||
| brcmImage.pl | ||
| build-time-log.sh | ||
| build-time-report.pl | ||
| bundle-libraries.sh | ||
| cache-run.sh | ||
| 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 | ||
| download-check-artifact.sh | ||
| download.pl | ||
| dump-target-info.pl | ||
| env | ||
| ext-toolchain.sh | ||
| ext-tools.sh | ||
| feeds | ||
| fit-add-avm-header.sh | ||
| fixup-makefile.pl | ||
| functions.sh | ||
| gen-cargo-vendor-tarball.sh | ||
| gen-dependencies.sh | ||
| gen_image_generic.sh | ||
| gen_netgear_rootfs_node.sh | ||
| get_source_date_epoch.sh | ||
| getver.sh | ||
| ipkg-build | ||
| ipkg-make-index.sh | ||
| ipkg-remove | ||
| json_add_image_info.py | ||
| json_overview_image_info.py | ||
| kconfig-reorder.sh | ||
| kconfig.pl | ||
| kernel_bump.sh | ||
| linksys-image.sh | ||
| make-index-json.py | ||
| make-ipkg-dir.sh | ||
| make-sbom.py | ||
| md5sum | ||
| mercusys-fwup.py | ||
| metadata.pm | ||
| mkhash.c | ||
| mkits-avm-container.sh | ||
| mkits-qsdk-ipq-image.sh | ||
| mkits-zyxel-fit-filogic.sh | ||
| mkits-zyxel-fit.sh | ||
| mkits.sh | ||
| moxa-encode-fw.py | ||
| nand-fwupgradecfg-gen.sh | ||
| netgear-encrypted-factory.py | ||
| noop.sh | ||
| om-fwupgradecfg-gen.sh | ||
| package-metadata.pl | ||
| pad_image | ||
| patch-kernel.sh | ||
| patch-specs.sh | ||
| portable_date.sh | ||
| projectsmirrors.json | ||
| qemustart | ||
| redboot-script.pl | ||
| relink-lib.sh | ||
| remote-gdb | ||
| rstrip.sh | ||
| rust-cc-wrapper.sh | ||
| rust-target-wrapper.sh | ||
| 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 | ||
| time.pl | ||
| timestamp.pl | ||
| tplink-mkimage-2022.py | ||
| tplink-re700x-factory.py | ||
| ubinize-image.sh | ||
| xxdi.pl | ||