How does rust searches for crates?

140 Views Asked by At

I am using termux and trying to compile a hello world in rust, of course it can't find std nor core, I want to know what is going on, it is quite opaque, which files are missing exactly, is it these?

$ ls $PREFIX/lib/rustlib/aarch64-linux-android/lib
libcstr-38cc1a700499a2b7.so            libicu_provider_macros-a70f76f425f67b0d.so  libserde_derive-221e8f38918486bf.so             libyoke_derive-91760fdd8460cca3.so
libdarling_macro-7b8000f62e2c15d5.so   libproc_macro_hack-0334bb6f224f7962.so      libthiserror_core_impl-f2c52c21a354b6ff.so      libzerofrom_derive-d617e7f86f6504a7.so
libderive_more-71b2ecc6e76493ab.so     librustc_driver-78f3b3010e7a7c26.so         libthiserror_impl-4af3faeadd561b3a.so           libzerovec_derive-508bcf32bf5cbb5e.so
libderive_setters-c8a70d2499d48f8a.so  librustc_fluent_macro-e6aa0ea268e4ad8f.so   libtracing_attributes-a629cf96ffb0f7a4.so
libdisplaydoc-dfd622a9e81bc289.so      librustc_macros-377d0e078de2eede.so         libunic_langid_macros_impl-bb5454d0d0ed57d6.so

they are not on /lib/rustlib but on $PREFIX/lib/rustlib, is that the problem?, how can I tell rust/cargo to use this? It's quite interesting as an academical excercise.

solutions on internet, are to simply use rustup, but rustup is not supported for android, but I also want to understand how rust actually searches for std and finds it, this is important, I tried using export RUSTFLAGS="-L $PREFIX/lib/rustlib/aarch64-linux-android/lib" it didn't seem to work either. I also tried rustc --sysroot $PREFIX/lib/rustlib/aarch64-linux-android src/main.rs error[E0463]: can't find crate for `std` which didn't seem to work either. Maybe I just need to compile std to android?

1

There are 1 best solutions below

0
moha On

you really can use rustup with a custom glibc built for Termux see this guide.

you will either use the autopatchelf script attached there for patching your elf files or patch your binaries with the project's official way of doing it, here

it's easy and it's working.