Skip to content

fix(library): compile .S/.s with the C driver, not C++ - #1886

Merged
zackees merged 1 commit into
mainfrom
agent/1885-lib-asm-dispatch
Nov 4, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/1885-lib-asm-dispatch

Conversation

@zackees

@zackees zackees commented Nov 4, 2026

Copy link
Copy Markdown
Member

What

Library translation units picked their compiler with source.extension() == "c", so every other extension — including preprocessed .S and raw .s assembly — was dispatched to g++ with the C++ flag set. The core/sketch path (CompilerBase::compile) already routes c and s through the C driver, so a library's assembly recipe depended on how that library entered the build.

uses_c_driver() now draws the line once, and both the dispatch (compile_one_source) and the rebuild signature (compile_signature) use it:

extension driver flags
.c .S .s gcc target C flags
.cpp .cc .cxx g++ C++ flags

Case is significant, as it is for GCC (.S is assembled with the preprocessor, .s without; .C is C++). library_info::is_collectable_source only collects c/S/s, so that is the complete set. Every library path — downloaded lib_deps, lib_extra_dirs, project-as-library, framework/local libs — funnels through this module, so there is a single fix site.

Because the signature is derived from the same predicate, an object already built as a C++ invocation is re-signed and recompiled rather than silently reused under the new driver.

Tests

New crates/fbuild-library/src/library/library_dispatch_tests.rs (sibling module — library_compiler_tests.rs was at 848 lines, close to the per-file cap):

  • assembly_tus_compile_with_the_c_driver_and_c_flags — compiles a.c, b.S, c.s, d.cpp through the fake backend and asserts the recorded compiler path and flag set per extension.
  • compile_signature_of_assembly_describes_the_c_driver_invocation — the signature of .S/.s/.c equals the C-driver hash and .cpp/.cc/.cxx the C++-driver hash, so signature and invocation cannot drift apart again.

Behavioural RED before the fix (real test output):

test ...compile_signature_of_assembly_describes_the_c_driver_invocation ... FAILED
  assertion failed: /src/vector.S must be signed as a C-driver invocation
test ...assembly_tus_compile_with_the_c_driver_and_c_flags ... FAILED
  b.S must use the C driver; got [("/fake/g++", ["-std=gnu++17", "-fno-rtti", ... b.S ...]),
                                  ("/fake/g++", ["-std=gnu++17", "-fno-rtti", ... c.s ...])]

GREEN after: soldr cargo test -p fbuild-library --lib → 321 passed; 0 failed; 1 ignored; the 2 new tests pass; soldr cargo fmt --all -- --check rc0; soldr cargo clippy -p fbuild-library --all-targets -- -D warnings clean; ci/check_test_layout.py rc0.

Not in this PR

The same report also found environment lib_archive = false and manifest build.libArchive: false silently ignored by the always-archive library paths. That is a link-input policy change (loose objects vs .a) touching every caller's return shape, so it lands separately rather than riding along here.

Refs #1885

Library TUs picked their driver with `extension() == "c"`, so every other
extension -- including preprocessed `.S` and raw `.s` assembly -- went to
g++ with the C++ flag set. The core/sketch path already routes `c` and `s`
through the C driver, so a library's asm recipe depended on how the library
entered the build.

`uses_c_driver()` now draws the line once, for both the dispatch and the
rebuild signature: `c`, `S` and `s` -> gcc + target C flags; `cpp`, `cc`,
`cxx` -> g++. Case is significant, as it is for GCC (`S` is assembled with
the preprocessor, `s` without, `C` is C++); `library_info` only collects
`c`/`S`/`s`, so that is the complete set.

Because the signature is derived from the same predicate, an already-built
object signed as a C++ invocation is re-signed and recompiled instead of
being silently reused with the new driver.

Tests: new `library_dispatch_tests.rs` (sibling module -- the main test file
was at 848 lines) asserts the compiler path and flag set per extension via
the fake backend, and that `compile_signature` equals the C-driver hash for
`.S`/`.s`/`.c` and the C++-driver hash for `.cpp`/`.cc`/`.cxx`.
Behavioral RED first: `.S` and `.s` dispatched `/fake/g++ -std=gnu++17
-fno-rtti`.

Remaining from the same report (separate change): environment `lib_archive`
and manifest `build.libArchive: false` are still ignored by the
always-archive library paths.

Refs #1885
@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant