Bug 14975 - Installing cargo on target fails
Summary: Installing cargo on target fails
Status: IN PROGRESS REVIEW
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: devtools / tool chain (show other bugs)
Version: 4.2
Hardware: x86 Multiple
: Medium normal
Target Milestone: 6.1
Assignee: Randy MacLeod
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2022-11-26 01:36 UTC by Randy MacLeod
Modified: 2026-02-12 14:55 UTC (History)
7 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy MacLeod 2022-11-26 01:36:06 UTC
In your conf/local.conf, add:

IMAGE_INSTALL:append = " rust-hello-world rust cargo"

for qemux86-64 and build
$ bitbake core-image-full-cmdline

and see:
|      Running `rustc --crate-name opener --edition=2018 /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/rustc-1.65.0-src/vendor/opener/src/lib.rs --error-
format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=457c3ee6920405e4 -C extra-filename=-457c3ee6920
405e4 --out-dir /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps --target x86_64-poky-linux-gnu -C linker=/a
la-lpggp31/rmacleod/src/distro/yocto/b/summit-rust-22.11/tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/wrapper/target-rust-ccld -L dependency=/.../tmp/work/co
re2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps -L dependency=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/targe
t/release/deps --extern bstr=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps/libbstr-8c5c1c7b9cee429d.rmeta
 --cap-lints allow -L /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/recipe-sysroot/usr/lib/rustlib/x86_64-poky-linux-gnu/lib --remap-path-prefix=/ala-lpg
gp31/rmacleod/src/distro/yocto/b/summit-rust-22.11/tmp/work/core2-64-poky-linux/cargo/1.65.0-r0=/usr/src/debug/cargo/1.65.0-r0`
|      Running `rustc --crate-name rand_xoshiro --edition=2018 /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/rustc-1.65.0-src/vendor/rand_xoshiro/src/lib
.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=49cea93c48df9ce5 -C extra-filename=
-49cea93c48df9ce5 --out-dir /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps --target x86_64-poky-linux-gnu
-C linker=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/wrapper/target-rust-ccld -L dependency=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps -L dependency=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/release/deps --extern rand_core=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps/librand_core-8cebb0f5994ebeb7.rmeta --cap-lints allow -L /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/recipe-sysroot/usr/lib/rustlib/x86_64-poky-linux-gnu/lib --remap-path-prefix=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0=/usr/src/debug/cargo/1.65.0-r0`                                                              
| error[E0463]: can't find crate for `proc_macro`                                                                                                                                                                  
|    --> /usr/src/debug/cargo/1.65.0-r0/rustc-1.65.0-src/vendor/proc-macro2-1.0.37/src/lib.rs:119:1                                                                                                                
|     |                                                                                                                                                                                                            
| 119 | extern crate proc_macro;                                                                                                                                                                                   
|     | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate                                                                                                                                                                  
|                                                                                                                                                                                                                  
| For more information about this error, try `rustc --explain E0463`.                                                                                                                                              
| error: could not compile `proc-macro2` due to previous error                                                                                                                                                     
|                                                                                                                                                                                                                  
| Caused by:                                                                                                                                                                                                       
|   process didn't exit successfully: `rustc --crate-name proc_macro2 --edition=2018 /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/rustc-1.65.0-src/vendo
r/proc-macro2-1.0.37/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=51be2a8927e76ee0 -C extra-filename=-51be2a8927e76ee0 --out-dir /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps --target x86_64-poky-linux-gnu -C linker=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/wrapper/target-rust-ccld -L dependency=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps -L dependency=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/release/deps --extern unicode_xid=/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/build/target/x86_64-poky-linux-gnu/release/deps/libunicode_xid-4bc56ec0bbcfdb1e.rmeta --cap-lints allow -L /.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/recipe-sysroot/usr/lib/rustlib/x86_WARNING: /ala-lpggp31/rmacleod/src/distro/yocto/poky.git/bitbake/lib/bb/ui/knotty.py:852: ResourceWarning: unclosed file <_io.TextIOWrapper name='/.../tmp/work/core2-64-poky-linux/cargo/1.65.0-r0/temp/log.do_compile.14259' mode='r' encoding='UTF-8'>                                                            
  main.shutdown = 2   

Note that rust alone on target builds fine:
IMAGE_INSTALL:append = " rust-hello-world rust"
Comment 1 Randy MacLeod 2022-11-26 02:29:22 UTC
When this is fixed, drop:
EXCLUDE_FROM_WORLD = "1"

