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

Zig Binding doesn't work with static libopendal_c #2471

Closed
Xuanwo opened this issue Jun 16, 2023 · 7 comments · Fixed by #2473
Closed

Zig Binding doesn't work with static libopendal_c #2471

Xuanwo opened this issue Jun 16, 2023 · 7 comments · Fixed by #2473

Comments

@Xuanwo
Copy link
Member

Xuanwo commented Jun 16, 2023

Zig binding's test will fail if libopendal_c is build in static:

https://github.com/apache/incubator-opendal/actions/runs/5287703769/jobs/9568516765?pr=2470

error: ld.lld: undefined symbol: _Unwind_SetIP
    note: referenced by gcc.rs:217 (library/std/src/personality/gcc.rs:217)
    note:               std-8389830094602f5a.std.fd8b77e9-cgu.0.rcgu.o:(rust_eh_personality) in archive /home/runner/work/incubator-opendal/incubator-opendal/target/debug/libopendal_c.a
@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 16, 2023

cc @tisonkun and @kassane, would you like to take a look?

@tisonkun
Copy link
Member

build in static

Do you mean statically link glibc?

@kassane
Copy link
Contributor

kassane commented Jun 16, 2023

Static build of glibc on the Zig toolchain is problematic.
However it is possible to build musl-libc statically.

Note: the error is libunwind missing (eql to gcc_s) exception library (C++)
Try replacing in build.zig, .linkLibC() to .linkLibCpp() (libcxx+libuwind+libc+libcompiler-rt).

Using --verbose-link to see if the libraries linking.

Only, musl, libcxx and (custom)compiler-rt are static libraries.
https://github.com/ziglang/zig/tree/master/lib/libc
https://github.com/ziglang/zig/tree/master/lib/libunwind

@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 16, 2023

Do you mean statically link glibc?

change the crate-type of libopendal_c like this will break CI:

- crate-type = ["cdylib"]
+ crate-type = ["cdylib", "staticlib"]

@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 16, 2023

Try replacing in build.zig, .linkLibC() to .linkLibCpp() (libcxx+libuwind+libc+libcompiler-rt).

Thanks, I will give it a try!

@kassane
Copy link
Contributor

kassane commented Jun 16, 2023

Thanks, I will give it a try!

cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
make: Saindo do diretório '/home/kassane/Documentos/incubator-opendal/bindings/c'

Build Summary: 4/4 steps succeeded; 2/2 tests passed
test success
├─ run make success 142ms MaxRSS:54M
└─ run test 2 passed 1ms MaxRSS:10M
   └─ zig test Debug native success 1s MaxRSS:814M
[kassane@Catarino zig]$ ls ../../target/debug/
build  deps  examples  incremental  libopendal_c.a  libopendal_c.d

-- Edit

(Optional) My suggestion:
use https://github.com/rust-cross/cargo-zigbuild (rustc + zig linker)

@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 16, 2023

@kassane Thanks a lot!

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