Skip to content

Conversation

@michaelrj-google
Copy link
Contributor

A temporary fix based on discussions in #128079

Currently, baremetal targets are failing to build because the scanf
internals require FILE* (either from the system's libc or our libc).
Normally we'd just turn off the broken entrypoint, but since the scanf
internals are built separately that doesn't work. This patch adds extra
conditions to building those internals, which we can hopefully remove
once we have a proper way to build scanf for embedded.

A temporary fix based on discussions in llvm#128079

Currently, baremetal targets are failing to build because the scanf
internals require FILE* (either from the system's libc or our libc).
Normally we'd just turn off the broken entrypoint, but since the scanf
internals are built separately that doesn't work. This patch adds extra
conditions to building those internals, which we can hopefully remove
once we have a proper way to build scanf for embedded.
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

A temporary fix based on discussions in #128079

Currently, baremetal targets are failing to build because the scanf
internals require FILE* (either from the system's libc or our libc).
Normally we'd just turn off the broken entrypoint, but since the scanf
internals are built separately that doesn't work. This patch adds extra
conditions to building those internals, which we can hopefully remove
once we have a proper way to build scanf for embedded.


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

2 Files Affected:

  • (modified) libc/src/stdio/scanf_core/CMakeLists.txt (+6)
  • (modified) libc/test/src/stdio/scanf_core/CMakeLists.txt (+6)
diff --git a/libc/src/stdio/scanf_core/CMakeLists.txt b/libc/src/stdio/scanf_core/CMakeLists.txt
index ce639fe65a106..e8125ff465020 100644
--- a/libc/src/stdio/scanf_core/CMakeLists.txt
+++ b/libc/src/stdio/scanf_core/CMakeLists.txt
@@ -54,6 +54,12 @@ add_header_library(
     libc.src.__support.CPP.string_view
 )
 
+if(NOT(TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
+  # Not all platforms have a file implementation. If file is unvailable, and a
+  # full build is requested, then we must skip all file based scanf sections.
+  return()
+endif()
+
 add_object_library(
   scanf_main
   SRCS
diff --git a/libc/test/src/stdio/scanf_core/CMakeLists.txt b/libc/test/src/stdio/scanf_core/CMakeLists.txt
index 9cdc6547821ee..9d05c7d4b89d1 100644
--- a/libc/test/src/stdio/scanf_core/CMakeLists.txt
+++ b/libc/test/src/stdio/scanf_core/CMakeLists.txt
@@ -18,6 +18,12 @@ add_libc_unittest(
     libc.src.__support.arg_list
 )
 
+if(NOT(TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
+  # Not all platforms have a file implementation. If file is unvailable, and a
+  # full build is requested, then we must skip all file based scanf sections.
+  return()
+endif()
+
 add_libc_unittest(
   reader_test
   SUITE

@michaelrj-google michaelrj-google merged commit 3fad640 into llvm:main Feb 21, 2025
16 of 18 checks passed
@michaelrj-google michaelrj-google deleted the libcScanfTempFix branch February 21, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants