Skip to content

Commit

Permalink
feat: dependencies in a separate task
Browse files Browse the repository at this point in the history
  • Loading branch information
banditopazzo committed Oct 19, 2024
1 parent 061d78b commit 3a2a348
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ An OpenEmebdded/Yocto layer providing pre-built toolchains for the
- [meta-rust-bin](#meta-rust-bin)
- [Basic Example](#basic-example)
- [Features](#features)
- [Use with Yocto Release 4.0 (kirkstone) and Above](#use-with-yocto-release-40-kirkstone-and-above)
- [Use with Yocto Release 3.4 (honister) and Above](#use-with-yocto-release-34-honister-and-above)
- [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)
- [Updating from an old `meta-rust-bin`](#updating-from-an-old-meta-rust-bin)
- [Advanced Features](#advanced-features)
- [Specifying Cargo Features](#specifying-cargo-features)
- [Using Components Individually](#using-components-individually)
Expand All @@ -34,9 +34,6 @@ LICENSE = "MIT"
inherit cargo_bin
# Enable network for the compile task allowing cargo to download dependencies
do_compile[network] = "1"
SRC_URI = "git://github.com/rust-embedded/gpio-utils.git;protocol=https;branch=master"
SRCREV="02b0658cd7e13e46f6b1a5de3fd9655711749759"
S = "${WORKDIR}/git"
Expand Down Expand Up @@ -76,18 +73,22 @@ Future:
(provides space savings).
* [ ] Total static linking using MUSL.

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

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

```bitbake
# After the line `inherit cargo_bin`
# Enable network access for `build.rs` in compile task
do_compile[network] = "1"
```

### Updating from an old `meta-rust-bin`
## Updating from an old `meta-rust-bin`

To avoid conflicts with the offical Rust layer of Yocto, the class `cargo` of
`meta-rust-bin` was renamed to `cargo_bin`.
Expand Down
22 changes: 15 additions & 7 deletions classes/cargo_bin.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ RUST_BUILD = "${@rust_target(d, 'BUILD')}"

# Additional flags passed directly to the "cargo build" invocation
EXTRA_CARGO_FLAGS ??= ""
EXTRA_RUSTFLAGS ??= ""
RUSTFLAGS += "${EXTRA_RUSTFLAGS}"

# Optional RUSTFLAGS
RUSTFLAGS ??= ""

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

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

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

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

FILES:${PN}-dev += "${libdir}/*.rlib"

CARGO_BUILD_FLAGS = "\
--offline \
--verbose \
--manifest-path ${CARGO_MANIFEST_PATH} \
--target=${RUST_TARGET} \
Expand Down Expand Up @@ -93,6 +95,13 @@ cargo_bin_do_configure() {
chmod +x "${WRAPPER_DIR}/linker-native-wrapper.sh"
}

addtask do_cargo_fetch after do_configure before do_compile
do_cargo_fetch[network] = "1"
do_cargo_fetch[dirs]= "${B}"
cargo_bin_do_cargo_fetch() {
cargo fetch --manifest-path ${CARGO_MANIFEST_PATH}
}

cargo_bin_do_compile() {
export TARGET_CC="${WRAPPER_DIR}/cc-wrapper.sh"
export TARGET_CXX="${WRAPPER_DIR}/cxx-wrapper.sh"
Expand All @@ -114,7 +123,6 @@ cargo_bin_do_compile() {
export CARGO_TARGET_APPLIES_TO_HOST="false"
export CARGO_TARGET_${@rust_target(d, 'TARGET').replace('-','_').upper()}_LINKER="${WRAPPER_DIR}/linker-wrapper.sh"
export CARGO_HOST_LINKER="${WRAPPER_DIR}/linker-native-wrapper.sh"
export CARGO_BUILD_FLAGS="-C rpath"
export CARGO_PROFILE_RELEASE_DEBUG="true"

# The CC crate defaults to using CFLAGS when compiling everything. We can
Expand Down Expand Up @@ -171,4 +179,4 @@ cargo_bin_do_install() {
fi
}

EXPORT_FUNCTIONS do_configure do_compile do_install
EXPORT_FUNCTIONS do_configure do_cargo_fetch do_compile do_install

0 comments on commit 3a2a348

Please sign in to comment.