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

Provide variant pkg-config file for multi-threaded static lib #4020

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

Ansuel
Copy link
Contributor

@Ansuel Ansuel commented Apr 6, 2024

Multi-threaded static library require -pthread to correctly link and works.
The pkg-config we provide tho only works with dynamic multi-threaded library
and won't provide the correct libs and cflags values if lib-mt is used.

To handle this, introduce an env variable MT to permit advanced user to
install and generate a correct pkg-config file for lib-mt or detect if
lib-mt target is called.

With MT env set on calling make install-pc, libzstd.pc.in is a
pkg-config file for a multi-threaded static library.

On calling make lib-mt, a libzstd.pc is generated for a multi-threaded
static library as it's what asked by the user by forcing it.

libzstd.pc is changed to PHONY to force regeneration of it on calling
lib targets or install-pc to handle case where the same directory is
used for mixed compilation.

This was notice while migrating from meson to make build system where
meson generates a correct .pc file while make doesn't.

@facebook-github-bot
Copy link

Hi @Ansuel!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

lib/Makefile Outdated
@@ -319,6 +319,17 @@ libzstd.pc: libzstd.pc.in
-e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
$< >$@

mt-libzstd.pc: mt-libzstd.pc.in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both recipes look identical.
So they could be combined.

@Cyan4973 Cyan4973 self-assigned this Apr 6, 2024
@Cyan4973
Copy link
Contributor

Cyan4973 commented Apr 6, 2024

I understand the need,
but I suspect the same capability could be created without adding a new make target and a new sed intermediate.
I would likely prefer this capability to be controlled via a build parameter.

@Ansuel
Copy link
Contributor Author

Ansuel commented Apr 6, 2024

Do you mean a special env on calling make install-pc ?

Also IMHO adding extra sed and token in the .in file might result in the file more bloated than keeping the thing separated but I understand it since I also hate duplicating things... It's just that makefile makes thing hard to handle with file stamp.

@Cyan4973
Copy link
Contributor

Cyan4973 commented Apr 6, 2024

Do you mean a special env on calling make install-pc ?

Yes.

It seems it would make sense to use the same variable both to create a MT static library, which would now depend on -pthread, and then to update the libzstd.pc with the correct link flags.

@Ansuel
Copy link
Contributor Author

Ansuel commented Apr 6, 2024 via email

@Ansuel Ansuel force-pushed the install-mt-pc branch 2 times, most recently from 5774737 to 8d88874 Compare April 8, 2024 15:44
Multi-threaded static library require -pthread to correctly link and works.
The pkg-config we provide tho only works with dynamic multi-threaded library
and won't provide the correct libs and cflags values if lib-mt is used.

To handle this, introduce an env variable MT to permit advanced user to
install and generate a correct pkg-config file for lib-mt or detect if
lib-mt target is called.

With MT env set on calling make install-pc, libzstd.pc.in is a
pkg-config file for a multi-threaded static library.

On calling make lib-mt, a libzstd.pc is generated for a multi-threaded
static library as it's what asked by the user by forcing it.

libzstd.pc is changed to PHONY to force regeneration of it on calling
lib targets or install-pc to handle case where the same directory is
used for mixed compilation.

This was notice while migrating from meson to make build system where
meson generates a correct .pc file while make doesn't.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@Ansuel
Copy link
Contributor Author

Ansuel commented Apr 8, 2024

@Cyan4973 I pushed a more advanced version of this... What do you think?

I also think there was a very latent bug in how the .pc file was handled on dirty build. (since lib generates the .pc, any call to install-pc would ignore any custom values of the PREFIX env) should be fixed by forcing .pc regeneration every time.

@Cyan4973
Copy link
Contributor

Cyan4973 commented Apr 8, 2024

Yes, that looks much better.

Give me some time to properly review the build/install flow, I should be able to comment this week.

@Ansuel
Copy link
Contributor Author

Ansuel commented Apr 8, 2024

@Cyan4973 no problem and thanks for reviewing this. We recently switched from xz to zstd on openwrt and this is just an effort to upstream our downstream patch (we use multi-threaded static library on our build systems)

Copy link
Contributor

@Cyan4973 Cyan4973 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@Cyan4973 Cyan4973 merged commit fb5a5e4 into facebook:dev Apr 16, 2024
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants