Skip to content

[bazel] Port #145358: LIBC_THREAD_MODE #151539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

rupprecht
Copy link
Collaborator

I'm not sure how libc should be configuring this in bazel, but for now it seems like LIBC_THREAD_MODE_PLATFORM restores the default behavior.

Defining this param is required:

ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/c9d34ded3a9d94cc250207948aceadfc/external/llvm-project/libc/BUILD.bazel:5788:14: Compiling libc/src/stdio/generic/vprintf.cpp failed: (Exit 1): clang failed: error executing CppCompile command (from target @@llvm-project//libc:vprintf) /usr/lib/llvm-18/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer ... (remaining 31 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from external/llvm-project/libc/src/stdio/generic/vprintf.cpp:11:
In file included from external/llvm-project/libc/src/__support/File/file.h:19:
external/llvm-project/libc/src/__support/threads/mutex.h:25:2: error: LIBC_THREAD_MODE is undefined
   25 | #error LIBC_THREAD_MODE is undefined
      |  ^

As an alternative to this PR, we could make the libc header default to LIBC_THREAD_MODE_PLATFORM if not provided, instead of an #error

@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Jul 31, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 31, 2025

@llvm/pr-subscribers-libc

Author: Jordan Rupprecht (rupprecht)

Changes

I'm not sure how libc should be configuring this in bazel, but for now it seems like LIBC_THREAD_MODE_PLATFORM restores the default behavior.

Defining this param is required:

ERROR: /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/c9d34ded3a9d94cc250207948aceadfc/external/llvm-project/libc/BUILD.bazel:5788:14: Compiling libc/src/stdio/generic/vprintf.cpp failed: (Exit 1): clang failed: error executing CppCompile command (from target @@<!-- -->llvm-project//libc:vprintf) /usr/lib/llvm-18/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer ... (remaining 31 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from external/llvm-project/libc/src/stdio/generic/vprintf.cpp:11:
In file included from external/llvm-project/libc/src/__support/File/file.h:19:
external/llvm-project/libc/src/__support/threads/mutex.h:25:2: error: LIBC_THREAD_MODE is undefined
   25 | #error LIBC_THREAD_MODE is undefined
      |  ^

As an alternative to this PR, we could make the libc header default to LIBC_THREAD_MODE_PLATFORM if not provided, instead of an #error


Full diff: https://github.com/llvm/llvm-project/pull/151539.diff

1 Files Affected:

  • (modified) utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl (+3)
diff --git a/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl b/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
index 96d7fa86e9ddf..b49e7c3fad954 100644
--- a/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
@@ -46,4 +46,7 @@ LIBC_CONFIGURE_OPTIONS = [
 
     # Documentation in libc/src/__support/libc_assert.h
     # "LIBC_COPT_USE_C_ASSERT",
+
+    # Documentation in libc/docs/configure.rst
+    "LIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM",
 ]

Copy link
Contributor

@saturn691 saturn691 left a comment

Choose a reason for hiding this comment

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

Hmm, it should default to LIBC_THREAD_MODE_PLATFORM...

"threads": {
"LIBC_CONF_THREAD_MODE": {
"value": "LIBC_THREAD_MODE_PLATFORM",
"doc": "The implementation used for Mutex, acceptable values are LIBC_THREAD_MODE_PLATFORM, LIBC_THREAD_MODE_SINGLE, and LIBC_THREAD_MODE_EXTERNAL."
}
},

@rupprecht
Copy link
Collaborator Author

Hmm, it should default to LIBC_THREAD_MODE_PLATFORM...

AFAICT, the bazel config doesn't read those json files. What I'm suggesting is the header file itself could default, i.e. use this:

#if !defined(LIBC_THREAD_MODE)
#define LIBC_THREAD_MODE LIBC_THREAD_MODE_PLATFORM
#endif // LIBC_THREAD_MODE

Instead of

#if !defined(LIBC_THREAD_MODE)
#error LIBC_THREAD_MODE is undefined
#endif // LIBC_THREAD_MODE

I don't have a preference though. Forcing the build system to define the vars is fine w/ me.

@rupprecht rupprecht merged commit d520dae into llvm:main Jul 31, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants