Skip to content

Add //cc/libc config settings for C standard libraries - #792

Open
fmeum wants to merge 5 commits into
bazelbuild:mainfrom
fmeum:libc-settings
Open

Add //cc/libc config settings for C standard libraries#792
fmeum wants to merge 5 commits into
bazelbuild:mainfrom
fmeum:libc-settings

Conversation

@fmeum

@fmeum fmeum commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Adds a new //cc/libc package with config_settings for common C standard libraries, fed by a new libc_flag rule that exposes the current CC toolchain's target_libc value to select(). This mirrors the existing //cc/compiler package for compilers.

Covered libcs: glibc, musl, uclibc, bionic, macosx (Apple's libSystem, using the historical value set by toolchains for all Apple platforms), freebsd, netbsd, openbsd, msvcrt, ucrt, msys, newlib, picolibc, llvm-libc, and wasi-libc. Toolchains not shipped with Bazel are encouraged to use the same canonical names.

Since Bazel documents target_libc as "the libc version string (e.g. glibc-2.2.2)", libc_flag strips a version suffix (everything from the first - followed by a digit) before matching, so versioned values still match their family's setting while names like wasi-libc and llvm-libc are preserved.

The following changes make the new constraints usable:

  • the auto-configured Unix toolchain detects the default libc via preprocessor macros and -dumpmachine
  • the target_libc values emitted by the bundled Windows and BSD toolchain configs are changed to the correct values
  • rule-based cc_toolchains can declare their target_libc or fall back to a reasonable default

@google-cla

google-cla Bot commented Jul 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@fmeum
fmeum force-pushed the libc-settings branch 3 times, most recently from 915bb8b to 82e1195 Compare July 17, 2026 21:49
Adds a libc_flag rule that exposes the current CC toolchain's
target_libc value to select() via config settings for common C standard
libraries in //cc/libc, mirroring //cc/compiler. Version suffixes in the
"glibc-2.2.2" format documented for
cc_common.create_cc_toolchain_config_info are ignored when matching.
Comment thread cc/toolchains/toolchain.bzl Outdated

@keith keith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i really like replacing local with unknown. i kinda think we should do that for other cases too in later PRs

Comment thread tests/libc_settings/BUILD Outdated
@fmeum
fmeum marked this pull request as ready for review July 20, 2026 15:45
@fmeum
fmeum requested review from c-mita, pzembrod and trybka as code owners July 20, 2026 15:45
Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
Comment thread tests/libc_settings/BUILD Outdated
@fmeum
fmeum requested a review from keith July 21, 2026 17:18
Comment thread cc/toolchains/toolchain.bzl Outdated
host_system_name = "local" if is_bsd else "armeabi-v7a"
target_system_name = "local" if is_bsd else "armeabi-v7a"
target_libc = "local" if is_bsd else "armeabi-v7a"
target_libc = cpu if is_bsd else "unknown"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand this--why would the libc be the cpu for bsd?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See line 59/60, cpu is set to the particular OS flavor, which is also the name of the libc. Yes, that also doesn't make much sense, but I didn't want to touch cpu as well :-)

Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
@fmeum
fmeum requested a review from trybka July 22, 2026 08:52
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.

3 participants