Bug 274723 - lang/rust 1.73.0 chokes
Summary: lang/rust 1.73.0 chokes
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: FreeBSD Rust Team
URL:
Keywords:
: 274724 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-10-26 01:35 UTC by doctor
Modified: 2023-12-09 15:05 UTC (History)
8 users (show)

See Also:
bugzilla: maintainer-feedback? (rust)


Attachments
[patch] fix link failure when 'unable to find library -lzlibstatic' (826 bytes, patch)
2023-11-01 10:20 UTC, John Hein
jcfyecrayz: maintainer-approval? (rust)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description doctor 2023-10-26 01:35:39 UTC
getting 

expected success, got: exit status: 101


Traceback (most recent call last):
  File "/usr/ports/lang/rust/work/rustc-1.73.0-src/x.py", line 50, in <module>
    bootstrap.main()
  File "/usr/ports/lang/rust/work/rustc-1.73.0-src/src/bootstrap/bootstrap.py", line 1111, in main
    bootstrap(args)
  File "/usr/ports/lang/rust/work/rustc-1.73.0-src/src/bootstrap/bootstrap.py", line 1086, in bootstrap
    run(args, env=env, verbose=build.verbose, is_bootstrap=True)
  File "/usr/ports/lang/rust/work/rustc-1.73.0-src/src/bootstrap/bootstrap.py", line 184, in run
    raise RuntimeError(err)
RuntimeError: failed to run: /usr/ports/lang/rust/work/_build/bootstrap/debug/bootstrap dist --jobs=1
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/lang/rust
*** Error code 1

Stop.
make: stopped in /usr/ports/lang/rust

===>>> make build failed for lang/rust
===>>> Aborting update

Major shopstopper
Comment 1 Daniel Engberg freebsd_committer freebsd_triage 2023-10-26 04:50:02 UTC
You need to provide more information, (OS version, Arch, amount of RAM) and I'd also suggest that you look in /var/log/messages for clues

It builds fine on 13.2 (amd64, aarch64) and 14.0 (amd64) on my end and it's also been tested in Poudriere before being committed.
Comment 2 Vanilla I. Shu freebsd_committer freebsd_triage 2023-10-26 08:30:03 UTC
in my test, it's failed with PORT_LLVM option.
Comment 3 Li-Wen Hsu freebsd_committer freebsd_triage 2023-10-26 13:49:03 UTC
*** Bug 274724 has been marked as a duplicate of this bug. ***
Comment 4 russo 2023-10-26 15:33:34 UTC
I am also having problems getting rust to compile on FreeBSD 12.4-STABLE.

The error I'm getting is:


error: linking with `cc` failed: exit status: 1
  |
...enormous  line that ends with:
"/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/deps/librustc_driver-b52f282798363e41.so" "-shared" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib"
  = note: ld: error: unable to find library -lzlibstatic
          cc: error: linker command failed with exit code 1 (use -v to see invocation)
          

    Building
