Skip to content

Conversation

michaelrj-google
Copy link
Contributor

Needed to support sys/resource in bazel

Needed to support sys/resource in bazel
@llvmbot llvmbot added the libc label Oct 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

Needed to support sys/resource in bazel


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

8 Files Affected:

  • (modified) libc/hdr/types/CMakeLists.txt (+11-2)
  • (added) libc/hdr/types/struct_rlimit.h (+22)
  • (modified) libc/src/sys/resource/linux/CMakeLists.txt (+2)
  • (modified) libc/src/sys/resource/linux/getrlimit.cpp (+2-3)
  • (modified) libc/src/sys/resource/linux/setrlimit.cpp (+2-3)
  • (modified) libc/test/src/sys/resource/CMakeLists.txt (-2)
  • (modified) libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp (+5-2)
  • (removed) libc/test/src/sys/resource/testdata/CMakeLists.txt ()
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 21971a4004760..225843924c243 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -1,5 +1,5 @@
 add_proxy_header_library(
-  char8_t 
+  char8_t
   HDRS
     char8_t.h
   DEPENDS
@@ -10,7 +10,7 @@ add_proxy_header_library(
 )
 
 add_proxy_header_library(
-  char32_t 
+  char32_t
   HDRS
     char32_t.h
   DEPENDS
@@ -470,3 +470,12 @@ add_proxy_header_library(
     libc.include.llvm-libc-types.dl_info
     libc.include.dlfcn
 )
+
+add_proxy_header_library(
+  struct_rlimit
+  HDRS
+    struct_rlimit.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_rlimit
+    libc.include.sys_resource
+)
diff --git a/libc/hdr/types/struct_rlimit.h b/libc/hdr/types/struct_rlimit.h
new file mode 100644
index 0000000000000..a09dd53ef76e9
--- /dev/null
+++ b/libc/hdr/types/struct_rlimit.h
@@ -0,0 +1,22 @@
+//===-- Proxy for struct rlimit -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_rlimit.h"
+
+#else // Overlay mode
+
+#include <sys/resource.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
diff --git a/libc/src/sys/resource/linux/CMakeLists.txt b/libc/src/sys/resource/linux/CMakeLists.txt
index 19f3901c98a29..9f0fdad3b0fdf 100644
--- a/libc/src/sys/resource/linux/CMakeLists.txt
+++ b/libc/src/sys/resource/linux/CMakeLists.txt
@@ -5,6 +5,7 @@ add_entrypoint_object(
   HDRS
     ../getrlimit.h
   DEPENDS
+    libc.hdr.types.struct_rlimit
     libc.include.sys_resource
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
@@ -18,6 +19,7 @@ add_entrypoint_object(
   HDRS
     ../setrlimit.h
   DEPENDS
+    libc.hdr.types.struct_rlimit
     libc.include.sys_resource
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp
index d272134194949..a3234ebf4f90b 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -8,13 +8,12 @@
 
 #include "src/sys/resource/getrlimit.h"
 
+#include "hdr/types/struct_rlimit.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h>  // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp
index 300bad75baa63..e2c2b379e7087 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -8,13 +8,12 @@
 
 #include "src/sys/resource/setrlimit.h"
 
+#include "hdr/types/struct_rlimit.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h>  // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/test/src/sys/resource/CMakeLists.txt b/libc/test/src/sys/resource/CMakeLists.txt
index 2870f2ca05b5c..2097a2c501fbd 100644
--- a/libc/test/src/sys/resource/CMakeLists.txt
+++ b/libc/test/src/sys/resource/CMakeLists.txt
@@ -1,7 +1,5 @@
 add_custom_target(libc_sys_resource_unittests)
 
-add_subdirectory(testdata)
-
 add_libc_unittest(
   getrlimit_setrlimit_test
   SUITE
diff --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index d6e1490e3a101..4e0a3c7d10b5f 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -27,8 +27,11 @@ TEST_F(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
   // successfully. Next, close the files and set the file descriptor limit
   // to 4. This will allow us to open one of those file but not the other.
 
-  constexpr const char *TEST_FILE1 = "testdata/resource_limits1.test";
-  constexpr const char *TEST_FILE2 = "testdata/resource_limits2.test";
+  constexpr const char *TEST_FILE1_NAME = "resource_limits1.test";
+  constexpr const char *TEST_FILE2_NAME = "resource_limits2.test";
+
+  auto TEST_FILE1 = libc_make_test_file_path(TEST_FILE1_NAME);
+  auto TEST_FILE2 = libc_make_test_file_path(TEST_FILE2_NAME);
 
   int fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd1, 0);
diff --git a/libc/test/src/sys/resource/testdata/CMakeLists.txt b/libc/test/src/sys/resource/testdata/CMakeLists.txt
deleted file mode 100644
index e69de29bb2d1d..0000000000000

michaelrj-google added a commit to michaelrj-google/llvm-project that referenced this pull request Oct 2, 2025
@michaelrj-google michaelrj-google merged commit f265353 into llvm:main Oct 6, 2025
21 checks passed
@michaelrj-google michaelrj-google deleted the libcCleanupResource branch October 6, 2025 22:42
michaelrj-google added a commit that referenced this pull request Oct 6, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 6, 2025
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