from cargo.inc.
Comment 2 Chen Pei 2022-12-01 03:04:43 UTC
This looks like proc-macro2 failed to compiled when compiling cargo.
If IMAGE_INSTALL does not contain cargo, it will not compile, so no error is reported.
The workaround method is to modify 'S = "${RUSTSRC}/library/test"' in libstd-rs_%.bb.
Comment 3 Sundeep KOKKONDA 2023-01-16 06:41:31 UTC
Issue fixed with commit https://git.openembedded.org/openembedded-core/commit/?id=550c273f38d8e6d2d431908023e213c6b018d7ed

'bitbake core-image-full-cmdline' built without any issues.

EXCLUDE_FROM_WORLD is only in .bb & .bbclass files (there is no .inc file having this flag). There is no cargo/rust recipe file having this flag. From where this should be removed?
Comment 4 Randy MacLeod 2023-01-19 15:59:55 UTC
Randy to test that we can build cargo /rust for the target without changes to local.conf.
Comment 5 Randy MacLeod 2023-02-21 14:50:53 UTC
Sundeep,

I still see a problem if running rust on target:
root@qemux86-64:~# rustc -o hw /tmp/hw.rs
error: linker `x86_64-poky-linux-gcc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

We can't just ask people to add whatever part of the gcc toolchain that's needed, we need the right dependency in the rust recipe for class-target.

Is there another defect to track that?



The cargo EXCLUDE_FROM_WORLD was dropped in:

commit d2925c9c110e272ed00ab1cd8e83bb0114a254b9
Author: Alex Kiernan <alex.kiernan@gmail.com>
Date:   Wed Dec 28 15:23:32 2022 +0000

    cargo: Drop exclude from world
    
    On-target cargo now builds/runs.
    
    (From OE-Core rev: eb8b8c5247a32f2bd6b680de6f1a999dc2fcbc5f)
Comment 6 Sundeep Kokkonda 2023-03-11 05:22:43 UTC
rust dependent modules are added to run rust on target.
Now, the rust linker issue solved and rust is running on target, verified on arm64 & x86_64 qemu. Below is the patch.

https://git.openembedded.org/openembedded-core/commit/?h=master-next&id=bb781f452299cfa6ec7fffd215b0af3149178f32
Comment 7 Randy MacLeod 2023-03-13 14:55:14 UTC
A fix has been merged to master so I've lowered the importance of the defect but I'd like to keep this issue open for reasons described below.

Fix/work-around:
https://git.openembedded.org/openembedded-core/commit/?id=bb781f452299cfa6ec7fffd215b0af3149178f32

Sundeep,

I suspect that part of what is provided by gcc, g++ is required but not all.
Have you looked at what is used in rustup to support cross-compilation?   
   https://rust-lang.github.io/rustup/cross-compilation.html

We may have to change the gcc, g++ recipes to make sub-packages so that less of the toolchain is install. What you have works, no doubt, but it's more than the minimum required I suspect.
Comment 8 Randy MacLeod 2023-04-21 18:45:44 UTC
Moved en masse from 4.2 to 4.3 by Randy.
Comment 9 Randy MacLeod 2023-05-10 22:01:27 UTC
Sundeep, any comments about what part of gcc, g++ is really needed?

If I run rust-up in an ubuntu container:
$ docker run -it ubuntu
root@d78c1c2d1ee0:/# cat /etc/os-release | grep PRETTY_NAME
PRETTY_NAME="Ubuntu 22.04.2 LTS"
root@d78c1c2d1ee0:/# apt update
...

root@d78c1c2d1ee0:/# apt install cargo
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu ca-certificates cpp cpp-11 fontconfig-config fonts-dejavu-core gcc gcc-11 gcc-11-base libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin
  libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libcurl3-gnutls libdeflate0 libedit2 libexpat1 libfontconfig1 libfreetype6 libgcc-11-dev libgd3 libgomp1 libicu70 libisl23 libitm1 libjbig0
  libjpeg-turbo8 libjpeg8 libldap-2.5-0 libldap-common libllvm14 liblsan0 libmd0 libmpc3 libmpfr6 libnghttp2-14 libnsl-dev libpng16-16 libpsl5 libquadmath0 librtmp1 libsasl2-2 libsasl2-modules
  libsasl2-modules-db libssh-4 libssh2-1 libstd-rust-1.65 libstd-rust-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 linux-libc-dev
  manpages manpages-dev openssl publicsuffix rpcsvc-proto rustc ucf
Suggested packages:
  binutils-doc cargo-doc python3 cpp-doc gcc-11-locales gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc gcc-11-multilib gcc-11-doc glibc-doc libgd-tools libsasl2-modules-gssapi-mit
  | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql man-browser llvm-14 lld-14 clang-14
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu ca-certificates cargo cpp cpp-11 fontconfig-config fonts-dejavu-core gcc gcc-11 gcc-11-base libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin
  libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libcurl3-gnutls libdeflate0 libedit2 libexpat1 libfontconfig1 libfreetype6 libgcc-11-dev libgd3 libgomp1 libicu70 libisl23 libitm1 libjbig0
  libjpeg-turbo8 libjpeg8 libldap-2.5-0 libldap-common libllvm14 liblsan0 libmd0 libmpc3 libmpfr6 libnghttp2-14 libnsl-dev libpng16-16 libpsl5 libquadmath0 librtmp1 libsasl2-2 libsasl2-modules
  libsasl2-modules-db libssh-4 libssh2-1 libstd-rust-1.65 libstd-rust-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 linux-libc-dev
  manpages manpages-dev openssl publicsuffix rpcsvc-proto rustc ucf
0 upgraded, 79 newly installed, 0 to remove and 4 not upgraded.
Need to get 166 MB of archives.
After this operation, 629 MB of additional disk space will be used.


root@d78c1c2d1ee0:/# cat /tmp/jj | tr ' ' '\n' | egrep 'gcc|g\+\+'
gcc
gcc-11
gcc-11-base
libgcc-11-dev
gcc-11-locales
gcc-multilib
gcc-doc
gcc-11-multilib
gcc-11-doc
gcc
gcc-11
gcc-11-base
libgcc-11-dev

or to be less restrictive:
root@d78c1c2d1ee0:/# cat /tmp/jj | tr ' ' '\n' | egrep "^g"
gcc
gcc-11
gcc-11-base
gcc-11-locales
gcc-multilib
gdb
gcc-doc
gcc-11-multilib
gcc-11-doc
glibc-doc
gcc
gcc-11
gcc-11-base
get

so do we really need g++?

similar ubuntu pkg info for rustc:

root@d78c1c2d1ee0:/# apt install rustc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-11 fontconfig-config fonts-dejavu-core gcc gcc-11 gcc-11-base libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin libc-devtools
  libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdeflate0 libedit2 libfontconfig1 libfreetype6 libgcc-11-dev libgd3 libgomp1 libicu70 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libllvm14
  liblsan0 libmd0 libmpc3 libmpfr6 libnsl-dev libpng16-16 libquadmath0 libstd-rust-1.65 libstd-rust-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2
  libxpm4 linux-libc-dev manpages manpages-dev rpcsvc-proto ucf
Suggested packages:
  binutils-doc cpp-doc gcc-11-locales gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc gcc-11-multilib gcc-11-doc glibc-doc libgd-tools man-browser cargo llvm-14 lld-14 clang-14
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-11 fontconfig-config fonts-dejavu-core gcc gcc-11 gcc-11-base libasan6 libatomic1 libbinutils libbrotli1 libbsd0 libc-dev-bin libc-devtools
  libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdeflate0 libedit2 libfontconfig1 libfreetype6 libgcc-11-dev libgd3 libgomp1 libicu70 libisl23 libitm1 libjbig0 libjpeg-turbo8 libjpeg8 libllvm14
  liblsan0 libmd0 libmpc3 libmpfr6 libnsl-dev libpng16-16 libquadmath0 libstd-rust-1.65 libstd-rust-dev libtiff5 libtirpc-dev libtsan0 libubsan1 libwebp7 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2
  libxpm4 linux-libc-dev manpages manpages-dev rpcsvc-proto rustc ucf
0 upgraded, 63 newly installed, 0 to remove and 4 not upgraded.
Need to get 160 MB of archives.
After this operation, 609 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Comment 10 Sundeep Kokkonda 2023-06-19 07:24:53 UTC
Hello Randy,

Currently, binutils installing the below tools on target machine.
x86_64-poky-linux-addr2line        x86_64-poky-linux-dwp              x86_64-poky-linux-gp-display-html  x86_64-poky-linux-gprofng          x86_64-poky-linux-nm               x86_64-poky-linux-readelf
x86_64-poky-linux-ar               x86_64-poky-linux-elfedit          x86_64-poky-linux-gp-display-src   x86_64-poky-linux-ld               x86_64-poky-linux-objcopy          x86_64-poky-linux-size
x86_64-poky-linux-as               x86_64-poky-linux-gp-archive       x86_64-poky-linux-gp-display-text  x86_64-poky-linux-ld.bfd           x86_64-poky-linux-objdump          x86_64-poky-linux-strings
x86_64-poky-linux-c++filt          x86_64-poky-linux-gp-collect-app   x86_64-poky-linux-gprof            x86_64-poky-linux-ld.gold          x86_64-poky-linux-ranlib           x86_64-poky-linux-strip

The tried installing the required tools such as as, ld.. etc but that's not working as binutils is collection of all those tools and currently binutils recipe in Yocto is not enabled to generate these individual module packages.
The g++ was analyzed earlier and it is required to run Cargo on target. The detailed analysis is here - https://lists.openembedded.org/g/openembedded-core/message/178207
Comment 11 Randy MacLeod 2023-06-21 00:55:10 UTC
Sundeep, Thanks for checking on this.

I still don't understand *why* we would need g++ even for cargo.

Running an ubuntu-22.04 docker container, I see the following dependencies, none of which is g++ but cargo does seem to need gcc. It would be good to understand why. 22.04 ships rustc-1.65, fyi.

$ docker run -it ubuntu 
root@dd3c5196093b:/# apt update
...
root@dd3c5196093b:/# apt depends rustc
rustc
  Depends: libc6 (>= 2.34)
  Depends: libgcc-s1 (>= 4.2)
  Depends: libstd-rust-dev (= 1.65.0+dfsg0ubuntu1-0ubuntu0.22.04.1)
  Depends: gcc
  Depends: <libc-dev>
    libc6-dev
  Depends: binutils (>= 2.26)
  Breaks: libstd-rust-dev (<< 1.26.2+dfsg1+llvm-0ubuntu1~~)
  Suggests: cargo (>= 0.65.0~~)
  Suggests: cargo (<< 0.66.0~~)
  Suggests: llvm-14
  Suggests: lld-14
  Suggests: clang-14
  Replaces: libstd-rust-dev (<< 1.26.2+dfsg1+llvm-0ubuntu1~~)
root@dd3c5196093b:/# apt depends cargo
cargo
  Depends: libc6 (>= 2.34)
  Depends: libcurl3-gnutls (>= 7.28.0)
  Depends: libgcc-s1 (>= 4.2)
  Depends: libssh2-1 (>= 1.7.0)
  Depends: libssl3 (>= 3.0.0~~alpha1)
  Depends: zlib1g (>= 1:1.1.4)
  Depends: rustc (>= 1.24)
  Depends: binutils
 |Depends: gcc
 |Depends: clang
  Depends: <c-compiler>
    bcc
    clang-11
    clang-12
    clang-13
    clang-14
    clang-15
    gcc
    gcc-10
    gcc-11
    gcc-12
    gcc-9
    pcc
    tcc
  Suggests: cargo-doc
  Suggests: python3
Comment 12 Sundeep Kokkonda 2023-07-17 16:07:08 UTC
Hello  Randy,

Here g++ is not a direct dependency of cargo/rust.
I tried a simple C program to compile and link w/o adding g++ and the linker failed with same errors mentioned earlier (x86_64-poky-linux/bin/ld: cannot find Scrt1.o: No such file or directory ... etc)
The missing files are 'C runtime startup code object files'. There is an explanation about these files here - https://stackoverflow.com/questions/16436035/whats-the-usage-of-mcrt1-o-and-scrt1-o
With g++ package these files are installing on the image. In Yocto, the gcc RPROVIDES g++, so this dependency is added.
Comment 13 Randy MacLeod 2023-08-11 19:35:47 UTC
I need to spend time on this to understand if we should be changing the gcc/g++
recipe to avoid RDEPENDing on g++ or if my understanding of cargo's requirement is simply not correct.
Comment 14 Randy MacLeod 2024-09-26 18:13:36 UTC
I'm still not convinced that we don't have an opportunity to trim down or sanitize our rust/cargo dependencies since according the the Fedora 40 sRPMs,
rust and cargo do not depend on g++:

https://www.rpmfind.net/linux/RPM/fedora/40/x86_64/r/rust-1.77.0-1.fc40.x86_64.html

https://www.rpmfind.net/linux/RPM/fedora/40/x86_64/c/cargo-1.77.0-1.fc40.x86_64.html

Anyway, bumping to the next release since I don't have more time for this now.
Comment 15 Randy MacLeod 2026-02-12 14:55:27 UTC
We should confirm that if we split up the gcc/g++ recipe to separate the linker parts from the compiler parts in 6.1.