Did not run successfully: exit status: 1stc_driver                
    LD_LIBRARY_PATH="/usr/ports/lang/rust/work/bootstrap/lib:/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/release/deps:/usr/ports/lang/rust/work/bootstrap/lib" "/usr/ports/lang/rust/work/bootstrap/bin/rustc" "--crate-name" "rustc_driver" "--edition=2021" "compiler/rustc_driver/src/lib.rs" "--error-format=json" "--json=diagnostic-rendered-ansi,artifacts,future-incompat" "--diagnostic-width=80" "--crate-type" "dylib" "--emit=dep-info,link" "-C" "prefer-dynamic" "-C" "opt-level=3" "-C" "embed-bitcode=no" "-Zunstable-options" "--check-cfg" "values(feature)" "--check-cfg" "names()" "--check-cfg" "values()" "-C" "metadata=b52f282798363e41" "-C" "extra-filename=-b52f282798363e41" "--out-dir" "/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/deps" "--target" "x86_64-unknown-freebsd" "-C" "linker=cc" "-L" "dependency=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/deps" "-L" "dependency=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/release/deps" "--extern" "rustc_driver_impl=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/deps/librustc_driver_impl-e385610155f4b4e4.rlib" "--cfg=bootstrap" "--cfg=windows_raw_dylib" "-Csymbol-mangling-version=v0" "-Zunstable-options" "--check-cfg=values(bootstrap)" "--check-cfg=values(parallel_compiler)" "--check-cfg=values(no_btreemap_remove_entry)" "--check-cfg=values(crossbeam_loom)" "--check-cfg=values(span_locations)" "--check-cfg=values(rustix_use_libc)" "--check-cfg=values(emulate_second_only_system)" "--check-cfg=values(windows_raw_dylib)" "-Zmacro-backtrace" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Zunstable-options" "-Csplit-debuginfo=off" "-Zunstable-options" "-Wrustc::internal" "-Cprefer-dynamic" "-Z" "binary-dep-depinfo" "-L" "native=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/build/psm-bbdb4f23c5d43a73/out" "-L" "native=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-rustc/x86_64-unknown-freebsd/release/build/rustc_llvm-b286433a4e4cdd9d/out" "-L" "native=/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/llvm/build/lib" "-Wrust_2018_idioms" "-Wunused_lifetimes" "-Wsemicolon_in_expressions_from_macros" "--sysroot" "/usr/ports/lang/rust/work/_build/x86_64-unknown-freebsd/stage0-sysroot" "-Ztls-model=initial-exec" "-Z" "force-unstable-if-unmarked"
Building-------------
error: could not compile `rustc_driver` (lib) due to previous error


Caused by:
  process didn't exit successfully:  [...followed by an enormous line and the traceback reported by the original poster]

Strangely, libzlibstatic.a exists in /usr/local/lib and was installed by the package assimp.
Comment 5 russo 2023-10-26 15:34:25 UTC
And in my case, there is no message in /var/log/messages, as this is not an out-of-memory issue or segfault.
Comment 6 rkoberman 2023-10-26 16:17:39 UTC
I am seeing the identical failure to the original report. 
FreeBSD ptavv 15.0-CURRENT FreeBSD 15.0-CURRENT #9 main-n265842-6e92fc930943-dirty: Wed Oct 25 15:48:31 PDT 2023     root@ptavv:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
===> The following configuration options are available for rust-1.73.0:
     DOCS=on: Build and/or install documentation
     GDB=off: Install ports gdb (necessary for debugging rust programs)
     LTO=off: Use Link-Time Optimization
     PORT_LLVM=off: Build against devel/llvm instead of bundled copy (experimental)
     SOURCES=on: Install source files
     WASM=on: Build the WebAssembly target (wasm32-unknown-unknown)

24G RAM Alder Lake 2p+8e

When I say "identical", I mean the error message is line by line and character by character identical.
Comment 7 John Hein 2023-10-26 20:14:39 UTC
(In reply to russo from comment #4)
I can reproduce the "unable to find library -lzlibstatic".

The issue is that cmake finds a zlib in /usr/local/lib first (before /usr/lib).  If zlib is installed in /usr/local, cmake will find it and try to use it.

In my case, multimedia/assimp is installed, and it has /usr/local/lib/libzlibstatic.a

share/cmake/Modules/FindZLIB.cmake has:

if(ZLIB_USE_STATIC_LIBS)
  set(ZLIB_NAMES zlibstatic zlibstat zlib z)
  set(ZLIB_NAMES_DEBUG zlibstaticd zlibstatd zlibd zd)
else()
  set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic zlibwapi zlibvc zlibstat)
  set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd zlibwapid zlibvcd zlibstatd)
endif()

I don't see ZLIB_USE_STATIC_LIBS defined in the rust source tree (and FindZLIB.cmake says that is off by default).  So I would have expected cmake to find /usr/lib/libz.* before any libzlibstatic.*, but clearly it does find the libzlibstatic:

-- Found ZLIB: /usr/local/lib/libzlibstatic.a (found version "1.2.12")

