Deliver libddprof_ffi as a shared library#22
Conversation
| [lib] | ||
| crate-type = ["lib", "staticlib"] | ||
| # LTO is ignored if "lib" is added as crate type | ||
| # cf. https://github.com/rust-lang/rust/issues/51009 |
| "x86_64-apple-darwin") | ||
| expected_native_static_libs=" -framework Security -liconv -lSystem -lresolv -lc -lm -liconv" | ||
| native_static_libs="${expected_native_static_libs}" | ||
| shared_library_suffix=".dylib" |
There was a problem hiding this comment.
Thanks for checking the mac os builds !
| [profile.release] | ||
| debug = 1 # line tables only | ||
| lto = true | ||
| codegen-units = 1 |
There was a problem hiding this comment.
Is this something we want to put in the cargo config, or could we not make sure to have it as a command line argument in the CI ?
I'm thinking we dan't want to slow all of our build times. Only the build time to generate the github release.
WDYT ?
There was a problem hiding this comment.
As discussed, locally we will use the develop profile. We can leave the release profile optimised for size.
| @@ -46,6 +48,10 @@ sed < ddprof_ffi.pc.in "s/@DDProf_FFI_VERSION@/${version}/g" \ | |||
| | sed "s/@DDProf_FFI_LIBRARIES@/${native_static_libs}/g" \ | |||
| > "$destdir/lib/pkgconfig/ddprof_ffi.pc" | |||
There was a problem hiding this comment.
The concept of "native static libs" doesn't apply to a shared object. There will be dependencies, of course, but this isn't how we should be populating them for the .so.
There was a problem hiding this comment.
Thanks for pointing this out. I did put them in Libs.private when I had still hope to be able to make a single pkg-config file for both shared and static library, but since I could not do it, it's better to completely remove them for the shared library.
|
The shared library artifact for alpine is suspicious, particularly the runpath: |
Hum, indeed this is strange. But I don't expect this to be an issue, the runpath here is not useful to find dependencies since libddprof_ffi.so depends only on libgcc/libc.
We could remove runpath from the lib just to be extra cautious. WDYT @morrisonlevi ? |
* Reduce number of codegen units to further reduce ouput library size. * Deliver shared library alongside static library
Create ddprof_ffi-static.pc for linking with static library
…ddprof_ffi-static.pc for static linking
…sary for dynamic linking
b386c52 to
a3e8035
Compare
Rust adds some weird RPATH/RUNPATH to cdylibs on alpine-musl (cf. https://git.alpinelinux.org/aports/tree/community/rust/alpine-target.patch,https://git.alpinelinux.org/aports/tree/community/rust/need-rpath.patch).
a3e8035 to
06174b3
Compare
ivoanjo
left a comment
There was a problem hiding this comment.
Thanks for this! I left two tiny notes, and I'll try to wire this up in Ruby and report back with the experience :)
| static ddprof_ffi_ByteSlice to_byteslice(const char *s) | ||
| { | ||
| return {.ptr = (uint8_t *)s, | ||
| .len = strlen(s)}; | ||
| } | ||
|
|
||
| static ddprof_ffi_Slice_c_char to_slice_c_char(const char *s) | ||
| { | ||
| return {.ptr = s, | ||
| .len = strlen(s)}; | ||
| } |
There was a problem hiding this comment.
Not related to this PR, but this looks to me as a weird sharp edge in the libddprof API.
It's weird to have both ddprof_ffi_ByteSlice and ddprof_ffi_Slice_c_char when they are effectively the same (?).
Also, I had to write similar helpers for using libddprof, so perhaps it would make sense to export these (possibly as macros?) in ffi.h as well :)
There was a problem hiding this comment.
You usually don't want to encourage people to transport strings without an actual size associated to it. strlen is also not something you want encourage, so I don't know how I feel about exposing these types of APIs.
I guess we can also mention this :-)
There was a problem hiding this comment.
Hmmm... I'm guessing the "don't want to encourage" may be related to performance -- is that the case?
If so, would it make sense to call it something like to_slice_slow? I guess for a bunch of hardcoded strings ("ruby", "wall-clock", "nanoseconds", "service", ...) we just use them once so the cost is trivial so we could have the ease of use instead :)
There was a problem hiding this comment.
- I agree there is room for improvements concerning the APIs, we could provide some helpers function like
to_slice_xxxon top of FFI headers. Maybe even a more friendly C++ interface. - It's strange that slices for type/unit/filename/build_id/name/system_name/... are different from slices used for /tags/filenames.
But this would be subject of another pull request ;)
There was a problem hiding this comment.
I don't feel super strongly about this, but I would usually avoid relying on C style null terminated strings. Though it is not clear how we could avoid these conversions at boundaries or how to have a common types.
morrisonlevi
left a comment
There was a problem hiding this comment.
Did we check Alpine builds? I remember the compiler telling me it can't make shared libs on Alpine.
|
Yes, there is a test in CI that try linking why shared library. |
What does this PR do?
Motivation
Some clients prefer having a shared library rather than a static one.