Bug 238556 - lang/rust 1.35.0 fails to build: CXX compiler: /usr/bin/clang++ -- broken
Summary: lang/rust 1.35.0 fails to build: CXX compiler: /usr/bin/clang++ -- broken
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: FreeBSD Rust Team
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2019-06-14 05:15 UTC by Matthias Apitz
Modified: 2020-04-23 15:36 UTC (History)
6 users (show)

See Also:
tobik: maintainer-feedback+


Attachments
pudriere build log of lang/rust (98.37 KB, text/plain)
2019-06-14 05:21 UTC, Matthias Apitz
no flags Details
rust-clang.diff (2.25 KB, patch)
2020-04-14 09:09 UTC, Tobias Kortkamp
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Apitz 2019-06-14 05:15:34 UTC

    
Comment 1 Matthias Apitz 2019-06-14 05:20:29 UTC
I'm building ports with poudriere on FreeBSD 13.0-CURRENT r342378 with ports tree from June, 10. The build fails with

...
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- broken
CMake Error at /usr/local/share/cmake/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/gmake cmTC_359c5/fast
    gmake[1]: Entering directory '/wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp'
    /usr/local/bin/gmake -f CMakeFiles/cmTC_359c5.dir/build.make CMakeFiles/cmTC_359c5.dir/build
    gmake[2]: Entering directory '/wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_359c5.dir/testCXXCompiler.cxx.o
    /usr/bin/clang++    -ffunction-sections -fdata-sections -fPIC --target=x86_64-unknown-freebsd    -o CMakeFiles/cmTC_359c5.dir/testCXXCompiler.cxx.o -c /wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_359c5
    /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_359c5.dir/link.txt --verbose=1
    /usr/bin/clang++  -ffunction-sections -fdata-sections -fPIC --target=x86_64-unknown-freebsd     CMakeFiles/cmTC_359c5.dir/testCXXCompiler.cxx.o  -o cmTC_359c5
    ld: error: unable to find library -lstdc++
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[2]: *** [CMakeFiles/cmTC_359c5.dir/build.make:87: cmTC_359c5] Error 1
    gmake[2]: Leaving directory '/wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp'
    gmake[1]: *** [Makefile:121: cmTC_359c5/fast] Error 2
    gmake[1]: Leaving directory '/wrkdirs/usr/ports/lang/rust/work/rustc-1.35.0-src/build/x86_64-unknown-freebsd/llvm/build/CMakeFiles/CMakeTmp'
...

