-
Notifications
You must be signed in to change notification settings - Fork 2
Deliver libddprof_ffi as a shared library #22
Conversation
@@ -8,7 +8,9 @@ edition = "2018" | |||
license = "Apache-2.0" | |||
|
|||
[lib] | |||
crate-type = ["lib", "staticlib"] | |||
# LTO is ignored if "lib" is added as crate type | |||
# cf. https://github.com/rust-lang/rust/issues/51009 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice referencing this
@@ -30,6 +31,7 @@ case "$target" in | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking the mac os builds !
@@ -14,3 +14,5 @@ debug = 2 # full debug info | |||
|
|||
[profile.release] | |||
debug = 1 # line tables only | |||
lto = true | |||
codegen-units = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I agree there is room for improvements concerning the APIs, we could provide some helpers function like
to_slice_xxx
on 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.