Skip to content

pkgconfig: support static linking#27869

Open
GGRei wants to merge 1 commit into
vlang:masterfrom
GGRei:feature/pkgconfig-static-linking
Open

pkgconfig: support static linking#27869
GGRei wants to merge 1 commit into
vlang:masterfrom
GGRei:feature/pkgconfig-static-linking

Conversation

@GGRei

@GGRei GGRei commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds generic static pkg-config support to V.

  • enables static pkg-config resolution for GCC and Clang when an exact -static token is passed through -cflags
  • supports explicit #pkgconfig --static directives
  • resolves public and private dependency metadata recursively
  • preserves linker ordering, repeated libraries, and linker groups
  • handles supported .pc field names case-insensitively
  • keeps the existing dynamic behavior unchanged for normal builds, TCC, MSVC, and cross-compilation

The 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:

  • Linux GCC
  • Linux Clang
  • Linux TCC
  • macOS Clang
  • Windows UCRT64 GCC
  • Windows UCRT64 Clang
  • Windows MSVC
  • Windows TCC

All changed V files pass v fmt -verify, and git diff --check is clean.

Fixes vlang/gui#74

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/pref/default.v Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 7d8524e to a4476e6 Compare July 19, 2026 13:23
@GGRei

GGRei commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pref/default.v
Comment thread vlib/v/builder/cc.v
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from a4476e6 to 952ece8 Compare July 19, 2026 14:58
@GGRei

GGRei commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/builder/cc.v
Comment thread vlib/v/pref/default.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 952ece8 to 6b36c0d Compare July 19, 2026 18:07
@GGRei

GGRei commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pref/default.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 6b36c0d to 2f710ee Compare July 20, 2026 10:27
@GGRei

GGRei commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/checker/checker.v Outdated
Comment thread vlib/v/pref/default.v
Comment thread vlib/v/pkgconfig/main.v
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 2f710ee to 38fffb7 Compare July 20, 2026 12:28
@GGRei

GGRei commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread vlib/v/pref/default.v
Comment on lines +71 to +73
}
if contains_exact_cflag_token(p.cflags, '-static')
|| contains_exact_cflag_token(p.ldflags, '-static') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +41 to +42
if pkgconfig_pthread && !projected.any(pref.contains_exact_cflag_token(it, '-pthread')) {
projected << '-pthread'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread vlib/v/builder/cc.v
Comment on lines +1502 to +1503
if arg in ['-Wl,-(', '-Wl,-)'] {
return os.quoted_path(arg)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +370 to +371
if r.visited[pkgname] {
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread vlib/v/checker/checker.v
Comment on lines +4534 to +4535
c.table.parse_pkgconfig_link_flags(result.link_flags.join(' '), c.mod,
c.pref.compile_defines_all) or {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C error statically linking on Windows

1 participant