Skip to content

Commit 4401519

Browse files
jameshilliardhiroshiyui
authored andcommitted
package/pkg-cargo: ensure host/target rustflags are properly split
In Cargo, it is quite typical for "build scripts" to be written in Rust and therefore they need to be compiled as part of the overall build. In cross-compilation, that means a mixed host and target build. Unfortunately, by default Cargo makes no distinction between the RUSTFLAGS used for the host and the target. There is, however, an unstable feature to make this distinction [1][2]. We already have CARGO_TARGET_APPLIES_TO_HOST="false". This makes sure that any configuration that we make for the target doesn't automatically apply to the host as well. However, this only applies for per-target configuration, for example the setting of "cc" in the config.toml generated by package/rust/rust.mk. Flags that are passed with RUSTFLAGS still apply to both host and target. Therefore, we need to use the CARGO_TARGET_<tuple>_RUSTFLAGS environment variable instead of plain RUSTFLAGS. This, however, doesn't allow us to specify flags that apply only to the host. We could use CARGO_TARGET_<hosttuple>_RUSTFLAGS for that, but that doesn't work in case the host and target tuple are the same. For this, we need another unstable feature, enabled with CARGO_UNSTABLE_HOST_CONFIG="true". With this enabled, we can specify flags that apply only for the host build using CARGO_HOST_RUSTFLAGS. Currently, we don't have any such flags, but we really should: we should pass the proper link flags to point to $(HOST_DIR)/lib. Therefore, add CARGO_HOST_RUSTFLAGS doing exactly that. [1] https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#host-config [2] rust-lang/cargo#10395 Signed-off-by: James Hilliard <[email protected]> Signed-off-by: Arnout Vandecappelle <[email protected]>
1 parent 2f47266 commit 4401519

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: package/pkg-cargo.mk

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ PKG_COMMON_CARGO_ENV = \
3434
# using nighly features on stable releases, i.e features that are not
3535
# yet considered stable.
3636
#
37-
# CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true" "enables the nightly
37+
# CARGO_UNSTABLE_HOST_CONFIG="true" enables the host specific
38+
# configuration feature
39+
#
40+
# CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true" enables the nightly
3841
# configuration option target-applies-to-host value to be set
3942
#
4043
# CARGO_TARGET_APPLIES_TO_HOST="false" is actually setting the value
@@ -43,17 +46,20 @@ PKG_COMMON_CARGO_ENV = \
4346
PKG_CARGO_ENV = \
4447
$(PKG_COMMON_CARGO_ENV) \
4548
__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS="nightly" \
49+
CARGO_UNSTABLE_HOST_CONFIG="true" \
4650
CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST="true" \
4751
CARGO_TARGET_APPLIES_TO_HOST="false" \
4852
CARGO_BUILD_TARGET="$(RUSTC_TARGET_NAME)" \
53+
CARGO_HOST_RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \
4954
CARGO_TARGET_$(call UPPERCASE,$(RUSTC_TARGET_NAME))_LINKER=$(notdir $(TARGET_CROSS))gcc
5055

5156
#
5257
# This is a workaround for https://github.com/rust-lang/compiler-builtins/issues/420
5358
# and should be removed when fixed upstream
5459
#
5560
ifeq ($(NORMALIZED_ARCH),arm)
56-
PKG_CARGO_ENV += RUSTFLAGS="-Clink-arg=-Wl,--allow-multiple-definition"
61+
PKG_CARGO_ENV += \
62+
CARGO_TARGET_$(call UPPERCASE,$(RUSTC_TARGET_NAME))_RUSTFLAGS="-Clink-arg=-Wl,--allow-multiple-definition"
5763
endif
5864

5965
HOST_PKG_CARGO_ENV = \

0 commit comments

Comments
 (0)