Skip to content

Fix TCC compiler integration for parallel compilation#27033

Merged
medvednikov merged 2 commits intomasterfrom
claude/fix-ci-issues-BM9T0
Apr 30, 2026
Merged

Fix TCC compiler integration for parallel compilation#27033
medvednikov merged 2 commits intomasterfrom
claude/fix-ci-issues-BM9T0

Conversation

@medvednikov
Copy link
Copy Markdown
Member

Summary

This PR fixes several issues with TCC (Tiny C Compiler) support, particularly in the context of parallel C compilation. The changes address path resolution problems, duplicate symbol detection, and header inclusion guards.

Key Changes

  • Parallel CC working directory handling: Changed TCC compilation to execute from the V root directory, since TCC resolves include and library search paths relative to the invocation directory. This ensures thirdparty/tcc/lib/tcc/... lookups work correctly for standard headers and runtime objects.

  • TCC duplicate symbol detection: Added detection for TCC's specific behavior where duplicate symbol errors are reported via stderr but the linker still exits with code 0. The build now properly fails when defined twice appears in TCC's output.

  • Simplified header inclusion guards: Removed TCC-specific __TINYC__ preprocessor checks from get_guarded_include_text() and get_inttypes_or_stdint_include_text() functions, relying instead on the more portable __has_include feature that TCC supports.

  • Parallel compilation symbol visibility: Modified the VV_LOC macro definition to be empty (instead of static) when _VPARALLELCC is defined, allowing proper symbol visibility across separately compiled object files in parallel compilation mode.

Implementation Details

  • Uses os.getwd() and os.chdir() with defer to safely manage working directory changes during TCC compilation
  • Maintains backward compatibility by only applying TCC-specific behavior when b.ccoptions.cc == .tcc
  • The _VPARALLELCC flag controls whether symbols should be static or globally visible across compilation units

https://claude.ai/code/session_012PDdNjq22fSCxGV3PiTBMT

Three independent issues caused parallel_cc_failure_test.v and
compiler_errors_test.v (missing_shader_header_1.vv) to fail under
`VFLAGS=-cc tcc -no-retry-compilation`:

1. parallel_cc passed `-B${vroot}/thirdparty/tcc` so tcc could find
   libtcc1.a, but `-B${path}` makes tcc look for system headers at
   `${path}/include` (which only ships libtcc.h), so `<stddef.h>` lookups
   failed. Drop the flag and instead chdir to vroot before invoking tcc,
   matching what builder/cc.v already does for thirdparty objects.

2. The non-Windows fallback branch of `VV_LOC` was always `static`, even
   in `-parallel-cc` mode. With tcc that branch is reached on Linux and
   the resulting per-translation-unit static functions could not satisfy
   cross-file references at link time. Mirror the Windows branch and
   make `VV_LOC` empty when `_VPARALLELCC` is defined.

3. `get_guarded_include_text` and `get_inttypes_or_stdint_include_text`
   bypassed `__has_include` for `__TINYC__`, so missing shader headers
   under tcc emitted tcc's terse `'foo.h' not found` instead of the
   `VERROR_MESSAGE` text the checker tests assert on. tcc 0.9.28 supports
   `__has_include` correctly, so use the same path as other compilers.

Also detect tcc's "defined twice" warning (which it prints to stderr but
still exits 0 from when an executable is produced) so that
test_parallel_cc_fails_when_final_linking_fails sees a proper failure.

https://claude.ai/code/session_012PDdNjq22fSCxGV3PiTBMT
@JalonSolov
Copy link
Copy Markdown
Collaborator

I thought we were going to drop tcc once v2 was done. There would no longer be a need for it.

Even bootstrapping a fresh install could be accomplished other ways.

Copy link
Copy Markdown

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

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

ℹ️ 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/cbuilder/parallel_cc.v Outdated
Comment on lines +89 to +92
prev_cwd := os.getwd()
if b.ccoptions.cc == .tcc {
os.chdir(b.pref.vroot) 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.

P1 Badge Avoid changing cwd before invoking TCC commands

Switching the process working directory to b.pref.vroot here breaks builds that rely on relative tool/flag paths in -parallel-cc mode with TCC. parallel_cc_compiler_path() uses b.pref.ccompiler verbatim, and compile/link args also carry user/env flags as provided, so values like -cc ./tcc, CFLAGS=-I./include, or LDFLAGS=-L./lib are now resolved relative to the V root instead of the project directory and can fail to find the compiler, headers, or libraries.

Useful? React with 👍 / 👎.

@medvednikov
Copy link
Copy Markdown
Member Author

This is a V1 fix, not V2. Have to make all tests pass.

The previous chdir-to-vroot approach risked breaking user-supplied
relative paths (e.g. `-cc ./tcc`, `CFLAGS=-I./include`,
`LDFLAGS=-L./lib`), since they would resolve relative to the V root
instead of the project directory.

Pass absolute `-B"${vroot}/thirdparty/tcc/lib/tcc"` for system header
discovery, plus `-L"${vroot}/thirdparty/tcc/lib/tcc"` so the linker
finds libtcc1.a / bt-*.o, and let the cwd remain whatever v was
invoked from. User-supplied relative flags continue to resolve
against the project directory as before.

https://claude.ai/code/session_012PDdNjq22fSCxGV3PiTBMT
@medvednikov medvednikov merged commit dc00f0d into master Apr 30, 2026
1 of 180 checks passed
Copy link
Copy Markdown

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

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

ℹ️ 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/gen/c/cgen.v
Comment on lines +13034 to 13035
|#if defined(__has_include)
|#if __has_include(${iname})
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 Restore TinyCC bypass for guarded include checks

Removing the defined(__TINYC__) fast path makes get_guarded_include_text() rely on __has_include for TinyCC whenever the prelude path does not inject the #undef __has_include guard (for example -no-preludes or -custom-prelude). In those modes, a #include hash stmt now goes through __has_include and can incorrectly hit the generated #error on TCC, while the previous code always emitted a direct include for TinyCC. This is a regression for TCC builds that customize or disable preludes.

Useful? React with 👍 / 👎.

@Jengro777
Copy link
Copy Markdown
Contributor

This is a V1 fix, not V2. Have to make all tests pass.

This will consume a lot of time, and it would be better if v2 could pass all tests as soon as possible if possible.

@JalonSolov
Copy link
Copy Markdown
Collaborator

All the tests would have to be converted over, all the CI jobs would have to be updated, etc. If the goal is to pass all tests with v1, then switch to v2, that's alright.

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.

4 participants