Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust 1.82 + cross compiling to aarch64-apple-darwin results in iconv linker error #289

Closed
rfairfax opened this issue Oct 24, 2024 · 3 comments

Comments

@rfairfax
Copy link
Contributor

We have a project that uses zstd-sys, which in turn pulls in libiconv and libcharset dependencies. On rust 1.81 and prior cargo-zigbuild was able to link properly via what looks like the tbd files that cargo-zigbuild drops.

When we compile the same code with 1.82 we get an error like the following:

  = note: error: unable to find dynamic system library 'iconv' using strategy 'paths_first'. searched paths:
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libiconv.tbd
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libiconv.dylib
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libiconv.so
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libiconv.a
          error: unable to find dynamic system library 'charset' using strategy 'paths_first'. searched paths:
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libcharset.tbd
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libcharset.dylib
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libcharset.so
            /workspace/oss-repo/core/src/rust/target/aarch64-apple-darwin/debug/build/zstd-sys-5f411c27504b93ea/out/libcharset.a

I'm not sure what combination of settings is tripping this up as the project is complex, but here's our repro:

# With Rust 1.82 installed

git clone --branch=develop https://github.com/filodb/FiloDB.git repro
cd repro/core/src/rust
cargo zigbuild --target aarch64-apple-darwin
@luketaverne
Copy link

luketaverne commented Oct 28, 2024

Hi all, I’ve run into the same issue. It can be reproduced with a simple helloworld with the following steps on Ubuntu (20.04):

pyenv shell 3.10.0 # python version I used
python -m venv .venv
source .venv/bin/activate
pip install "maturin[zig]"

maturin new helloworld # press enter on pyo3
cd helloworld

# 1.81 works
rustup toolchain install 1.81
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
maturin build --release --target aarch64-apple-darwin -i python3.10 --zig # --zig invokes cargo-zigbuild
maturin build --release --target x86_64-apple-darwin -i python3.10 --zig 

# both compile, now do 1.82
rustup toolchain install 1.82
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
maturin build --release --target aarch64-apple-darwin -i python3.10 --zig
maturin build --release --target x86_64-apple-darwin -i python3.10 --zig

Gives the following error:

(.venv) luke@luke-desktop:~/maturin-zig/helloworld$ maturin build --release --target x86_64-apple-darwin -i python3.10 --zig
 Found pyo3 bindings
 Found CPython 3.10
 Using build options features from pyproject.toml
 Using `MACOSX_DEPLOYMENT_TARGET=10.12` for x86_64-apple-darwin by default
   Compiling unindent v0.2.3
   Compiling once_cell v1.20.2
   Compiling cfg-if v1.0.0
   Compiling pyo3-build-config v0.22.5
   Compiling libc v0.2.161
   Compiling memoffset v0.9.1
   Compiling pyo3-macros-backend v0.22.5
   Compiling pyo3-ffi v0.22.5
   Compiling pyo3 v0.22.5
   Compiling pyo3-macros v0.22.5
   Compiling helloworld v0.1.0 (/home/luke/maturin-zig/helloworld)
error: linking with `/home/luke/.cache/cargo-zigbuild/0.19.3/zigcc-x86_64-apple-darwin-db1e.sh` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/luke/maturin-zig/.venv/bin:/usr/local/cuda/bin:/home/luke/.cargo/bin:/home/luke/.pyenv/shims:/home/luke/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/luke/.local/share/JetBrains/Toolbox/scripts" VSLANG="1033" ZERO_AR_DATE="1" "/home/luke/.cache/cargo-zigbuild/0.19.3/zigcc-x86_64-apple-darwin-db1e.sh" "-Wl,-exported_symbols_list" "-Wl,/tmp/rustctP7gYA/list" "-arch" "x86_64" "-m64" "/tmp/rustctP7gYA/symbols.o" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/helloworld.helloworld.39b5626b2ea3a229-cgu.0.rcgu.o" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/helloworld.helloworld.39b5626b2ea3a229-cgu.1.rcgu.o" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/helloworld.6mzpv3gfb9o9ritdksmol1jg7.rcgu.o" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libpyo3-8f8a9608071a5f95.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libcfg_if-91f3e21e04e8c380.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libmemoffset-5ff88791c6a469df.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libonce_cell-1d611e34cc186fc9.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libpyo3_ffi-99f47721ff8d8e39.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/liblibc-da3b39af13a72771.rlib" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libunindent-c611096cc0e65ddc.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libstd-61602592c271c404.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-aeb4058a408754f7.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libobject-2347acd1a76495bc.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-2cacaa99e1370983.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-d22d75eab3ee9f91.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libgimli-d45a4af6567e40f5.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-629221368a04a8cc.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-ccf80679c2766d42.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-343b4303636920e6.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-4ade444259fc53a0.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libminiz_oxide-45c3b99287a6b825.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libadler-bc7af87c325a8997.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libunwind-94df3cb34810525c.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-c37598a755f715a4.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liblibc-afe23bae68f053d8.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liballoc-f4619dbb652638d6.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-3068aae2853ba0bc.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcore-eb22ed92aa3586d1.rlib" "/home/luke/.rustup/toolchains/1.82-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-304a1afb7a72a7c7.rlib" "-liconv" "-lSystem" "-lc" "-lm" "-o" "/home/luke/maturin-zig/helloworld/target/x86_64-apple-darwin/release/deps/libhelloworld.dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "-undefined" "dynamic_lookup" "-Wl,-install_name,@rpath/helloworld.cpython-310-darwin.so"
  = note: error: unable to find dynamic system library 'iconv' using strategy 'paths_first'. searched paths: none
          error: unable to find dynamic system library 'charset' using strategy 'paths_first'. searched paths: none

I hope this helps figure out what happened between cargo-zigbuild / rust versions 🙂

@messense
Copy link
Member

messense commented Nov 1, 2024

Seems like this is caused by rust-lang/rust#128370

@messense
Copy link
Member

Fixed in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants