Aarch64-darwin rust-rocksdb bindgen linking error

I’ve spent way more time on this issue than I care to admit. I’m trying to use rust-rocksdb in a rust project in a nix flake. I have a minimal example that works under x86_64-linux but fails under aarch64-darwin. You can see and run the example here: GitHub - trevorbernard/rocksdb-nix

I’ve tried many permutations of different clang and libclang but all fail with the same error. Any help will be greatly appreciated.

nix build
warning: Git tree '/Users/tbernard/p/granola/rocksdb-nix' is dirty
error: builder for '/nix/store/s7w8mzn8s48g4js3pj9sk7nx9985py2g-rocksdb-nix-0.1.0.drv' failed with exit code 101;
       last 10 log lines:
       >                 rocksdb::ColumnFamilyDescriptor::~ColumnFamilyDescriptor() in liblibrocksdb_sys-912774aaa3cc819f.rlib(c.o)
       >                 std::__1::vector<rocksdb::ColumnFamilyDescriptor, std::__1::allocator<rocksdb::ColumnFamilyDescriptor>>::~vector[abi:v160006]() in liblibrocksdb_sys-912774aaa3cc819f.rlib(c.o)
       >                 std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::~vector[abi:v160006]() in liblibrocksdb_sys-912774aaa3cc819f.rlib(c.o)
       >                 _rocksdb_column_family_handle_destroy in liblibrocksdb_sys-912774aaa3cc819f.rlib(c.o)
       >                 ...
       >           ld: symbol(s) not found for architecture arm64
       >           clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       >
       >
       > error: could not compile `rocksdb-nix` (bin "rocksdb-nix") due to previous error
       For full logs, run 'nix-store -l /nix/store/s7w8mzn8s48g4js3pj9sk7nx9985py2g-rocksdb-nix-0.1.0.drv'.

I found the solution to my problem. I needed to point my linker to the following package when the (stdenv.cc.isClang && stdenv.isDarwin) is true:

NIX_LDFLAGS="-l${stdenv.cc.libcxx.cxxabi.libName}";

I updated my repo with the fix for posterity.

1 Like

For future readers, this should be addressed by llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx by a-n-n-a-l-e-e · Pull Request #292043 · NixOS/nixpkgs · GitHub without any such kludge.