termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.08k stars 3k forks source link

[Bug]: Rust: Thin LTO broken #12260

Closed dead10ck closed 1 year ago

dead10ck commented 2 years ago

Problem description

I'll not sure at what point this started happening, but I think within the last couple of Rust versions, I've started getting this error at the end of compiling a project with Thin LTO enabled:

error: failed to prepare thin LTO module: Opaque pointers are only supported in -opaque-pointers mode (Producer: 'LLVM15.0.1' Reader: 'LLVM 15.0.1')

It appears to have something to do with LLVM 15.

What steps will reproduce the bug?

Build any project with Thin LTO.

What is the expected behavior?

The project compiles

System information

termux-info:

Termux Variables:
TERMUX_APK_RELEASE=F_DROID                                        TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=27912                                              TERMUX_IS_DEBUGGABLE_BUILD=0                                      TERMUX_MAIN_PACKAGE_FORMAT=debian                                 TERMUX_VERSION=0.118.0                                            Packages CPU architecture:                                        aarch64                                                           Subscribed repositories:                                          # sources.list                                                    deb https://packages.termux.dev/apt/termux-main stable main       Updatable packages:                                               All packages up to date                                           termux-tools version:                                             1.29.3                                                            Android version:
12                                                                Kernel build information:                                         Linux localhost 5.4.191-qgki-g017ec6c9bb6f #1 SMP PREEMPT Tue Sep 27 08:51:29 UTC 2022 aarch64 Android                              Device manufacturer:                                              OnePlus                                                           Device model:                                                     LE2125
finagolfin commented 2 years ago

LLVM 15 just came out last month, so if you saw it with previous Rust versions, those would be using LLVM 14. I think this issue hit Zig too and may have delayed their release: do you not see this error on other platforms like linux x86_64? If you see it there too, you should report this upstream, not here.

dead10ck commented 2 years ago

No, I do not see this on Fedora.

AK2993 commented 1 year ago

hello, I am facing the same issue. Any help?

psmears commented 1 year ago

hello, I am facing the same issue. Any help?

I managed to work around this by creating ~/.cargo/config.toml, with the following contents:

[profile.dev]
lto = false
[profile.release]
lto = false
[profile.test]
lto  =false
[profile.bench]
lto = false

That will disable link-time optimisation - not sure what effect that will have on performance, or whether all of those lines are needed, but neither of those things are important to what I'm doing so I haven't investigated further. Hopefully the same may work for you too.

dead10ck commented 1 year ago

lto = "fat" also works, it's just slower.

elbakramer commented 1 year ago

Possibly related issue: #12163

It suggests a workaround setting RUSTFLAGS environment variable like below:

export RUSTFLAGS+=" -C lto=no"

For my case, it also seems to work with the following:

export RUSTFLAGS+=" -C llvm-args=-opaque-pointers"
xtkoba commented 1 year ago

It has been a while since the release of LLVM 15, but Googling still does not tell me about any similar issues with other platforms than Termux. I just wonder why.

Need documentation about this if it cannot be fixed.

mablue commented 1 year ago

Hi friend if you have problem with installing cryptography and or telethonfaketls and or ccxt packages: pip install cryptography pip3 install TelethonFakeTLS pip install ccxt

note: This error originates from a subprocess, and is likely not a problem with pip.        
ERROR: Failed building wheel for cryptography                                             
Failed to build cryptography                  
ERROR: Could not build wheels for cryptography, which is required to install pyproject.toml-based projects

fix it with this commands:

export RUSTFLAGS=" -C lto=no" && export CARGO_BUILD_TARGET="$(rustc -vV | sed -n 's|host: ||p')" && pip install cryptography

I hope people will work on it and solve it. also it's a persian lng page to fix other similar problems too: Link:Click

sylirre commented 1 year ago

@mablue Now Termux provides python-cryptography package that provides a prebuilt cryptography module. No need to install it by pip unless using Python from Termux User Repository which has different versions that provided by termux-packages.

xtkoba commented 1 year ago

This does not seem to happen anymore with rust 1.68.2 and libllvm 16.0.2. Execution of pip install cryptography succeeds without any workarounds other than CARGO_BUILD_TARGET env var. Can anyone else confirm this?

mablue commented 1 year ago

@mablue Now Termux provides python-cryptography package that provides a prebuilt cryptography module. No need to install it by pip unless using Python from Termux User Repository which has different versions that provided by termux-packages.

Thanks all. It's better to have this key things internally cuz it can increase usability of termux as coridor of to introduce BsD/Linux based systems to noob people that just want to have fun. Many people in the world never can Think about removing windows from his pc and use a bsd based system on it but them correctly using termux on his phone without any problem :) I have many friends that them cant buy a pc 😔 or a laptop, but them use termux on his old phone to do great things ( small hacks and etc 🤣 ) <<cuz of that I think we should have an other termux version for android 4 support to help these people to be alive>> There is many old phones that can convert to any good thing with termux. Them are all better than atimegas,arduinos,arms,Raspberry Pis and other Fruits... We shoud Continue to this work and make it better but should keep it simple and usable Cuz this is the greatest service that can be done to humanity. And some body realy love it as a friend not just an android app! List of my best friends: Aide, Acode, Termux, dualingo, sololearn, X-plore, MixPlorer, Newpipe, Matsuri, seal, b612, sketchbook, Whats your friends?!🤔🥹 (Yes I know its off topic) take it easy man 😂

xtkoba commented 1 year ago

Closing as resolved.

Nemris commented 1 year ago

For those who might be interested - it appears that current Cargo can build Rust software with both full and thin LTO. It might be relevant to cryptography as well.