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

meson: don't add -pthread to static linking flags on Windows #3931

Merged
merged 1 commit into from
Apr 21, 2024
Merged

meson: don't add -pthread to static linking flags on Windows #3931

merged 1 commit into from
Apr 21, 2024

Conversation

bgilbert
Copy link
Contributor

@bgilbert bgilbert commented Mar 7, 2024

Meson always returns -pthread in dependency('threads') on non-MSVC compilers. On Windows we use Windows threading primitives, so we don't need this. Avoid adding -pthread to libzstd's link flags, either as a Meson subproject or via pkg-config Libs.private, so the application doesn't inadvertently depend on winpthreads.

Add a Meson MinGW cross-compile CI test that checks for this. It turns out that pzstd fails to build in that environment, so have the test skip building contrib for now.

@bgilbert
Copy link
Contributor Author

bgilbert commented Apr 4, 2024

Is there anything I can do to help this move forward?

@Cyan4973
Copy link
Contributor

Cyan4973 commented Apr 4, 2024

It's mostly a matter of finding someone for the review.

In my understanding, this PR is helpful when using meson to build zstd on Windows.

It seems this is a combination we don't have in CI, hence we can't "witness" the impact of this change.
An opened question at this stage is if it would be worthwhile to add (and if yes: how, and what's the runtime cost).

@bgilbert
Copy link
Contributor Author

bgilbert commented Apr 5, 2024

It's helpful for building zstd for Windows with MinGW, possibly via cross-compilation. Many application stacks will already use winpthreads, either because something in the stack uses pthreads explicitly, or because something uses C/C++ thread intrinsics and MinGW-w64 is configured to implement those via pthreads. In that case, zstd's current behavior amounts to harmless overlinking. My stack uses MinGW-w64 configured to implement intrinsics via Win32 primitives (a less common configuration), and does not otherwise use or ship winpthreads, so the current behavior produces an unsatisfied dependency.

If desired, I can see about adding a short test job for MinGW + Meson, or provide manual build instructions for verification.

@Cyan4973
Copy link
Contributor

Cyan4973 commented Apr 5, 2024

That would be a good idea.
It would help preserve this property across future modifications,
otherwise another contributor might come and change a detail which breaks this property, and we wouldn't notice.

Meson always returns -pthread in dependency('threads') on non-MSVC
compilers.  On Windows we use Windows threading primitives, so we don't
need this.  Avoid adding -pthread to libzstd's link flags, either as a
Meson subproject or via pkg-config Libs.private, so the application
doesn't inadvertently depend on winpthreads.

Add a Meson MinGW cross-compile CI test that checks for this.  It turns
out that pzstd fails to build in that environment, so have the test
skip building contrib for now.
@bgilbert bgilbert changed the title meson: don't link with -pthread on Windows meson: don't add -pthread to static linking flags on Windows Apr 10, 2024
@bgilbert
Copy link
Contributor Author

Added a CI job.

It turns out that the DLL doesn't end up linked against winpthreads, so the problem is limited to the linker flags we tell applications to use when linking with our static library. I've updated the PR description and commit message accordingly.

@Cyan4973 Cyan4973 self-assigned this Apr 10, 2024
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
Copy link
Contributor

I assume the last remaining CI error (cygwin) is unrelated

@bgilbert
Copy link
Contributor Author

Yes, looks like the Cygwin failure is a transient network issue.

@bgilbert
Copy link
Contributor Author

Is this ready to go in?

@Cyan4973
Copy link
Contributor

Is this ready to go in?

yep

@Cyan4973 Cyan4973 merged commit 1232d4c into facebook:dev Apr 21, 2024
94 checks passed
@bgilbert bgilbert deleted the pthread branch April 21, 2024 03:41
bgilbert added a commit to bgilbert/wrapdb that referenced this pull request Apr 21, 2024
Meson always returns -pthread in dependency('threads') on non-MSVC
compilers.  On Windows, zstd uses Windows threading primitives, so we
don't need this.  Avoid adding -pthread to libzstd's link flags, either as
a Meson subproject or via pkg-config Libs.private, so the application
doesn't inadvertently depend on winpthreads.

Merged upstream in facebook/zstd#3931.
eli-schwartz pushed a commit to mesonbuild/wrapdb that referenced this pull request Apr 21, 2024
Meson always returns -pthread in dependency('threads') on non-MSVC
compilers.  On Windows, zstd uses Windows threading primitives, so we
don't need this.  Avoid adding -pthread to libzstd's link flags, either as
a Meson subproject or via pkg-config Libs.private, so the application
doesn't inadvertently depend on winpthreads.

Merged upstream in facebook/zstd#3931.
willwray pushed a commit to willwray/wrapdb that referenced this pull request Apr 22, 2024
Meson always returns -pthread in dependency('threads') on non-MSVC
compilers.  On Windows, zstd uses Windows threading primitives, so we
don't need this.  Avoid adding -pthread to libzstd's link flags, either as
a Meson subproject or via pkg-config Libs.private, so the application
doesn't inadvertently depend on winpthreads.

Merged upstream in facebook/zstd#3931.
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