And in work/_build/x86_64-unknown-freebsd/llvm/build/CMakeCache.txt:

//Path to a file.
ZLIB_INCLUDE_DIR:PATH=/usr/include

//Path to a library.
ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND

//Path to a library.
ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/local/lib/libzlibstatic.a


So somehow cmake is preferring that version of zlib library before /usr/lib/libzlib.* - cmake's logic can be difficult to follow, especially in a complex build, and I have only made a cursory attempt to understand why it does that.  So I don't have an answer about that yet.

Then when it comes time to link something with libzlibstatic, there is no -L/usr/local/lib, so the linker can't find it.  It seems cmake makes an assumption that the libraries it finds in cmake's default search path will be found by the linker which must (it appears to be thinking without checking) have the same default search path.


Note that cmake is run during 'make build', not 'make configure', for lang/rust.  So adding CMAKE_ARGS=-DZLIB_ROOT=/usr to lang/rust/Makefile (to force using zlib from base) won't get passed on to the cmake that is invoked during 'make build'.


Long story short, I don't have a solution at this time but have determined the cause of the linker failure.  If there is a way to get -DZLIB_ROOT=/usr passed in to the cmake that is invoked, that might do the trick.
Comment 8 John Hein 2023-10-26 20:16:31 UTC
It would be good to change this title to something like "lang/rust: 'make build dies' - linker fails to find -lzlibstatic"
Comment 9 John Hein 2023-10-26 20:17:36 UTC
This failure did not occur for rust 1.72.0

I have not determined the difference that triggers the failure for 1.73.0
Comment 10 John Hein 2023-10-26 20:20:41 UTC
Oh... and it's not clear that the OP's failure (from comment 0) is the same as the failure shown in comment 4.  There might be more than one issue.

But I see the same snippet mentioned in comment 0 for the case where it failed to link with -lzlibstatic.  So it could very well be the same problem.
Comment 11 rkoberman 2023-10-26 22:55:50 UTC
After capturing the entire build log, it is pretty clear that my (and the OP's) issues are with failing to find zlibstatic. I had to look just a tiny bit earlier in the log to determine that failure to find zlibstatic as the real issue.
Comment 12 John Hein 2023-11-01 10:20:45 UTC
Created attachment 246047 [details]
[patch] fix link failure when 'unable to find library -lzlibstatic'

The attached patch fixes the link failure when 'unable to find library -lzlibstatic'.

It explicitly enforces the use of -lzlib in base (/usr/lib) even in cases where a different zlib is detected in LOCALBASE - the cmake port prefers to look in LOCALBASE first in its default search. There's no way to change that with an environment variable (cmake modules only support environment variables if they are explicitly written to do so, and FindZlib.cmake is not). And I could not find a way to pass cmake options (like -DZLIB_ROOT=/usr) via the current do-build target implementation in lang/rust/Makefile.

No need to bump PORTREVISION - it helps in cases when lang/rus t was not building, so there would be no existing package that would be built differently by this change.
Comment 13 russo 2023-11-03 00:41:18 UTC
(In reply to John Hein from comment #12)
I just rebuilt rust with your patch and it worked fine.

Shortly thereafter I noticed that my system wanted me to rebuild assimp, and a look at the git log showed bug 274717 to be the reason for that.  That issue was also about rust failing, but it was not linked to this one and was "fixed" by changing assimp's install.

So it appears that this issue, while it *is* a rust cmake failing, has already been addressed by removing zlibstatic.a from the files installed by assimp.

This may have been "overcome by events."
Comment 14 John Hein 2023-11-06 15:41:25 UTC
(In reply to russo from comment #13)
That only helps with one case of one port that installed a zlib in /usr/local.  lang/rust is still susceptible to other ports that may install zlib in /usr/local.  It will detect that version of zlib but (a) will not provide the -L flags to link with that library and (b) if it were able to link with the /usr/local zlib, that would be a hidden dependency (since lang/rust/Makefile would not list it as a LIB_DEPENDS item).

It is better to tell lang/rust to explicitly use zlib from base.