Skip to contentSkip to conversation

package/pkg-cargo.mk: fix build with BR2_ENABLE_DEBUG

PATCH In review David GOUARIN 2 participants 2 messages Mar 30, 2022 – Jun 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pkg-cargo.mk: fix build with BR2_ENABLE_DEBUG

When building with BR2_ENABLE_DEBUG, cargo packages are first built with --debug, then the installation step rebuilds the sources in release mode with cargo install. This is because cargo install forces a rebuild when the --path option is used.

This patch adds a --debug to the cargo install command line as a workaround when necessary, but it does not address the root cause, which is that cargo install will rebuild the sources, possibly with different build options. For example, when one use PKG_CARGO_BUILD_OPTS = --features myfeature, one must also use PKG_CARGO_INSTALL_OPTS = --features myfeature.

---
 package/pkg-cargo.mk | 1 +
 1 file changed, 1 insertion(+)
package/pkg-cargo.mk +1 -0
index f7e3f39503..cf5ee2ae54 100644
@@ -155,6 +155,7 @@ define $(2)_INSTALL_TARGET_CMDS
 		$$($(2)_CARGO_ENV) \
 		cargo install \
 			--offline \
+			$$(if $$(BR2_ENABLE_DEBUG),--debug,) \
 			--root $$(TARGET_DIR)/usr/ \
 			--bins \
 			--path ./ \
Signature · 6 lines
2.17.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

David, All,

On 2022-03-30 18:04 +0200, David GOUARIN spake thusly:

Quoted 3 lines

When building with BR2_ENABLE_DEBUG, cargo packages are first built with --debug, then the installation step rebuilds the sources in release mode with cargo install. This is because cargo install forces a rebuild when the --path option is used.

So, should we also be passing --path ./ at build time too?

Quoted 5 lines

This patch adds a --debug to the cargo install command line as a workaround when necessary, but it does not address the root cause, which is that cargo install will rebuild the sources, possibly with different build options. For example, when one use PKG_CARGO_BUILD_OPTS = --features myfeature, one must also use PKG_CARGO_INSTALL_OPTS = --features myfeature.

You mean, something like:

    diff --git a/package/pkg-cargo.mk b/package/pkg-cargo.mk
    index f7e3f39503..bc697ea6c1 100644
    --- a/package/pkg-cargo.mk
    +++ b/package/pkg-cargo.mk
    @@ -90,6 +90,10 @@ endif
     # listed in <pkg>_LICENSE.
     $(2)_LICENSE += , vendored dependencies licenses probably not listed
     
    +# By default, the same set of options must be pass both at build time
    +# and install time.
    +$(2)_CARGO_INSTALL_OPTS ?= $$($(2)_CARGO_INSTALL_OPTS)
    +
     # Note: in all the steps below, we "cd" into the build directory to
     # execute the "cargo" tool instead of passing $(@D)/Cargo.toml as the
     # manifest-path. Indeed while the latter seems to work, it in fact
Quoted 10 lines
---
 package/pkg-cargo.mk | 1 +
 1 file changed, 1 insertion(+)
package/pkg-cargo.mk +0 -0
index f7e3f39503..cf5ee2ae54 100644

package/pkg-cargo.mk define $(2)_INSTALL_TARGET_CMDS · line 158

Quoted 4 lines
package/pkg-cargo.mk +1 -0
@@ -155,6 +155,7 @@ define $(2)_INSTALL_TARGET_CMDS
 		$$($(2)_CARGO_ENV) \
 		cargo install \
 			--offline \
+			$$(if $$(BR2_ENABLE_DEBUG),--debug,) \

At build time, we do it the other way around:

    $$(if $$(BR2_ENABLE_DEBUG),,--release)

so I believe this is exactly what we should do here as well, unless there is a good reason to do otherwise (in which case it should be explained in the commit log).

Regards,
Yann E. MORIN.

Quoted 10 lines
package/pkg-cargo.mk +0 -0
 			--root $$(TARGET_DIR)/usr/ \
 			--bins \
 			--path ./ \
Signature · 6 lines
2.17.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot