blas-lapack-rs / blas-src

BLAS source of choice
Other
39 stars 18 forks source link

Accelerate Linkage Failure -- without explicit linkage in build.rs #22

Open ethanmsl opened 9 months ago

ethanmsl commented 9 months ago

General Description:

The accelerate libary fails to link, despite correct dependency and feature specification. Clonable minmial repo example below. For a simple crate, addition of a build.rs script explicitely linking the library seems to fix this ("cargo:rustc-link-lib=framework=Accelerate").

Exception:

However, not show below, I was not able to fix this problem with a build-script for a Workspace based repo.

Minimal Repo Example:

Error on build:

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="
...
"
  = note: ld: Undefined symbols:
            _cblas_cgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_dgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_sgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_zgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `accelerate-test` (bin "accelerate-test") due to previous error

Caused by:
  process didn't exit successfully: `/Users/username/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name accelerate_test --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=181 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=df9792214fc029cd -C extra-filename=-df9792214fc029cd --out-dir /Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps -C incremental=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/incremental -L dependency=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps --extern blas_src=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libblas_src-8261a14688e7d167.rlib --extern ndarray=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libndarray-cebad4e9c98c9d7b.rlib --extern ndarray_linalg=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libndarray_linalg-435cbc831f01e25f.rlib` (exit status: 1)

System & Cargo information:

astraw commented 9 months ago

Thanks for the report. I confirm the same behavior on my machine. The accelerate-src crate does print "cargo:rustc-link-lib=framework=Accelerate" but with recent Rust versions, this linker arg isn't getting picked when building the binary. This transitive setting of linker args by dependencies previously worked but was unintentional and has been discontinued. So you would indeed need to set linker args in the final binary.

Ideally blas-src and accelerate-src should make this as easy as possible, e.g. by implementing and documenting use of the DEP_ environment variables and this mechanism.