I will attach the complete log.
Comment 2 Matthias Apitz 2019-06-14 05:21:22 UTC
Created attachment 205053 [details]
pudriere build log of lang/rust
Comment 3 Mikael Urankar freebsd_committer 2019-06-14 11:03:50 UTC
(In reply to Matthias Apitz from comment #1)
Why do you modify CC, CXX?

/usr/local/etc/poudriere.d/freebsd-r342378-make.conf
CC=clang             # Highly recommended over GCC,
CXX=clang++          # but only needed for 8.X and 9.X
CPP=clang-cpp        # since it's the default in 10.0
Comment 4 Tobias Kortkamp freebsd_committer 2019-06-14 12:12:15 UTC
(In reply to Matthias Apitz from comment #1)
> I'm building ports with poudriere on FreeBSD 13.0-CURRENT r342378 with ports
> tree from June, 10.

r342378 is ~6 months old at this point.  You should update ASAP.

Given the error message, can you compile any other C++ based port?

Or in the Poudriere build jail does

$ echo 'int main() {}' | clang++ -x c++ - && ./a.out

even work?
Comment 5 Matthias Apitz 2019-06-14 12:29:19 UTC
(In reply to mikael.urankar from comment #3)

I think I do not modify the CC, ... I just mention the defaults.
Comment 6 Matthias Apitz 2019-06-14 12:35:04 UTC
(In reply to Tobias Kortkamp from comment #4)

I've built with this jail and port checkout ~1800 ports. I don't know how many use clang++, but for example this one:
...
=======================<phase: configure      >============================
===>  Configuring for kf5-purpose-5.58.0
===>  Performing out-of-source build
/bin/mkdir -p /wrkdirs/usr/ports/misc/kf5-purpose/work/.build
-- The C compiler identification is Clang 7.0.1
-- The CXX compiler identification is Clang 7.0.1
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
...

In this case here, the real problem is;

      ld: error: unable to find library -lstdc++

why it is missing libstdc++?
Comment 7 Tobias Kortkamp freebsd_committer 2019-06-14 13:53:00 UTC
The problem can be reproduced with just

$ clang++ --target=x86_64-unknown-freebsd /dev/null
ld: error: unable to find library -lstdc++
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Looks like clang defaults to using libstdc++ with
--target=x86_64-unknown-freebsd.

Why Rust decides to add --target with CXX=clang++ I do not know.
It does not happen with CXX=c++ (see [1] for comparison).

I recommend you stop setting CC, CXX, CPP in make.conf to non-default
values for now.  There is no benefit to setting them to /usr/bin/clang
etc. anyway.

[1]  http://beefy12.nyi.freebsd.org/data/head-amd64-default/p503933_s348887/logs/rust-1.35.0.log
Comment 8 Matthias Apitz 2019-06-14 17:25:11 UTC
(In reply to Tobias Kortkamp from comment #7)

Unsetting CC, CXX, ... fixed the issue. Thanks.
Comment 9 Jan Beich freebsd_committer 2019-06-17 13:36:52 UTC
(In reply to Tobias Kortkamp from comment #7)
> Looks like clang defaults to using libstdc++ with --target=x86_64-unknown-freebsd.

Probably due to rust discarding OS version. --target=x86_64-unknown-freebsd13.0 is not affected.

// From contrib/llvm/tools/clang/lib/Driver/ToolChains/FreeBSD.cpp:
ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const {
  if (getTriple().getOSMajorVersion() >= 10)
    return ToolChain::CST_Libcxx;
  return ToolChain::CST_Libstdcxx;
}
Comment 10 Walter Schwarzenfeld freebsd_triage 2019-08-15 08:49:01 UTC
We have version 1.36.0. Is this still relevant?
Comment 11 Tobias Kortkamp freebsd_committer 2019-08-15 09:15:50 UTC
(In reply to Walter Schwarzenfeld from comment #10)
I have no reason to believe the problem is magically gone as the code shown
comment #9 is still in place in LLVM and Rust still discards the OS version
from target triples.

Since FreeBSD 9.x is no longer supported, maybe LLVM's GetDefaultCXXStdlibType()
should start to always default to libc++ now.
Comment 12 Jan Beich freebsd_committer 2020-04-09 04:48:02 UTC
(In reply to Tobias Kortkamp from comment #11)
> Since FreeBSD 9.x is no longer supported, maybe LLVM's GetDefaultCXXStdlibType()
> should start to always default to libc++ now.

See https://reviews.llvm.org/D77776
Comment 13 Tobias Kortkamp freebsd_committer 2020-04-14 09:09:00 UTC
Created attachment 213386 [details]
rust-clang.diff

(In reply to Jan Beich from comment #12)
Thanks.  In the meantime I think we can patch Rust to not pass --target to
the compiler when it has "clang" in its name.
Comment 14 commit-hook freebsd_committer 2020-04-17 10:54:05 UTC
A commit references this bug:

Author: tobik
Date: Fri Apr 17 10:53:20 UTC 2020
New revision: 531922
URL: https://svnweb.freebsd.org/changeset/ports/531922

Log:
  lang/rust-nightly: Update to 1.44.0.20200417

  - Add workaround to fix build when CC/CXX have "clang" in them [1]
  - Add patch to allow build with outdated libgit2 0.99.0

  Changes:	https://github.com/rust-lang/rust/compare/485c5fb6e1...7f3df57724
  PR:		238556 [1]

Changes:
  head/lang/rust-nightly/Makefile
  head/lang/rust-nightly/distinfo
  head/lang/rust-nightly/files/patch-vendor_cc_src_lib.rs
  head/lang/rust-nightly/files/patch-vendor_libgit2-sys_build.rs
Comment 15 commit-hook freebsd_committer 2020-04-23 15:32:58 UTC
A commit references this bug:

Author: tobik
Date: Thu Apr 23 15:32:39 UTC 2020
New revision: 532685
URL: https://svnweb.freebsd.org/changeset/ports/532685

Log:
  lang/rust: Update to 1.43.0

  - Add workaround to fix build when CC/CXX have "clang" in them [1]
  - Respect AR to fix build with external toolchains [2]
  - Force rebuild all consumers to catch regressions early

  Changes:	https://blog.rust-lang.org/2020/04/23/Rust-1.43.0.html
  PR:		238556 [1], 245583 [2]
  Reported by:	Matthias Apitz <guru@unixarea.de> [1], Greg V <greg@unrelenting.technology> [2]
  Tested by:	mikael, pkubaj, tobik
  With hat:	rust
  Differential Revision:	https://reviews.freebsd.org/D24521

Changes:
  head/Mk/Uses/cargo.mk
  head/audio/ncspot/Makefile
  head/audio/spotify-tui/Makefile
  head/audio/spotifyd/Makefile
  head/benchmarks/hyperfine/Makefile
  head/devel/bingrep/Makefile
  head/devel/cargo-c/Makefile
  head/devel/cargo-tree/Makefile
  head/devel/desed/Makefile
  head/devel/git-absorb/Makefile
  head/devel/git-delta/Makefile
  head/devel/interactive_rebase_tool/Makefile
  head/devel/pijul/Makefile
  head/devel/racer/Makefile
  head/devel/racer/distinfo
  head/devel/rust-bindgen/Makefile
  head/devel/rust-cbindgen/Makefile
  head/devel/sccache/Makefile
  head/devel/sentry-cli/Makefile
  head/devel/tokei/Makefile
  head/dns/doh-proxy/Makefile
  head/editors/kak-lsp/Makefile
  head/editors/parinfer-rust/Makefile
  head/editors/xi-core/Makefile
  head/editors/xi-term/Makefile
  head/games/dose-response/Makefile
  head/games/genact/Makefile
  head/games/jaggedalliance2/Makefile
  head/games/veloren/Makefile
  head/graphics/ikona/Makefile
  head/graphics/librsvg2-rust/Makefile
  head/graphics/pastel/Makefile
  head/graphics/rx/Makefile
  head/graphics/svgbob/Makefile
  head/lang/rust/Makefile
  head/lang/rust/distinfo
  head/lang/rust/files/patch-src_stdarch_crates_std__detect_src_detect_mod.rs
  head/lang/rust/files/patch-vendor_cc_src_lib.rs
  head/lang/rust-bootstrap/Makefile
  head/lang/rust-bootstrap/distinfo
  head/mail/thunderbird/Makefile
  head/mail/thunderbird/files/patch-bug1580963
  head/misc/broot/Makefile
  head/multimedia/librav1e/Makefile
  head/multimedia/rav1e/Makefile
  head/multimedia/termplay/Makefile
  head/net/boringtun/Makefile
  head/net/findomain/Makefile
  head/net/proby/Makefile
  head/net/rabbiteer/Makefile
  head/net/routinator/Makefile
  head/net-im/fractal/Makefile
  head/net-p2p/parity-ethereum/Makefile
  head/security/acmed/Makefile
  head/security/cargo-audit/Makefile
  head/security/cloak/Makefile
  head/security/suricata/Makefile
  head/shells/ion/Makefile
  head/shells/starship/Makefile
  head/sysutils/dua-cli/Makefile
  head/sysutils/exa/Makefile
  head/sysutils/fd/Makefile
  head/sysutils/flowgger/Makefile
  head/sysutils/fselect/Makefile
  head/sysutils/fusefs-sandboxfs/Makefile
  head/sysutils/hexyl/Makefile
  head/sysutils/potnet/Makefile
  head/sysutils/rsfetch/Makefile
  head/sysutils/tealdeer/Makefile
  head/sysutils/vector/Makefile
  head/textproc/bat/Makefile
  head/textproc/ripgrep/Makefile
  head/textproc/sd/Makefile
  head/textproc/sonic/Makefile
  head/textproc/xsv-rs/Makefile
  head/www/cliqz/Makefile
  head/www/ffsend/Makefile
  head/www/firefox/Makefile
  head/www/firefox-esr/Makefile
  head/www/firefox-esr/files/patch-bug1580963
  head/www/geckodriver/Makefile
  head/www/jwt-cli/Makefile
  head/www/miniserve/Makefile
  head/www/newsboat/Makefile
  head/www/websocat/Makefile
  head/www/zola/Makefile
  head/x11/admiral/Makefile
  head/x11/alacritty/Makefile
  head/x11/squeekboard/Makefile