-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another attempt to support the rust language #19863
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
472983a
rust-lang: Add the rust language support
lu-zero 1accb44
ripgrep: Add the package
lu-zero 8624cce
maturin: Add package
lu-zero ba1482b
rust-lang: Apply suggestions from code review
lu-zero e778b32
rust-lang: Add an Host/Compile helper as well
lu-zero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Rust Language Options | ||
menu "Compiler Options" | ||
visible if PACKAGE_rust | ||
|
||
config RUST_DEBUG | ||
bool "Enables Debugging Environment (--enable-debug)" | ||
|
||
config RUST_DOCS | ||
bool "Build standard library documentation (--enable-docs)" | ||
|
||
config RUST_COMPILER_DOCS | ||
bool "Build compiler documentation (--enable-compiler-docs)" | ||
|
||
config RUST_OPTIMIZE_TESTS | ||
bool "Build tests with optimizations (--enable-optimized-tests)" | ||
|
||
config RUST_PARALLEL | ||
bool "Build with multi-threaded support (--enable-parallel-compiler)" | ||
|
||
config RUST_VERBOSE_TESTS | ||
bool "Enable verbose output when running tests (--enable-verbose-tests)" | ||
|
||
config RUST_CCACHE | ||
bool "Build with ccache enabled (--enable-ccache)" | ||
|
||
config RUST_LLVM_STATIC | ||
bool "Statically link to libstdc++ to LLVM (--enable-llvm-static-stdccp)" | ||
|
||
config RUST_LLVM_SHARED | ||
bool "Prefer shared linking to LLVM (--enable-llvm-link-shared)" | ||
|
||
config RUST_CODEGEN_TESTS | ||
bool "Run the src/test/codegen tests (--enable-codegen-tests)" | ||
|
||
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)" | ||
|
||
config RUST_VENDOR | ||
bool "Enable usage of vendored Rust crates (--enable-vendor)" | ||
|
||
config RUST_SANITIZERS | ||
bool "Build the sanitizer runtimes (asan, lsan, msan, tsan) (--enable-sanitizers)" | ||
|
||
config RUST_DIST_SRC | ||
bool "When building tarballs enables building a source tarball (--enable-dist-src)" | ||
|
||
config RUST_CARGO_NATIVE_STATIC | ||
bool "Build static native libraries in Cargo (--enable-cargo-native-static)" | ||
|
||
config RUST_PROFILER | ||
bool "Build the profiler runtime (--enable-profiler)" | ||
|
||
config RUST_FULL_TOOLS | ||
bool "Build all tools (--enable-full-tools)" | ||
|
||
config RUST_MISSING_TOOLS | ||
bool "Allow failures when building tools (--enable-missing-tools)" | ||
default y | ||
|
||
config RUST_USE_LIBCXX | ||
bool "Build LLVM with libc++ (--enable-use-libcxx)" | ||
|
||
config RUST_CONTROL_FLOW_GUARD | ||
bool "Enable Control Flow Guard (--enable-control-flow-guard)" | ||
|
||
config RUST_OPTIMIZE_LLVM | ||
bool "Build optimized LLVM (--enable-optimize-llvm)" | ||
default y | ||
|
||
config RUST_LLVM_ASSERTIONS | ||
bool "Build LLVM with assertions (--enable-llvm-assertions)" | ||
|
||
config RUST_DEBUG_ASSERTIONS | ||
bool "Build with debugging assertions (--enable-debug-assertions)" | ||
|
||
config RUST_LLVM_RELEASE_DEBUGINFO | ||
bool "Build LLVM with debugger metadata (--enable-llvm-release-debuginfo)" | ||
|
||
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)" | ||
|
||
endmenu | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# | ||
# Copyright (C) 2023 Luca Barbato and Donald Hoskins | ||
|
||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=rust | ||
PKG_VERSION:=1.67.1 | ||
PKG_RELEASE:=1 | ||
|
||
PKG_SOURCE:=rustc-$(PKG_VERSION)-src.tar.gz | ||
PKG_SOURCE_URL:=https://static.rust-lang.org/dist/ | ||
PKG_HASH:=46483d3e5de85a3bd46f8e7a3ae1837496391067dbe713a25d3cf051b3d9ff6e | ||
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/rustc-$(PKG_VERSION)-src/ | ||
|
||
PKG_MAINTAINER:=Luca Barbato <lu_zero@luminem.org> | ||
PKG_LICENSE:=Apache-2.0 MIT | ||
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT | ||
|
||
HOST_BUILD_DEPENDS:=python3/host | ||
PKG_HOST_ONLY:=1 | ||
|
||
include $(INCLUDE_DIR)/package.mk | ||
include $(INCLUDE_DIR)/host-build.mk | ||
|
||
# rust environment variables | ||
include ./rust-host.mk | ||
|
||
# Rust Temp Directory | ||
RUST_TMP_DIR:=$(TMP_DIR)/rust-install | ||
|
||
RUST_INSTALL_HOST_FILENAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_HOST_ARCH)-install.tar.xz | ||
RUST_INSTALL_TARGET_FILENAME:=$(PKG_NAME)-$(PKG_VERSION)-$(RUSTC_TARGET_ARCH)-install.tar.xz | ||
|
||
# Rust-lang has an uninstall script | ||
RUST_UNINSTALL:=$(CARGO_HOME)/lib/rustlib/uninstall.sh | ||
|
||
# Target Flags | ||
TARGET_CONFIGURE_ARGS = \ | ||
--set=target.$(RUSTC_TARGET_ARCH).ar=$(TARGET_AR) \ | ||
--set=target.$(RUSTC_TARGET_ARCH).cc=$(TARGET_CC_NOCACHE) \ | ||
--set=target.$(RUSTC_TARGET_ARCH).cxx=$(TARGET_CXX_NOCACHE) \ | ||
--set=target.$(RUSTC_TARGET_ARCH).linker=$(TARGET_CC_NOCACHE) \ | ||
--set=target.$(RUSTC_TARGET_ARCH).musl-root=$(TOOLCHAIN_DIR) \ | ||
--set=target.$(RUSTC_TARGET_ARCH).ranlib=$(TARGET_RANLIB) | ||
|
||
# CARGO_HOME is an environmental | ||
HOST_CONFIGURE_OPTS += CARGO_HOME="$(CARGO_HOME)" | ||
|
||
# Rust Configuration Arguments | ||
HOST_CONFIGURE_ARGS = \ | ||
--build=$(RUSTC_HOST_ARCH) \ | ||
--target=$(RUSTC_TARGET_ARCH),$(RUSTC_HOST_ARCH) \ | ||
--host=$(RUSTC_HOST_ARCH) \ | ||
--prefix=$(CARGO_HOME) \ | ||
--bindir=$(CARGO_HOME)/bin \ | ||
--libdir=$(CARGO_HOME)/lib \ | ||
--sysconfdir=$(CARGO_HOME)/etc \ | ||
--datadir=$(CARGO_HOME)/share \ | ||
--mandir=$(CARGO_HOME)/man \ | ||
--dist-compression-formats=xz \ | ||
--enable-llvm-link-shared \ | ||
--enable-llvm-plugins \ | ||
--enable-missing-tools \ | ||
--enable-ninja \ | ||
--disable-sanitizers \ | ||
--release-channel=stable \ | ||
--enable-cargo-native-static \ | ||
$(TARGET_CONFIGURE_ARGS) | ||
|
||
define Host/Prepare | ||
# Ensure rust temp directory | ||
[ -d $(RUST_TMP_DIR) ] || \ | ||
mkdir -p $(RUST_TMP_DIR) | ||
|
||
$(call Host/Prepare/Default) | ||
endef | ||
|
||
define Host/Uninstall | ||
# Call the Uninstall script | ||
[ -f $(RUST_UNINSTALL) ] && \ | ||
$(BASH) $(RUST_UNINSTALL) || echo No Uninstall | ||
|
||
rm -rf $(RUST_TMP_DIR) | ||
endef | ||
|
||
# Makes and then packages the dist artifacts | ||
define Host/Compile | ||
cd $(HOST_BUILD_DIR) && \ | ||
$(PYTHON) x.py --config ./config.toml dist build-manifest cargo llvm-tools \ | ||
rustc rust-std rust-src | ||
|
||
$(call Host/PackageDist) | ||
endef | ||
|
||
# Distribution Artifacts are packaged by Host/PackageDist | ||
# We just need to extract and install | ||
define Host/Install | ||
$(TAR) -C $(RUST_TMP_DIR) -xJf $(DL_DIR)/$(RUST_INSTALL_HOST_FILENAME) && \ | ||
$(TAR) -C $(RUST_TMP_DIR) -xJf $(DL_DIR)/$(RUST_INSTALL_TARGET_FILENAME) | ||
|
||
cd $(RUST_TMP_DIR) && \ | ||
find -iname "*.xz" -exec tar -xJf {} ";" && \ | ||
find ./* -type f -name install.sh -execdir sh {} --prefix=$(CARGO_HOME) --disable-ldconfig \; | ||
|
||
echo -e "[target.$(RUSTC_TARGET_ARCH)]\nlinker = \"$(TARGET_CC_NOCACHE)\"\nrustflags = [\"-Ctarget-feature=-crt-static\", \"-Clink-args=$(RUSTC_LDFLAGS)\"]" > $(CARGO_HOME)/config | ||
echo -e "\n[profile.stripped]\ninherits = \"release\"\nopt-level = \"s\"\nstrip = true" >> $(CARGO_HOME)/config | ||
endef | ||
|
||
# Packages the Distribution Artifacts into HOST and TARGET bundles. | ||
define Host/PackageDist | ||
( \ | ||
cd $(HOST_BUILD_DIR)/build/dist ; \ | ||
$(TAR) -cJf $(DL_DIR)/$(RUST_INSTALL_TARGET_FILENAME) \ | ||
rust-*-$(RUSTC_TARGET_ARCH).tar.xz ; \ | ||
$(TAR) -cJf $(DL_DIR)/$(RUST_INSTALL_HOST_FILENAME) \ | ||
--exclude rust-*-$(RUSTC_TARGET_ARCH).tar.xz *.xz ; \ | ||
) | ||
endef | ||
|
||
define Package/rust | ||
SECTION:=lang | ||
CATEGORY:=Languages | ||
TITLE:=Rust Programming Language Compiler | ||
URL:=https://www.rust-lang.org/ | ||
DEPENDS:=$(RUST_ARCH_DEPENDS) \ | ||
+pkg-config +libunwind +libopenssl +liblzma +libc | ||
endef | ||
|
||
define Package/rust/description | ||
Rust is a multi-paradigm, general-purpose programming language designed for performance | ||
and safety, especially safe concurrency. Rust is syntactically similar to C++, but can | ||
guarantee memory safety by using a borrow checker to validate references. | ||
endef | ||
|
||
define Package/rust/config | ||
source "$(SOURCE)/Config.in" | ||
endef | ||
|
||
$(eval $(call HostBuild)) | ||
$(eval $(call BuildPackage,rust)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# | ||
# Copyright (C) 2023 Luca Barbato | ||
|
||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=maturin | ||
PKG_VERSION:=0.14.10 | ||
PKG_RELEASE:=1 | ||
|
||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz | ||
PKG_SOURCE_URL:=https://codeload.github.com/PyO3/maturin/tar.gz/v$(PKG_VERSION)? | ||
PKG_HASH:=8fc9bcdcb7f1535d5e3e8bb500c348ca1bff5a6dce87b0ab7dbc5a49723da28a | ||
dangowrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
PKG_MAINTAINER:=Luca Barbato <lu_zero@luminem.org> | ||
PKG_LICENSE:=Apache-2.0 MIT | ||
PKG_LICENSE_FILES:=license-apache license-mit | ||
|
||
HOST_BUILD_DEPENDS:=rust/host | ||
PKG_BUILD_DEPENDS:=rust/host | ||
|
||
PKG_BUILD_PARALLEL:=1 | ||
PKG_HOST_ONLY:=1 | ||
|
||
include ../rust-package.mk | ||
include $(INCLUDE_DIR)/host-build.mk | ||
include $(INCLUDE_DIR)/package.mk | ||
|
||
define Package/maturin | ||
SECTION:=lang | ||
CATEGORY:=Languages | ||
SUBMENU:=Rust | ||
TITLE:=Build and publish crates as python packages | ||
DEPENDS:=$(RUST_ARCH_DEPENDS) | ||
URL:=https://maturin.rs | ||
endef | ||
|
||
define Host/Compile | ||
$(call Host/Compile/Cargo) | ||
endef | ||
|
||
define Package/maturin/description | ||
Build and publish crates with pyo3, rust-cpython, cffi and uniffi | ||
bindings as well as rust binaries as python packages. | ||
endef | ||
|
||
define Host/Install | ||
$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/bin | ||
$(INSTALL_BIN) $(HOST_INSTALL_DIR)/bin/maturin $(STAGING_DIR_HOSTPKG)/bin/maturin | ||
endef | ||
|
||
$(eval $(call HostBuild)) | ||
$(eval $(call BuildPackage,maturin)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I'm interested in rust support for openwrt and I tested your branch for a hello-world rust package.
It would be better to have to have access to build helpers outside of the feed
package
.Maybe by installing them on the host staging dir too
And use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know which is the best practice in this regard. surely it can be done that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meson was and python3 or go are examples.
Since this lives in the package feed repository, you can just put any .mk helper files in the root of this package and other packages can include the .mk file based on their own location.
See 468572a (where it still lived here before moving it to the base repo).
Or
git grep python3-package.mk
orgit grep golang-package.mk
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so it would be
$(STAGING_DIR_HOSTPKG)/lib/rust/build.mk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the approach from python/README.md is deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean the
$(TOPDIR)
part, I, and I guess all others , prefer relative paths, but both would work I guess :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meson approach copies the helper files in $(STAGING_DIR_HOSTPKG), the python approach makes you refer to the file in feeds, I'd go the meson way.
Right now I'm having absurd problems with the choice of bundling a (stale) libc but not its headers nor a compiler aware of it so I guess this issue is secondary...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meson copies itself to staging, because it's just a bunch of python scripts. It's similar to a toolchain that installs itself there. I assume your rust host package does the same.
But then there're .mk helper files, and by that I mean pure OpenWrt specific files to help creating OpenWrt runtime packages. I assumed we're talking about that, in which case the feed location is appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I misread how meson worked based on what @maximilien-baumann suggested.