diff mbox series

[8/9] classes/cargo-c: pass flags via CARGO_BUILD_FLAGS

Message ID 20260804165803.598030-8-ross.burton@arm.com
State Accepted, archived
Commit 9079283776997287d455ef32696895d756bc37b3
Headers show
Series [1/9] classes/cargo_common: move PKG_CONFIG_ALLOW_CROSS export to oe_cargo_fix_env | expand

Commit Message

Ross Burton Aug. 4, 2026, 4:58 p.m. UTC
We need to pass the same flags to cbuild and cinstall, as otherwise it
will build in do_compile and then rebuild with the right paths in
do_install.

Add the flags to CARGO_BUILD_FLAGS so that they get used in all calls
and do_install no longer does any building. Example from buildstats:

PKG                        TASK        ABSDIFF  RELDIFF  WALLTIME1 -> WALLTIME2
gstreamer1.0-plugins-rs    do_install  -263.6s   -99.0%     266.2s -> 2.7s

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/classes-recipe/cargo_c.bbclass | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Enrico Scholz Sept. 17, 2026, 4:31 p.m. UTC | #1
"Ross Burton via lists.openembedded.org"
<ross.burton=arm.com@lists.openembedded.org> writes:

> Add the flags to CARGO_BUILD_FLAGS so that they get used in all calls
> and do_install no longer does any building.
>
> +CARGO_BUILD_FLAGS += "\
> +    --destdir ${D} \
> +    --prefix ${prefix} \
> +    --libdir ${libdir} \
> +    --library-type cdylib \
> +    "

Most/all of these flags are not supported by cargo and will break recipes
which use it directly (e.g. by inheriting the ptest-cargo class):

| ERROR: ... do_compile_ptest_cargo: Unable to compile test with cargo, '.../cargo build ... --destdir ...' failed

It would be better to define and use a dedicated variable
(e.g. CARGO_C_BUILD_FLAGS).



Enrico
Ross Burton Sept. 23, 2026, 4:55 p.m. UTC | #2
On 17 Sep 2026, at 17:31, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
> 
> "Ross Burton via lists.openembedded.org"
> <ross.burton=arm.com@lists.openembedded.org> writes:
> 
>> Add the flags to CARGO_BUILD_FLAGS so that they get used in all calls
>> and do_install no longer does any building.
>> 
>> +CARGO_BUILD_FLAGS += "\
>> +    --destdir ${D} \
>> +    --prefix ${prefix} \
>> +    --libdir ${libdir} \
>> +    --library-type cdylib \
>> +    "
> 
> Most/all of these flags are not supported by cargo and will break recipes
> which use it directly (e.g. by inheriting the ptest-cargo class):
> 
> | ERROR: ... do_compile_ptest_cargo: Unable to compile test with cargo, '.../cargo build ... --destdir ...' failed
> 
> It would be better to define and use a dedicated variable
> (e.g. CARGO_C_BUILD_FLAGS).

Ah. Is there a recipe in a public layer that can be used to demonstrate this?

Ross
Enrico Scholz Sept. 23, 2026, 5:17 p.m. UTC | #3
Ross Burton <Ross.Burton@arm.com> writes:

>> Most/all of these flags are not supported by cargo and will break
>> recipes which use it directly (e.g. by inheriting the ptest-cargo
>> class):
>> 
>> | ERROR: ... do_compile_ptest_cargo: Unable to compile test with cargo, '.../cargo build ... --destdir ...' failed
>> 
>> It would be better to define and use a dedicated variable
>> (e.g. CARGO_C_BUILD_FLAGS).
>
> Ah. Is there a recipe in a public layer that can be used to demonstrate this?

not that I am aware of; I find only one public user of cargo_c:
rust-c-lib-example in meta-selftest/recipes-devtools/rust

But doing

| --- a/meta-selftest/recipes-devtools/rust/rust-c-lib-example_git.bb
| +++ b/meta-selftest/recipes-devtools/rust/rust-c-lib-example_git.bb
| @@ -10,5 +10,6 @@ SRC_URI = " \
|  SRCREV = "fc53c457f69aa5221ec1f8619a007e8150db5e60"
|  
|  inherit cargo_c
| +inherit ptest-cargo
|  
|  require ${BPN}-crates.inc

shows the problem.


My usecase (with non-public sources):  rust project is

| .
| |- Cargo.toml
| |- src/
| |  |- lib.rs
| |- examples/
| |- project-c
|    |- Cargo.toml

C dylib is built by

| cargo cbuild --package project-c ...

while examples (shipped as ptest) require

| cargo build --examples



Enrico
diff mbox series

Patch

diff --git a/meta/classes-recipe/cargo_c.bbclass b/meta/classes-recipe/cargo_c.bbclass
index e68ac93a610..cd486b20067 100644
--- a/meta/classes-recipe/cargo_c.bbclass
+++ b/meta/classes-recipe/cargo_c.bbclass
@@ -16,6 +16,13 @@  BASEDEPENDS:append = " cargo-c-native"
 
 B = "${WORKDIR}/build"
 
+CARGO_BUILD_FLAGS += "\
+    --destdir ${D} \
+    --prefix ${prefix} \
+    --libdir ${libdir} \
+    --library-type cdylib \
+    "
+
 do_compile[progress] = "outof:\s+(\d+)/(\d+)"
 cargo_c_do_compile() {
     oe_cargo_fix_env
@@ -27,11 +34,7 @@  cargo_c_do_compile() {
 cargo_c_do_install() {
     oe_cargo_fix_env
     export RUSTFLAGS="${RUSTFLAGS}"
-    cargo-cinstall cinstall ${CARGO_BUILD_FLAGS} \
-        --destdir ${D} \
-        --prefix ${prefix} \
-        --libdir ${libdir} \
-        --library-type cdylib
+    cargo-cinstall cinstall ${CARGO_BUILD_FLAGS}
 }
 
 EXPORT_FUNCTIONS do_compile do_install