Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 876493 - dev-lang/rust fails with USE=system-llvm and libcxx
Summary: dev-lang/rust fails with USE=system-llvm and libcxx
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Georgy Yakovlev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: systemwide-libcxx
  Show dependency tree
 
Reported: 2022-10-10 10:49 UTC by Manuel Nickschas
Modified: 2022-10-16 02:36 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge.info.xz,6.82 KB, application/x-xz)
2022-10-10 10:49 UTC, Manuel Nickschas
Details
build.log (build.log.xz,116.91 KB, application/x-xz)
2022-10-10 10:49 UTC, Manuel Nickschas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Nickschas 2022-10-10 10:49:10 UTC
I'm trying to build dev-lang/rust with clang and system-wide libcxx.

Seems the issue fixed in https://bugs.gentoo.org/732632 is back:

[rustc_llvm 0.0.0] cargo:rustc-link-lib=static=llvm-wrapper
[rustc_llvm 0.0.0] cargo:rustc-link-search=native=/var/tmp/portage/dev-lang/rust-1.64.0-r1/work/rustc-1.64.0-src/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/rustc_llvm-0d080e9e638c9ba7/out
[rustc_llvm 0.0.0] cargo:rerun-if-env-changed=LLVM_LINK_SHARED
[rustc_llvm 0.0.0] cargo:rustc-link-lib=dylib=LLVM-14libcxx
[rustc_llvm 0.0.0] thread 'main' panicked at 'assertion failed: !cxxflags.contains(\"stdlib=libc++\")', compiler/rustc_llvm/build.rs:348:13
[rustc_llvm 0.0.0] stack backtrace:
[rustc_llvm 0.0.0]    0: rust_begin_unwind
[rustc_llvm 0.0.0]    1: core::panicking::panic_fmt
[rustc_llvm 0.0.0]    2: core::panicking::panic
[rustc_llvm 0.0.0]    3: build_script_build::main
[rustc_llvm 0.0.0]    4: core::ops::function::FnOnce::call_once
[rustc_llvm 0.0.0] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[rustc_llvm 0.0.0] cargo:rustc-link-search=native=/usr/lib/llvm/14/lib64
[rustc_llvm 0.0.0] cargo:rerun-if-env-changed=LLVM_LINKER_FLAGS
[rustc_llvm 0.0.0] cargo:rerun-if-env-changed=LLVM_STATIC_STDCPP
[rustc_llvm 0.0.0] cargo:rerun-if-env-changed=LLVM_USE_LIBCXX
error: failed to run custom build command for `rustc_llvm v0.0.0 (/var/tmp/portage/dev-lang/rust-1.64.0-r1/work/rustc-1.64.0-src/compiler/rustc_llvm)`

I can reproduce this with the current version 1.64.0-r1 as well as with 1.63.0-r1 that I had previously successfully built, so I assume the recent changes to libcxx detection might cause the issue. Setting USE=-system-llvm leads to a successful build, but obviously cannot be the solution.

Note that the backtrace quoted above points to llvm-14 for some reason - I have llvm-14 still installed since some packages still require it, but the main toolchain is llvm-15. So maybe the libcxx detection fails if llvm is installed in more than one slot?

Reproducible: Always

Steps to Reproduce:
1. Use system-wide clang and libcxx
2. Emerge dev-lang/rust
3. Profit
Actual Results:  
Fails to compile due to libcxx detection somehow going wrong

Expected Results:  
Should compile
Comment 1 Manuel Nickschas 2022-10-10 10:49:34 UTC
Created attachment 823450 [details]
emerge --info
Comment 2 Manuel Nickschas 2022-10-10 10:49:53 UTC
Created attachment 823453 [details]
build.log
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-10 11:42:23 UTC
Yeah, it's definitely not clocking it:

```
[target.x86_64-unknown-linux-gnu]
ar = "llvm-ar"
cc = "clang"
cxx = "clang++"
linker = "clang"
ranlib = "llvm-ranlib"
llvm-libunwind = "no"
llvm-config = "/usr/lib/llvm/14/bin/llvm-config"
```

Could you poke at https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lang/rust/rust-1.64.0-r1.ebuild#n361 & https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lang/rust/rust-1.64.0-r1.ebuild#n234 and look at why it's failing for you?

I guess is_libcxx_linked returns no?
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-10-10 15:54:53 UTC
Your flags on sys-devel/clang and sys-devel/clang-common (all installed versions), plz.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-10-10 15:59:14 UTC
(In reply to Manuel Nickschas from comment #0)
> Note that the backtrace quoted above points to llvm-14 for some reason - I
> have llvm-14 still installed since some packages still require it, but the
> main toolchain is llvm-15. So maybe the libcxx detection fails if llvm is
> installed in more than one slot?

Rust forces LLVM 14, so if you use unversioned clang/clang++, it ends up using -14.  If you want to force 15, try CC=clang-15 CXX=clang++-15.
Comment 6 Manuel Nickschas 2022-10-11 08:04:48 UTC
Mystery has been solved. I got caught by the move of default-* USE flags from clang to clang-common, not realizing that simply renaming the entry in my config would affect the still-installed clang:14 which thus was indeed built with libstdcxx after world rebuild.

And mgorny explained why clang:14 would be found, so this is also clarified.

Sorry for the noise, I guess this can be closed (should I do this myself, or leave this to the assignee, in the general case?)
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-10-11 09:31:57 UTC
That said, I'm not sure if we should allow llvm.eclass to force older clang via CC/CXX.  I could add some logic to prevent that from happening, like:

  if [[ ${CC} == *clang ]]; then
    local version=...
    if type -P ${CC}-${version} &>/dev/null; then
      CC+=-${version}
    fi
  fi
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-16 02:36:33 UTC
(In reply to Manuel Nickschas from comment #6)
> Mystery has been solved. I got caught by the move of default-* USE flags
> from clang to clang-common, not realizing that simply renaming the entry in
> my config would affect the still-installed clang:14 which thus was indeed
> built with libstdcxx after world rebuild.
> 
> And mgorny explained why clang:14 would be found, so this is also clarified.
> 
> Sorry for the noise, I guess this can be closed (should I do this myself, or
> leave this to the assignee, in the general case?)

It's OK to do it yourself if you think it's PEBKAC etc.

(In reply to Michał Górny from comment #7)
> That said, I'm not sure if we should allow llvm.eclass to force older clang
> via CC/CXX.  I could add some logic to prevent that from happening, like:
> 
>   if [[ ${CC} == *clang ]]; then
>     local version=...
>     if type -P ${CC}-${version} &>/dev/null; then
>       CC+=-${version}
>     fi
>   fi

I think it might be worth considering this given firefox etc keeps reinventing it.