pkgconfig: support static linking#27869
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d8524ee18
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
7d8524e to
a4476e6
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4476e6893
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a4476e6 to
952ece8
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 952ece874f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
952ece8 to
6b36c0d
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b36c0d145
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6b36c0d to
2f710ee
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f710ee23d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2f710ee to
38fffb7
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38fffb7950
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| if contains_exact_cflag_token(p.cflags, '-static') | ||
| || contains_exact_cflag_token(p.ldflags, '-static') { |
There was a problem hiding this comment.
Honor static env flags before resolving pkg-config
When a build requests static linking through environment CFLAGS or LDFLAGS, setup_ccompiler_options still forwards those env values to the C compiler, but this mode detection only inspects p.cflags/p.ldflags. In that environment, #pkgconfig stays in dynamic mode and omits Requires.private/Libs.private, while the final link is static and can fail with missing libraries.
Useful? React with 👍 / 👎.
| if pkgconfig_pthread && !projected.any(pref.contains_exact_cflag_token(it, '-pthread')) { | ||
| projected << '-pthread' |
There was a problem hiding this comment.
Mirror pthread compiler gating in parallel-cc
For -parallel-cc, this unconditionally adds -pthread to every object compile command whenever a static pkg-config linker segment contains it, but the normal compile-only path below only projects that flag for GCC/Clang/C++ and explicitly leaves TCC/MSVC unsupported. An explicit static #pkgconfig used with parallel TCC (or another non-GNU compiler) can therefore fail or behave differently from the non-parallel build.
Useful? React with 👍 / 👎.
| if arg in ['-Wl,-(', '-Wl,-)'] { | ||
| return os.quoted_path(arg) |
There was a problem hiding this comment.
Escape group aliases in generated project commands
This escaping is only applied to the direct compile path; -generate-c-project still writes all_args.join(' ') into build.sh/Makefile. When a static .pc emits GNU group aliases like -Wl,-( and -Wl,-), the generated POSIX shell command has an unquoted ( token and fails with a shell syntax error even though the normal compile path succeeds.
Useful? React with 👍 / 👎.
| if r.visited[pkgname] { | ||
| return |
There was a problem hiding this comment.
Preserve repeated public deps across private branches
When a root package has Requires: a and Requires.private: b, and b also publicly requires a, this global visited check suppresses the second visit to a. Static archive links can need the repeated -la around -lb for left-to-right symbol resolution, so emitting only one copy can leave public/private dependency cycles unresolved.
Useful? React with 👍 / 👎.
| c.table.parse_pkgconfig_link_flags(result.link_flags.join(' '), c.mod, | ||
| c.pref.compile_defines_all) or { |
There was a problem hiding this comment.
Route static pkg-config libs into MSVC linker args
When compiling with -cc msvc and a source explicitly uses #pkgconfig --static --libs, these libraries are stored only in link_flag_segments. The MSVC driver builds its library list from v.get_os_cflags() via msvc_string_flags and never consumes these ordered segments, so the .lib/-l entries from static pkg-config are dropped from the cl.exe invocation.
Useful? React with 👍 / 👎.
Summary
This PR adds generic static pkg-config support to V.
-statictoken is passed through-cflags#pkgconfig --staticdirectives.pcfield names case-insensitivelyThe implementation and tests are fully self-contained. No Pango, vglyph, vcpkg, external consumer, or external pkgconf oracle is added to V or its CI.
This issue was originally identified on vgui.
Validation
A dedicated smoke matrix passed on:
All changed V files pass
v fmt -verify, andgit diff --checkis clean.Fixes vlang/gui#74