Skip to content

Commit 3a2a348

Browse files
committed
feat: dependencies in a separate task
1 parent 061d78b commit 3a2a348

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ An OpenEmebdded/Yocto layer providing pre-built toolchains for the
99
- [meta-rust-bin](#meta-rust-bin)
1010
- [Basic Example](#basic-example)
1111
- [Features](#features)
12-
- [Use with Yocto Release 4.0 (kirkstone) and Above](#use-with-yocto-release-40-kirkstone-and-above)
13-
- [Use with Yocto Release 3.4 (honister) and Above](#use-with-yocto-release-34-honister-and-above)
12+
- [Allow `build.rs` to access the network in Yocto Release 4.0 (kirkstone) and Above](#allow-buildrs-to-access-the-network-in-yocto-release-40-kirkstone-and-above)
13+
- [Updating from an old `meta-rust-bin`](#updating-from-an-old-meta-rust-bin)
1414
- [Advanced Features](#advanced-features)
1515
- [Specifying Cargo Features](#specifying-cargo-features)
1616
- [Using Components Individually](#using-components-individually)
@@ -34,9 +34,6 @@ LICENSE = "MIT"
3434
3535
inherit cargo_bin
3636
37-
# Enable network for the compile task allowing cargo to download dependencies
38-
do_compile[network] = "1"
39-
4037
SRC_URI = "git://github.com/rust-embedded/gpio-utils.git;protocol=https;branch=master"
4138
SRCREV="02b0658cd7e13e46f6b1a5de3fd9655711749759"
4239
S = "${WORKDIR}/git"
@@ -76,18 +73,22 @@ Future:
7673
(provides space savings).
7774
* [ ] Total static linking using MUSL.
7875

79-
### Use with Yocto Release 4.0 (kirkstone) and Above
76+
### Allow `build.rs` to access the network in Yocto Release 4.0 (kirkstone) and Above
8077

8178
From Yocto version 4.0 network access from tasks is disabled by default on
8279
kernels which support this feature (on most recent distros such as CentOS 8 and
83-
Debian 11 onwards). The task `do_compile` need to access the network because it
84-
downloads dependencies, so add the following line to the recipe:
80+
Debian 11 onwards). If the `build.rs` needs access to the network, you have to
81+
enable the network for the `do_compile` task adding the following line to the
82+
recipe:
8583

8684
```bitbake
85+
# After the line `inherit cargo_bin`
86+
87+
# Enable network access for `build.rs` in compile task
8788
do_compile[network] = "1"
8889
```
8990

90-
### Updating from an old `meta-rust-bin`
91+
## Updating from an old `meta-rust-bin`
9192

9293
To avoid conflicts with the offical Rust layer of Yocto, the class `cargo` of
9394
`meta-rust-bin` was renamed to `cargo_bin`.

classes/cargo_bin.bbclass

+15-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ RUST_BUILD = "${@rust_target(d, 'BUILD')}"
2222

2323
# Additional flags passed directly to the "cargo build" invocation
2424
EXTRA_CARGO_FLAGS ??= ""
25-
EXTRA_RUSTFLAGS ??= ""
26-
RUSTFLAGS += "${EXTRA_RUSTFLAGS}"
25+
26+
# Optional RUSTFLAGS
27+
RUSTFLAGS ??= ""
2728

2829
# Space-separated list of features to enable
2930
CARGO_FEATURES ??= ""
3031

3132
# Control the Cargo build type (debug or release)
32-
CARGO_BUILD_PROFILE ?= "release"
33+
# This is based on the content of CARGO_BUILD_FLAGS and generally will need to
34+
# change if CARGO_BUILD_FLAGS changes.
35+
CARGO_BUILD_PROFILE ?= "${@oe.utils.conditional('DEBUG_BUILD', '1', 'debug', 'release', d)}"
3336

3437
CARGO_INSTALL_DIR ?= "${D}${bindir}"
3538

@@ -49,9 +52,8 @@ WRAPPER_DIR = "${WORKDIR}/wrappers"
4952
# Set the Cargo manifest path to the typical location
5053
CARGO_MANIFEST_PATH ?= "${S}/Cargo.toml"
5154

52-
FILES:${PN}-dev += "${libdir}/*.rlib"
53-
5455
CARGO_BUILD_FLAGS = "\
56+
--offline \
5557
--verbose \
5658
--manifest-path ${CARGO_MANIFEST_PATH} \
5759
--target=${RUST_TARGET} \
@@ -93,6 +95,13 @@ cargo_bin_do_configure() {
9395
chmod +x "${WRAPPER_DIR}/linker-native-wrapper.sh"
9496
}
9597

98+
addtask do_cargo_fetch after do_configure before do_compile
99+
do_cargo_fetch[network] = "1"
100+
do_cargo_fetch[dirs]= "${B}"
101+
cargo_bin_do_cargo_fetch() {
102+
cargo fetch --manifest-path ${CARGO_MANIFEST_PATH}
103+
}
104+
96105
cargo_bin_do_compile() {
97106
export TARGET_CC="${WRAPPER_DIR}/cc-wrapper.sh"
98107
export TARGET_CXX="${WRAPPER_DIR}/cxx-wrapper.sh"
@@ -114,7 +123,6 @@ cargo_bin_do_compile() {
114123
export CARGO_TARGET_APPLIES_TO_HOST="false"
115124
export CARGO_TARGET_${@rust_target(d, 'TARGET').replace('-','_').upper()}_LINKER="${WRAPPER_DIR}/linker-wrapper.sh"
116125
export CARGO_HOST_LINKER="${WRAPPER_DIR}/linker-native-wrapper.sh"
117-
export CARGO_BUILD_FLAGS="-C rpath"
118126
export CARGO_PROFILE_RELEASE_DEBUG="true"
119127

120128
# The CC crate defaults to using CFLAGS when compiling everything. We can
@@ -171,4 +179,4 @@ cargo_bin_do_install() {
171179
fi
172180
}
173181

174-
EXPORT_FUNCTIONS do_configure do_compile do_install
182+
EXPORT_FUNCTIONS do_configure do_cargo_fetch do_compile do_install

0 commit comments

Comments
 (0)