Skip to content

[libc] Remove unused target conditionals for Apple platforms #119030

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
Dec 9, 2024

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Dec 6, 2024

It seems that LIBC_TARGET_OS_IS_MACOS and LIBC_TARGET_OS_IS_IPHONE were never actually used in the code, so these definitions can be removed.

I came across these because libc++ now depends on llvm-libc to build (for from_chars), and the unguarded use of TargetConditionals.h broke some of our downstream configurations. There are some platforms for which __APPLE__ is defined but that don't provide TargetConditionals.h.

If there is a need to keep defining those, the compiler also provides some uglier macro definitions like __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ that do not require including any header.

It seems that LIBC_TARGET_OS_IS_MACOS and LIBC_TARGET_OS_IS_IPHONE were
never actually used in the code, so these definitions can be removed.

I came across these because libc++ now depends on llvm-libc to build
(for from_chars), and the unguarded use of TargetConditionals.h broke
some of our downstream configurations. There are some platforms for
which __APPLE__ is defined but that don't provide TargetConditionals.h.

If there is a need to keep defining those, the compiler also provides
some uglier macro definitions like __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
that do not require including any header.
@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2024

@llvm/pr-subscribers-libc

Author: Louis Dionne (ldionne)

Changes

It seems that LIBC_TARGET_OS_IS_MACOS and LIBC_TARGET_OS_IS_IPHONE were never actually used in the code, so these definitions can be removed.

I came across these because libc++ now depends on llvm-libc to build (for from_chars), and the unguarded use of TargetConditionals.h broke some of our downstream configurations. There are some platforms for which APPLE is defined but that don't provide TargetConditionals.h.

If there is a need to keep defining those, the compiler also provides some uglier macro definitions like __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ that do not require including any header.


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

1 Files Affected:

  • (modified) libc/src/__support/macros/properties/os.h (-12)
diff --git a/libc/src/__support/macros/properties/os.h b/libc/src/__support/macros/properties/os.h
index 1c8fd5721ce679..807ce1812735c0 100644
--- a/libc/src/__support/macros/properties/os.h
+++ b/libc/src/__support/macros/properties/os.h
@@ -25,18 +25,6 @@
 #define LIBC_TARGET_OS_IS_WINDOWS
 #endif
 
-#if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__))
-// From https://stackoverflow.com/a/49560690
-#include "TargetConditionals.h"
-#if defined(TARGET_OS_OSX)
-#define LIBC_TARGET_OS_IS_MACOS
-#endif
-#if defined(TARGET_OS_IPHONE)
-// This is set for any non-Mac Apple products (IOS, TV, WATCH)
-#define LIBC_TARGET_OS_IS_IPHONE
-#endif
-#endif
-
 #if defined(__Fuchsia__)
 #define LIBC_TARGET_OS_IS_FUCHSIA
 #endif

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.

LGTM, we can look into other solutions if necessary. For now it looks like #ifdef __APPLE__ is good enough for what we're currently doing.

@ldionne
Copy link
Member Author

ldionne commented Dec 6, 2024

What's the policy for merging? I assume this can be merged once CI is green?

@michaelrj-google
Copy link
Contributor

Correct. If this patch was urgent it would be okay to merge before the CI finished, but for normal patches we recommend waiting for the CI.

@ldionne ldionne merged commit b9a2097 into llvm:main Dec 9, 2024
9 checks passed
@ldionne ldionne deleted the review/libc-fix-target-conditionals branch December 9, 2024 14:09
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