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.

Scope boundaries and intentionally unchanged behavior

This PR is deliberately limited to explicit static pkg-config resolution and ordered propagation of the resulting flags.

It does not:

  • infer static pkg-config mode from ambient CFLAGS or LDFLAGS; these remain opaque compiler pass-through inputs. Static mode is selected through V's parsed -cflags/-ldflags -static options or an explicit #pkgconfig --static directive;
  • implement target-aware pkg-config or sysroot selection for cross-compilation. The existing protection against leaking host include and library paths into another target remains unchanged;
  • change historical dynamic pkg-config behavior;
  • require an external pkgconf executable at compiler runtime;
  • change the pre-existing mixed-case -l*.LIB normalization behavior.

Previously reviewed non-actionable findings

The following recurring Codex findings have already been checked with executable probes:

  • Ambient CFLAGS / LDFLAGS should select static mode: rejected because these variables are backend pass-through inputs, not semantic dependency-resolution selectors.
  • Repeated dependency graph traversals must be preserved: rejected against pkgconf 2.5.1. For shared public/private dependencies, multiple roots, cycles, and diamonds, pkgconf and V emit each dependency once in the same order. Explicit repeated library fragments and positional linker groups are still preserved.
  • Static metadata-only queries must validate the dependency closure: rejected against the selected pkgconf 2.5.1 oracle. Metadata-only queries remain direct reads, while --exists and flag-producing queries validate the required closure.
  • Cross-target pkg-config flags should be retained: rejected as pre-existing out-of-scope behavior. A correct solution requires an explicit target pkg-config/sysroot contract rather than reusing host paths.
  • A different public-cycle ordering should be used: rejected because the claimed ordering is version-dependent; this implementation follows pkgconf 2.5.1.
  • Out of scope: this PR does not make run_result().output safe for arbitrary unquoted shell or Make embedding, since the compiler consumes structured cflags/link_flags directly. It also does not extend the parser to cover pkgconf-specific escaped-hash handling in variable assignments; that requires a separate cross-mode parser change and is not needed for the reported Windows static-linking issue.

@codex Please do not reopen these findings without a reproducer against the current PR head and the selected pkgconf 2.5.1 oracle.

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 Outdated
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 thread vlib/v/builder/cbuilder/parallel_cc.v Outdated
Comment thread vlib/v/builder/cc.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/checker/checker.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 38fffb7 to 9068717 Compare July 20, 2026 15:48
@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: 9068717919

ℹ️ 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 Outdated
Comment thread vlib/v/builder/cc.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pref/default.v
Comment thread vlib/v/builder/cc.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 9068717 to 81ecef0 Compare July 20, 2026 20:41
@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: 81ecef0d10

ℹ️ 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 thread vlib/v/ast/cflags.v Outdated
Comment thread vlib/v/builder/msvc_windows.v
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 81ecef0 to ea799b8 Compare July 20, 2026 21:46
@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: ea799b8e13

ℹ️ 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 thread vlib/v/checker/checker.v
Comment thread vlib/v/pkgconfig/pkgconfig.v
@GGRei

GGRei commented Jul 21, 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: ea799b8e13

ℹ️ 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/ast/cflags.v Outdated
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 ea799b8 to e1395ec Compare July 21, 2026 07:48
@GGRei

GGRei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review but reread the PR description and follow the scope and review instructions stated there.

@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: e1395ec850

ℹ️ 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/pkgconfig/pkgconfig.v
Comment thread vlib/v/builder/cc.v Outdated
Comment thread vlib/v/builder/cc.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from e1395ec to 7fb169a Compare July 21, 2026 09:20
@GGRei

GGRei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review but reread the PR description and follow the scope and review instructions stated there.

@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: 7fb169a2e5

ℹ️ 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 Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 7fb169a to eb54738 Compare July 21, 2026 10:22
@GGRei

GGRei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review but reread the PR description and follow the scope and review instructions stated there.

@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: eb54738718

ℹ️ 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/main.v
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
Comment thread vlib/v/pkgconfig/pkgconfig.v Outdated
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from eb54738 to 6e4decc Compare July 21, 2026 11:24
@GGRei

GGRei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review but reread the PR description and follow the scope and review instructions stated there.

@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: 6e4decc5ba

ℹ️ 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 on lines +687 to +690
previous := m.find_visible(fragment)
if previous >= 0 && m.should_merge_visible(previous, fragment) {
m.fragments.delete(previous)
m.merge_visible.delete(previous)

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 direct archive operands

When a public Libs: field intentionally repeats a direct archive operand, e.g. Libs: /path/libcycle.a /path/libcycle.a, this merge path treats the archive like a normal visible fragment and deletes the earlier occurrence before appending the later one. Repeating a static archive is a valid way for .pc metadata to satisfy circular symbol dependencies, so V can now emit only one archive and fail links that the pkg-config metadata explicitly made repeatable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The circular-archive scenario is real, but this is not actionable for this PR. For ordinary public Libs fragments, V intentionally follows pkgconf 2.5.1, which also collapses A B A to B A. Repetitions required for circular resolution are already preserved in Libs.private, linker groups, and positional epochs, and the existing tests explicitly encode that policy. Changing public direct archives would diverge from the selected oracle and expand the scope beyond vlang/gui#74.

@GGRei

GGRei commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review but reread the PR description and follow the scope and review instructions stated there.

@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: 6e4decc5ba

ℹ️ 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/main.v
Comment on lines +351 to +352
if flag.starts_with(prefix) {
res << flag

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 split operands in static-only filters

When a static .pc file uses valid split operands such as Libs: -L /dir -l foo or Cflags: -I /dir, this token-by-token filter keeps only the -L/-l/-I control token for --*-only-* queries and drops the following operand; --libs-only-other has the inverse problem and emits those dropped operands as standalone “other” flags. In #pkgconfig --static --libs-only-L ... the checker then feeds a bare -L into parse_pkgconfig_link_flags, which rejects it as missing a path, while the CLI output is also unusable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rejected for this PR. pkgconf 2.5.1 produces the same bare controls and standalone operands for split-form ---only- queries, and V's historical dynamic directive behaves identically. The complete static compiler path used by vlang/gui#74 preserves the split pairs and links successfully. Making these metadata-only filters pair-aware would diverge from the selected oracle and expand this PR into a general CLI-filter contract change.

@medvednikov medvednikov reopened this Jul 21, 2026
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 6e4decc to 5ef7e9d Compare July 22, 2026 11:00
@GGRei
GGRei force-pushed the feature/pkgconfig-static-linking branch from 5ef7e9d to d2662d9 Compare July 23, 2026 09:57
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

2 participants