1
0
mirror of https://git.openwrt.org/feed/packages.git synced 2024-06-18 13:23:57 +02:00
Commit Graph

16 Commits

Author SHA1 Message Date
Tianling Shen
9f01010958 rust: unexport host sccache env variable
Users might configure their own env variables on the host, and sometimes
it can lead build failure or unexpected behavior.

Fixes: #22889

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2024-01-01 11:04:28 +08:00
Drew Young
3d799c3eee rust: fix build with glibc, ARM and hard floats
Patch the target triple for Rust with glibc to include hard floating
point support.

The GNU target triple used elsewhere does not include hard float support,
instead `-mfloat-abi=hard` is passed separately. For Rust it must be
included in the target triple. This was already being done for musl,
this commit adds the same patching for glibc.

Without this patch Rust compilation fails with an error like this
(abbreviated to fit the line length):

    ld: error: libstd.so uses VFP register arguments, ... does not
    ld: failed to merge target specific data of file ...

Signed-off-by: Drew Young <dyoung@viridiparente.com>
2023-10-16 09:01:43 +08:00
Jeffery To
8bf2725f9b
rust: Set release profile settings
* codegen-units, lto, opt-level - Set to values to optimize binary
  size[1].

* overflow-checks - Enabled because in release mode, integer overflows
  are defined as two's complement wrap[2]. It is highly unlikely that
  any program is intentionally relying on this behaviour; it would be
  better to panic instead of continue execution in this case.

* debug, debug-assertions, panic, rpath - Set to their default (release)
  values, to override any settings made by packages, e.g. ripgrep sets
  debug = 1[3].

[1]: https://github.com/johnthagen/min-sized-rust
[2]: https://huonw.github.io/blog/2016/04/myths-and-legends-about-integer-overflow-in-rust/
[3]: https://github.com/BurntSushi/ripgrep/blob/13.0.0/Cargo.toml#L79-L80

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-10-11 15:50:24 +08:00
Jeffery To
b4ec017398
rust: Add option to use sccache
Using sccache makes recompilation of rustc and Rust packages faster.

This also makes the rust package visible in menuconfig, in order for the
sccache options to be accessible.

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
853c9c9e86
rust: Move CARGO_HOME to $(DL_DIR)/cargo
As CARGO_HOME mainly functions as a download and source cache[1], moving
it into $(DL_DIR) allows it to persist and be reused between different
buildroots/sdks (when DL_DIR is set to a custom/external location).

[1]: https://doc.rust-lang.org/cargo/guide/cargo-home.html

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
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
Jonas Jelonek
c287e98af2 rust: correct mistake in previous host-build fix
Fixes the commit 105fa3920e which was intended to make rust/host build
on aarch64 darwin working again. However, the fix contains a mistake
because it sets RUSTC_TARGET_ARCH instead of RUSTC_HOST_ARCH. Thus, the
fix doesn't work.
This properly sets the correct variable RUSTC_HOST_ARCH.

Fixes: 105fa3920e ("rust: fix host build on aarch64 darwin")
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
2023-08-19 14:26:43 +08:00
Jonas Jelonek
105fa3920e rust: fix host build on aarch64 darwin
rust/host failed to compile on macOS running on Apple Silicon M1 Pro
because the host target triple is autogenerated to be
'arm64-unknown-linux-'. Rust doesn't have such a target triple, thus the
build failes because there are no pre-built artifacts for bootstrapping.

Fix this by setting RUSTC_HOST_ARCH to 'aarch64-apple-darwin' in case
our host is HOST_ARCH=arm64 and HOST_OS=darwin.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
2023-08-17 09:39:24 +02:00
Orne Brocaar
f489e019ac rust: compile host package per target
While the compiled binaries are intended to run on the host system, the
rust/host package does include the target matching the configured
OpenWrt target.

If using (for example) ./scripts/env to switch between different
OpenWrt configurations, this will cause issues if the different
configuration is for a different target. In such case there will be a
mismatch between the available Rust target and OpenWrt target and the
following error will be printed:

> error[E0463]: can't find crate for `core`
> note: the `XXX` target may not be installed

This fix will add the RUSTC_TARGET_ARCH as HOST_BUILD_DIR and CARGO_HOME
suffix, such that rust/host will be compiled in case an OpenWrt
configuration change causes the RUSTC_TARGET_ARCH to change.

Fixes: #21530

Signed-off-by: Orne Brocaar <info@brocaar.com>
[Applied Jeffery To's suggestion for build and install path]
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2023-07-18 04:49:50 +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
bb3082a1c5 rust: fix build with glibc
Don't set musl-specific options/ldflags when using glibc.

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2023-03-24 02:08:47 +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