Commit Graph

12 Commits

Author SHA1 Message Date
Jeffery To 0dfc1b508d
rust: Use make's jobserver when building packages
This allows cargo to use make's jobserver when building packages, by
marking the cargo command as recursive (with the + prefix[1]) and
setting MAKEFLAGS.

This also:

* Give cargo/x.py the build directory instead of having to change the
  current directory (and opening subshells)

* Set PKG_BUILD_PARALLEL/HOST_BUILD_PARALLEL for Rust packages to enable
  the use of make's jobserver

[1]: https://www.gnu.org/software/make/manual/html_node/POSIX-Jobserver.html

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-10-11 15:50:24 +08:00
Jeffery To 9db7284d58
rust: Consolidate cargo environment variables
This consolidates all environment variables for cargo into:

* CARGO_HOST_CONFIG_VARS / CARGO_PKG_CONFIG_VARS

  These contain all cargo-specific environment variables, i.e. without
  "common" variables like CC.

* CARGO_HOST_VARS / CARGO_PKG_VARS (renamed from CARGO_VARS)

  These contain all environment variables to be passed to cargo.

This also:

* Set the CARGO_BUILD_TARGET environment variable instead of using the
  --target command-line option

* Update Python include files to use CARGO_HOST_CONFIG_VARS /
  CARGO_PKG_CONFIG_VARS

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-10-11 15:50:23 +08:00
Jeffery To 5c5123f0f6
rust: Move cargo config options into environment variables
This also:

* Modify the "release" profile in place of adding the "stripped" profile

  Only the profile for target is modified; there are no file size
  constraints for host.

* For host, build with the "release" profile

* For target, build with either the "dev" or "release" profile based on
  CONFIG_DEBUG

There is no environment variable to specify the "strip" option, but
enabling this option is not necessary as the build system will already
strip binaries based on CONFIG_NO_STRIP / CONFIG_USE_STRIP /
CONFIG_USE_SSTRIP.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-10-11 15:50:23 +08:00
Jeffery To 49aaf19c65
rust: Install to $(STAGING_DIR)/host
This allows rustc/cargo/etc to be called without having to set PATH, as
$(STAGING_DIR)/host/bin is already in PATH.

This also fixes CARGO_HOME not being set during Host/Configure and
Host/Compile.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-10-11 15:50:22 +08:00
Jeffery To 37762abcb4
rust: Set rustflags by environment variable
In order to use $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR, the line to
include rust-values.mk in the Rust makefile was moved in
f489e019ac, causing it to be included
before package.mk is included.

This had the side effect of preventing "-lssp_nonshared" from being
added to RUSTC_LDFLAGS, because PKG_SSP is indirectly set by package.mk
(package.mk includes hardening.mk, hardening.mk sets PKG_SSP).

There is a deeper issue; it is the Rust package's PKG_SSP value that
causes RUSTC_LDFLAGS to be set and written to the Cargo config file. For
packages that use Rust to build, their PKG_SSP value does not affect the
linker flag.

This sets rustflags with the RUSTFLAGS environment variable, instead of
writing the value to the Cargo config file, allowing PKG_SSP from the
package being built to be used and for the package being built to modify
the rustflags used.

This also:

* Fix "-lssp_nonshared" being added to TARGET_CFLAGS instead of
  RUSTC_LDFLAGS, when CONFIG_PKG_CC_STACKPROTECTOR_STRONG is set.

* Remove the use of $(RUSTC_TARGET_ARCH) in HOST_BUILD_DIR and move the
  include line for rust-values.mk back to after package.mk.

  Since the host build directory was moved under the target build
  directory in efdbac38dc, it is no longer
  necessary to separate build directories with RUSTC_TARGET_ARCH;
  $(BUILD_DIR) already separates build directories by target.

* Add BUILDONLY:=1, as the Rust package does not build a target package.

* Install the Cargo config file as "config.toml" instead of "config", as
  this is the preferred form[1].

* Rename RUST_CFLAGS to RUSTC_CFLAGS and CONFIG_HOST_SUFFIX to
  RUSTC_HOST_SUFFIX, for consistency.

* Allow CARGO_VARS to be set before rust-values.mk is included.

[1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

Fixes: f489e019ac ("rust: compile host package per target")
Fixes: 83785a7ce0 ("rust-lang: Add the rust language support")
Fixes: https://github.com/openwrt/packages/issues/22133

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-18 09:30:56 +08:00
Jeffery To 985738b399
rust: Move RUST_ARCH_DEPENDS into rust-values.mk
This allows other packages access to RUST_ARCH_DEPENDS by including
rust-values.mk, instead of rust-package.mk which also sets
Build/Compile.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-09-13 04:27:11 +08:00
Tianling Shen 7ace3bb7d6
rust: enable riscv64 support
rust natively supports riscv64 so let's enable it.

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2023-06-07 19:17:08 +08:00
Oskari Rauta 49782b3db4 rust: update to 1.68.1
also add new variable CARGO_VARS to make it possible
to pass environment variables for cargo process.
This is necessary when for example, cross-compiling
netavark.

Signed-off-by: Oskari Rauta <oskari.rauta@gmail.com>
2023-03-31 03:35:41 +08:00
Tianling Shen e7016bb4bc rust: refactor build helper
Added new RustBinPackage, RustBinHostBuild wrapper.
Added new RUST_PKG_FEATURES flag.
Moved CARGO_HOME to STAGING_DIR_HOSTPKG.
Overrode default Build/Compile and Host/Compile to Cargo build.

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2023-03-24 02:08:47 +08:00
Luca Barbato 2d3e0da711 rust-lang: Add an Host/Compile helper as well
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2023-03-10 14:24:16 +00:00
Luca Barbato 44d1d22a16 rust-lang: Apply suggestions from code review
Co-authored-by: Tianling Shen <cnsztl@gmail.com>
Signed-off-by: Luca Barbato <luca.barbato@gmail.com>
2023-03-10 14:24:16 +00:00
Luca Barbato 83785a7ce0 rust-lang: Add the rust language support
Based on work from Donald Hoskins <grommish@gmail.com>.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2023-03-10 14:24:16 +00:00