For Rust from source:
This includes the Makefile, menuconfig entries, etc.
Rust Makefile
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=rust
PKG_VERSION:=1.49.0
PKG_RELEASE:=1
PKG_LICENSE:=Apache-2.0 MIT
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/rust-lang/rust.git
PKG_SOURCE_DATE:=2020-10-18
#PKG_SOURCE_VERSION:=c71248b70870960af9993de4f31d3cba9bbce7e8
#PKG_SOURCE_VERSION:=19356453cbfb734bc60a1853c10e3095d05e0342
PKG_SOURCE_VERSION:=b6ac411f45d38d867ce9f689bbd5c3e7456d0f65
PKG_HASH:=skip
PKG_HOST_ONLY:=1
#PKG_INSTALL:=1
include $(INCLUDE_DIR)/cmake.mk
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk
include ./rustc-triple.mk
#include ../../lang/python/python3-package.mk
HOST_BUILD_DEPENDS:=ninja/host python3/host
define Package/rust
SECTION:=lang
CATEGORY:=Languages
TITLE:=Rust Programming Language Compiler
URL:=https://www.rust-lang.org/
DEPENDS:=+python3 +ninja +pkg-config +libopenssl +openssl-util +libyaml +libyaml-cpp +python3-yaml
endef
define Package/rust/description
Rust lang
endef
define Package/rust/config
source "$(SOURCE)/Config.in"
endef
CMAKE_INSTALL:=1
RUSTC_TARGET_ARCH:=mips64-unknown-linux-muslabi64
# Basic Configuration Args that are used across all builds.
# Other build arguments are found in ./rustc-config.mk
#
# Default CONFIGURE_ARGS introduces unknown options - Use this instead
CONFIGURE_ARGS = \
--build=$(RUSTC_HOST_ARCH) \
--host=$(RUSTC_HOST_ARCH) \
--target=$(RUSTC_TARGET_ARCH) \
--prefix=$(CARGO_HOME) \
--bindir=$(CARGO_HOME)/bin \
--libdir=$(CARGO_HOME)/lib \
--sysconfdir=$(CARGO_HOME)/etc \
--datadir=$(CARGO_HOME)/share \
--localstatedir=/var \
--mandir=$(CARGO_HOME)/man \
--infodir=$(CARGO_HOME)/info \
--release-channel=experimental
include ./rustc-config.mk
define Host/Prepare
$(call Host/Prepare/Default)
# Allows outside packages to call $(BUILD_DIR_HOST)/rust as the dir
# rather than needing the version number.
[ -L $(BUILD_DIR_HOST)/rust ] || (cd $(BUILD_DIR_HOST); ln -s "$(PKG_NAME)-$(PKG_VERSION)" rust)
# This is our $CARGO_HOME, so make sure it's there to receive files
[ -d $(CARGO_HOME) ] || (mkdir -p $(CARGO_HOME))
[ -d $(RUSTUP_HOME) ] || (mkdir -p $(RUSTUP_HOME))
endef
define Host/Configure
# Required because OpenWrt Default CONFIGURE_ARGS contain extra
# args that cause errors
cd $(HOST_BUILD_DIR) && RUST_BACKTRACE=1 ./configure $(CONFIGURE_ARGS)
endef
define Host/Compile
cd $(HOST_BUILD_DIR) && RUST_BACKTRACE=1 $(PYTHON) x.py dist library/std src/librustc
cd $(HOST_BUILD_DIR) && RUST_BACKTRACE=1 $(PYTHON) x.py install \
--build=$(RUSTC_HOST_ARCH) \
--host=$(RUSTC_HOST_ARCH) \
--target=$(RUSTC_TARGET_ARCH)
endef
define Host/Clean
$(call Host/Clean/Default)
rm -rf $(CARGO_HOME) $(RUSTUP_HOME) $(BUILD_DIR_HOST)/rust
endef
define Host/InstallDev
true
endef
define Package/install
true
endef
$(eval $(call HostBuild))
$(eval $(call BuildPackage,rust))
Rust rustc-triple.mk
# To enable rustc/cargo support in your packages, add:
# include $(TOPDIR)/feeds/packages/lang/rustup/rustc-triple.mk
# below include $(TOPDIR)/rules.mk
#
# You will need to add --host=$(RUSTC_TARGET_ARCH) to your packages
# CONFIGURE_VARS to cross-compile for the target architecture
RUSTC_ARCH_TARGETS:= \
aarch64-unknown-linux-gnu aarch64-unknown-linux-musl \
\
arm-unknown-linux-gnueabi arm-unknown-linux-gnueabihf \
arm-unknown-linux-musleabi arm-unknown-linux-musleabihf \
\
armv4t-unknown-linux-gnueabi \
\
armv5te-unknown-linux-gnueabi armv5te-unknown-linux-musleabi \
\
armv7-unknown-linux-gnueabi armv7-unknown-linux-gnueabihf \
armv7-unknown-linux-musleabi \
\
hexagon-unknown-linux-musl \
\
i586-unknown-linux-gnu i586-unknown-linux-musl \
\
i686-unknown-linux-gnu i686-unknown-linux-musl \
\
mips-unknown-linux-gnu mips-unknown-linux-musl mips-unknown-linux-uclibc \
\
mips64-unknown-linux-gnuabi64 mips64-unknown-linux-muslabi64 \
mips64-unknown-linux-gnuabi64sf mips64-unknown-linux-muslabi64sf \
\
mips64el-unknown-linux-gnuabi64 mips64el-unknown-linux-muslabi64 \
\
mipsel-unknown-linux-gnu mipsel-unknown-linux-musl \
mipsel-unknown-linux-uclibc \
\
mipsisa32r6-unknown-linux-gnu mipsisa32r6el-unknown-linux-gnu \
\
mipsisa64r6-unknown-linux-gnuabi64 mipsisa64r6el-unknown-linux-gnuabi64 \
\
powerpc-unknown-linux-gnu powerpc-unknown-linux-musl \
\
powerpc64-unknown-linux-gnu powerpc64-unknown-linux-musl \
\
powerpc64le-unknown-linux-gnu powerpc64le-unknown-linux-musl \
\
riscv64gc-unknown-linux-gnu \
\
s390x-unknown-linux-gnu \
\
sparc-unknown-linux-gnu \
\
sparc64-unknown-linux-gnu \
\
thumbv7neon-unknown-linux-gnueabihf thumbv7neon-unknown-linux-musleabihf \
\
x86_64-unknown-linux-gnu x86_64-unknown-linux-musl
CONFIG_HOST_SUFFIX:=$(shell cut -d"-" -f4 <<<"$(GNU_HOST_NAME)")
RUSTC_HOST_ARCH:= \
$(strip $(foreach \
v, \
$(filter $(HOST_ARCH)-%, $(RUSTC_ARCH_TARGETS)), \
$(if $(findstring -$(CONFIG_HOST_SUFFIX:"%"=%),$v),$v) \
) \
)
RUSTC_TARGET_ARCH_BASE:= \
$(strip $(foreach \
v, \
$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), \
$(if $(findstring -$(CONFIG_TARGET_SUFFIX:"%"=%),$v),$v) \
) \
)
# Check to see if it's a soft-float target
ifeq ($(CONFIG_SOFT_FLOAT),y)
RUSTC_TARGET_ARCH:=$(strip $(filter %sf, $(RUSTC_TARGET_ARCH_BASE)))
else
RUSTC_TARGET_ARCH:=$(strip $(filter-out %sf, $(RUSTC_TARGET_ARCH_BASE)))
endif
# More than one triple-target remains.
ifneq ($(word 2, $(RUSTC_TARGET_ARCH)),)
$(error RUSTC ERROR: Unsupported or Unknown Target Triple: $(RUSTC_TARGET_ARCH))
endif
# These are environment variables that are used by other packages to
# define where rustc/cargo are kept.
CARGO_HOME:=$(BUILD_DIR_HOST)/.cargo
RUSTUP_HOME:=$(BUILD_DIR_HOST)/.rustup
Rust rustc-config.mk:
ifeq ($(CONFIG_RUST_DEBUG),y)
CONFIGURE_ARGS += --enable-debug
endif
ifeq ($(CONFIG_RUST_DOCS),y)
CONFIGURE_ARGS += --enable-docs
else
CONFIGURE_ARGS += --disable-docs
endif
ifeq ($(CONFIG_RUST_COMPILER_DOCS),y)
CONFIGURE_ARGS += --enable-compiler-docs
else
CONFIGURE_ARGS += --disable-compiler-docs
endif
ifeq ($(CONFIG_RUST_OPTIMIZE_TESTS),y)
CONFIGURE_ARGS += --enable-optimize-tests
endif
ifeq ($(CONFIG_RUST_PARALLEL),y)
CONFIGURE_ARGS += --enable-parallel-compiler
endif
ifeq ($(CONFIG_RUST_VERBOSE_TESTS),y)
CONFIGURE_ARGS += --enable-verbose-tests
endif
ifeq ($(CONFIG_RUST_CCACHE),y)
CONFIGURE_ARGS += --enable-ccache
endif
ifeq ($(CONFIG_RUST_LLVM_STATIC),y)
CONFIGURE_ARGS += --enable-llvm-static-stdcpp
endif
ifeq ($(CONFIG_RUST_LLVM_SHARED),y)
CONFIGURE_ARGS += --enable-llvm-link-shared
endif
ifeq ($(CONFIG_RUST_CODEGEN_TESTS),y)
CONFIGURE_ARGS += --enable-codegen-tests
endif
ifeq ($(CONFIG_RUST_OPTION_CHECKING),y)
CONFIGURE_ARGS += --enable-option-checking
endif
ifeq ($(CONFIG_RUST_ENABLE_NINJA),y)
CONFIGURE_ARGS += --enable-ninja
endif
ifeq ($(CONFIG_RUST_LOCKED_DEPS),y)
CONFIGURE_ARGS += --enable-locked-deps
endif
ifeq ($(CONFIG_RUST_VENDOR),y)
CONFIGURE_ARGS += --enable-vendor
endif
ifeq ($(CONFIG_RUST_SANITIZERS),y)
CONFIGURE_ARGS += --enable-sanitizers
endif
ifeq ($(CONFIG_RUST_DIST_SRC),y)
CONFIGURE_ARGS += --enable-dist-src
endif
ifeq ($(CONFIG_RUST_CARGO_NATIVE_STATIC),y)
CONFIGURE_ARGS += --enable-cargo-native-static
endif
ifeq ($(CONFIG_RUST_PROFILER),y)
CONFIGURE_ARGS += --enable-profiler
endif
ifeq ($(CONFIG_RUST_FULL_TOOLS),y)
CONFIGURE_ARGS += --enable-full-tools
endif
ifeq ($(CONFIG_RUST_MISSING_TOOLS),y)
CONFIGURE_ARGS += --enable-missing-tools
endif
ifeq ($(CONFIG_RUST_USE_LIBCXX),y)
CONFIGURE_ARGS += --enable-use-libcxx
endif
ifeq ($(CONFIG_RUST_CONTROL_FLOW_GUARD),y)
CONFIGURE_ARGS += --enable-control-flow-guard
endif
ifeq ($(CONFIG_RUST_LLVM_LIB_UNWIND),y)
CONFIGURE_ARGS += --enable-llvm-libunwind
endif
ifeq ($(CONFIG_RUST_OPTIMIZE),y)
CONFIGURE_ARGS += --enable-optimize
endif
ifeq ($(CONFIG_RUST_OPTIMIZE_LLVM),y)
CONFIGURE_ARGS += --enable-optimize-llvm
endif
ifeq ($(CONFIG_RUST_LLVM_ASSERTIONS),y)
CONFIGURE_ARGS += --enable-llvm-assertions
endif
ifeq ($(CONFIG_RUST_DEBUG_ASSERTIONS),y)
CONFIGURE_ARGS += --enable-debug-assertions
endif
ifeq ($(CONFIG_RUST_LLVM_RELEASE_DEBUGINFO),y)
CONFIGURE_ARGS += --enable-llvm-release-debuginfo
endif
ifeq ($(CONFIG_RUST_MANAGE_SUBMODULES),y)
CONFIGURE_ARGS += --enable-manage-submodules
endif
ifeq ($(CONFIG_RUST_FULL_BOOTSTRAP),y)
CONFIGURE_ARGS += --enable-full-bootstrap
endif
ifeq ($(CONFIG_LIBC),"musl")
CONFIGURE_ARGS += \
--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_DIR)
endif
Rust Config.in:
# Rust Language Options
menu "Compiler Options"
depends on PACKAGE_rust
config RUST_DEBUG
bool "Enables Debugging Environment (--enable-debug)"
default n
config RUST_DOCS
bool "Build standard library documentation (--enable-docs)"
default n
config RUST_COMPILER_DOCS
bool "Build compiler documentation (--enable-compiler-docs)"
default n
config RUST_OPTIMIZE_TESTS
bool "Build tests with optimizations (--enable-optimized-tests)"
default n
config RUST_PARALLEL
bool "Build with multi-threaded support (--enable-parallel-compiler)"
default n
config RUST_VERBOSE_TESTS
bool "Enable verbose output when running tests (--enable-verbose-tests)"
default n
config RUST_CCACHE
bool "Build with ccache enabled (--enable-ccache)"
default n
config RUST_LLVM_STATIC
bool "Statically link to libstdc++ to LLVM (--enable-llvm-static-stdccp)"
default n
config RUST_LLVM_SHARED
bool "Prefer shared linking to LLVM (--enable-llvm-link-shared)"
default n
config RUST_CODEGEN_TESTS
bool "Run the src/test/codegen tests (--enable-codegen-tests)"
default n
config RUST_OPTION_CHECKING
bool "Complain about unrecognized options in this configure script (--enable-option-checking)"
default y
config RUST_ENABLE_NINJA
bool "Build LLVM using the Ninja generator (--enable-ninja)"
default y
config RUST_LOCKED_DEPS
bool "Force Cargo.lock to be up to date (--enable-locked-deps)"
default n
config RUST_VENDOR
bool "Enable usage of vendored Rust crates (--enable-vendor)"
default n
config RUST_SANITIZERS
bool "Build the sanitizer runtimes (asan, lsan, msan, tsan) (--enable-sanitizers)"
default n
config RUST_DIST_SRC
bool "When building tarballs enables building a source tarball (--enable-dist-src)"
default n
config RUST_CARGO_NATIVE_STATIC
bool "Build static native libraries in Cargo (--enable-cargo-native-static)"
default n
config RUST_PROFILER
bool "Build the profiler runtime (--enable-profiler)"
default n
config RUST_FULL_TOOLS
bool "Build all tools (--enable-full-tools)"
default n
config RUST_MISSING_TOOLS
bool "Allow failures when building tools (--enable-missing-tools)"
default y
config RUST_USE_LIBCXX
bool "Build LLMV with libc++ (--enable-use-libcxx)"
default n
config RUST_CONTROL_FLOW_GUARD
bool "Enable Control Flow Guard (--enable-control-flow-guard)"
default n
config RUST_LLVM_LIB_UNWIND
bool "Use LLVM libunwind (--enable-llvm-libunwind)"
default n
config RUST_OPTIMIZE
bool "Build optimized rust code (--enable-optimize)"
default n
config RUST_OPTIMIZE_LLVM
bool "Build optimized LLVM (--enable-optimize-llvm)"
default n
config RUST_LLVM_ASSERTIONS
bool "Build LLVM with assertions (--enable-llvm-assertions)"
default n
config RUST_DEBUG_ASSERTIONS
bool "Build with debugging assertions (--enable-debug-assertions)"
default n
config RUST_LLVM_RELEASE_DEBUGINFO
bool "Build LLVM with debugger metadata (--enable-llvm-release-debuginfo)"
default n
config RUST_MANAGE_SUBMODULES
bool "Let the build manage the git submodules (--enable-manage-submodules)"
default y
config RUST_FULL_BOOTSTRAP
bool "Full Bootstrap - Build three compilers instead of two (--enable-full-bootstrap)"
default y
endmenu