Skip to content
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

[bazel] Improve libc build on macOS #86174

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

keith
Copy link
Member

@keith keith commented Mar 21, 2024

With these changes you can now bazel build @llvm-project//... on macOS, and the targets in libc that don't yet support macOS (or non-linux) are ignored

@keith keith requested a review from gchatelet March 21, 2024 18:45
@keith keith requested a review from rupprecht as a code owner March 21, 2024 18:45
@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Mar 21, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 21, 2024

@llvm/pr-subscribers-libc

Author: Keith Smiley (keith)

Changes

This isn't enough to get everything in libc working, but I started down this path and these were the first required fixes. I might get back to more changes later.


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

1 Files Affected:

  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+31-14)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index c4f6eab0622181..59855dbef7bb05 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -742,12 +742,12 @@ libc_support_library(
     deps = [
         ":__support_common",
         ":__support_cpp_bit",
-        ":__support_sign",
         ":__support_cpp_type_traits",
         ":__support_libc_assert",
         ":__support_macros_attributes",
         ":__support_macros_properties_types",
         ":__support_math_extras",
+        ":__support_sign",
         ":__support_uint128",
     ],
 )
@@ -964,11 +964,17 @@ libc_support_library(
 libc_support_library(
     name = "__support_osutil_syscall",
     hdrs = ["src/__support/OSUtil/syscall.h"],
-    textual_hdrs = [
-        "src/__support/OSUtil/linux/syscall.h",
-        "src/__support/OSUtil/linux/aarch64/syscall.h",
-        "src/__support/OSUtil/linux/x86_64/syscall.h",
-    ],
+    textual_hdrs = select({
+        "@platforms//os:macos": [
+            "src/__support/OSUtil/darwin/syscall.h",
+            "src/__support/OSUtil/darwin/arm/syscall.h",
+        ],
+        "//conditions:default": [
+            "src/__support/OSUtil/linux/syscall.h",
+            "src/__support/OSUtil/linux/aarch64/syscall.h",
+            "src/__support/OSUtil/linux/x86_64/syscall.h",
+        ],
+    }),
     deps = [
         ":__support_common",
         ":__support_cpp_bit",
@@ -978,9 +984,10 @@ libc_support_library(
 libc_support_library(
     name = "__support_osutil_io",
     hdrs = ["src/__support/OSUtil/io.h"],
-    textual_hdrs = [
-        "src/__support/OSUtil/linux/io.h",
-    ],
+    textual_hdrs = select({
+        "@platforms//os:macos": ["src/__support/OSUtil/darwin/io.h"],
+        "//conditions:default": ["src/__support/OSUtil/linux/io.h"],
+    }),
     deps = [
         ":__support_common",
         ":__support_cpp_string_view",
@@ -992,10 +999,15 @@ libc_support_library(
 libc_support_library(
     name = "__support_osutil_quick_exit",
     hdrs = ["src/__support/OSUtil/quick_exit.h"],
-    textual_hdrs = [
-        "src/__support/OSUtil/linux/quick_exit.h",
-        #TODO: add support for GPU quick_exit (isn't just in a header.)
-    ],
+    textual_hdrs = select({
+        "@platforms//os:macos": [
+            "src/__support/OSUtil/darwin/quick_exit.h",
+        ],
+        "//conditions:default": [
+            "src/__support/OSUtil/linux/quick_exit.h",
+            #TODO: add support for GPU quick_exit (isn't just in a header.)
+        ],
+    }),
     deps = [
         ":__support_osutil_syscall",
     ],
@@ -1927,7 +1939,12 @@ libc_math_function(name = "copysignf")
 
 libc_math_function(name = "copysignl")
 
-libc_math_function(name = "copysignf128")
+libc_math_function(
+    name = "copysignf128",
+    additional_deps = [
+        ":llvm_libc_types_float128",
+    ],
+)
 
 libc_math_function(name = "ilogb")
 

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

This patch LGTM, I will warn you that there hasn't been much work on the MacOS build (bazel or cmake) recently so there may be some broken pieces. Feel free to send issues my way, but also we could absolutely use your expertise in bringing it online.

@keith
Copy link
Member Author

keith commented Mar 21, 2024

good to know thanks! I'm not sure how much more I will try to do, originally I just set out to do a bazel build ... and started dealing with the failures, but I'm not sure if we will have a dep on this that will require more fixes, we'll see!

@keith keith force-pushed the ks/bazel-improve-libc-build-on-macos branch from e46f6de to bc0124a Compare March 26, 2024 17:16
@keith
Copy link
Member Author

keith commented Mar 26, 2024

rebased and pushed some more changes so now nothing fails to build on macOS (but many things are just skipped)

Copy link
Contributor

@gchatelet gchatelet left a comment

Choose a reason for hiding this comment

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

LGTM modulo a few comments. I'd need to check that this is compatible with downstream before landing this change.

utils/bazel/llvm-project-overlay/libc/BUILD.bazel Outdated Show resolved Hide resolved
utils/bazel/llvm-project-overlay/libc/BUILD.bazel Outdated Show resolved Hide resolved
This isn't enough to get everything in libc working, but I started down
this path and these were the first required fixes. I might get back to
more changes later.
@keith keith force-pushed the ks/bazel-improve-libc-build-on-macos branch from bc0124a to 0d56e88 Compare April 4, 2024 22:15
@keith keith requested a review from gchatelet April 4, 2024 22:17
Copy link
Contributor

@gchatelet gchatelet left a comment

Choose a reason for hiding this comment

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

Downstream is happy, LGTM

@keith keith merged commit 51a4ab2 into llvm:main Apr 5, 2024
4 checks passed
@keith keith deleted the ks/bazel-improve-libc-build-on-macos branch April 5, 2024 15:37
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.

None yet

6 participants