Skip to content

Commit 51a4ab2

Browse files
authored
[bazel] Improve libc build on macOS (#86174)
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
1 parent b861e27 commit 51a4ab2

File tree

1 file changed

+130
-10
lines changed

1 file changed

+130
-10
lines changed

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 130 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ libc_support_library(
9494
libc_support_library(
9595
name = "llvm_libc_types_float128",
9696
hdrs = ["include/llvm-libc-types/float128.h"],
97+
target_compatible_with = select({
98+
"@platforms//os:linux": [],
99+
"//conditions:default": ["@platforms//:incompatible"],
100+
}),
97101
deps = [":llvm_libc_macros_float_macros"],
98102
)
99103

@@ -972,11 +976,17 @@ libc_support_library(
972976
libc_support_library(
973977
name = "__support_osutil_syscall",
974978
hdrs = ["src/__support/OSUtil/syscall.h"],
975-
textual_hdrs = [
976-
"src/__support/OSUtil/linux/syscall.h",
977-
"src/__support/OSUtil/linux/aarch64/syscall.h",
978-
"src/__support/OSUtil/linux/x86_64/syscall.h",
979-
],
979+
textual_hdrs = select({
980+
"@platforms//os:macos": [
981+
"src/__support/OSUtil/darwin/syscall.h",
982+
"src/__support/OSUtil/darwin/arm/syscall.h",
983+
],
984+
"@platforms//os:linux": [
985+
"src/__support/OSUtil/linux/syscall.h",
986+
"src/__support/OSUtil/linux/aarch64/syscall.h",
987+
"src/__support/OSUtil/linux/x86_64/syscall.h",
988+
],
989+
}),
980990
deps = [
981991
":__support_common",
982992
":__support_cpp_bit",
@@ -986,9 +996,10 @@ libc_support_library(
986996
libc_support_library(
987997
name = "__support_osutil_io",
988998
hdrs = ["src/__support/OSUtil/io.h"],
989-
textual_hdrs = [
990-
"src/__support/OSUtil/linux/io.h",
991-
],
999+
textual_hdrs = select({
1000+
"@platforms//os:macos": ["src/__support/OSUtil/darwin/io.h"],
1001+
"@platforms//os:linux": ["src/__support/OSUtil/linux/io.h"],
1002+
}),
9921003
deps = [
9931004
":__support_common",
9941005
":__support_cpp_string_view",
@@ -1001,6 +1012,10 @@ libc_support_library(
10011012
name = "__support_osutil_quick_exit",
10021013
srcs = ["src/__support/OSUtil/linux/quick_exit.cpp"],
10031014
hdrs = ["src/__support/OSUtil/quick_exit.h"],
1015+
target_compatible_with = select({
1016+
"@platforms//os:linux": [],
1017+
"//conditions:default": ["@platforms//:incompatible"],
1018+
}),
10041019
deps = [
10051020
":__support_osutil_syscall",
10061021
],
@@ -1019,6 +1034,10 @@ libc_support_library(
10191034
"src/__support/StringUtil/error_to_string.h",
10201035
"src/__support/StringUtil/signal_to_string.h",
10211036
],
1037+
target_compatible_with = select({
1038+
"@platforms//os:linux": [],
1039+
"//conditions:default": ["@platforms//:incompatible"],
1040+
}),
10221041
deps = [
10231042
":__support_cpp_array",
10241043
":__support_cpp_span",
@@ -1036,6 +1055,10 @@ libc_support_library(
10361055
"src/__support/threads/mutex.h",
10371056
"src/__support/threads/mutex_common.h",
10381057
],
1058+
target_compatible_with = select({
1059+
"@platforms//os:linux": [],
1060+
"//conditions:default": ["@platforms//:incompatible"],
1061+
}),
10391062
textual_hdrs = [
10401063
"src/__support/threads/linux/mutex.h",
10411064
"src/__support/threads/linux/futex_word.h",
@@ -1695,13 +1718,19 @@ libc_math_function(
16951718
)
16961719

16971720
libc_math_function(name = "fabs")
1721+
16981722
libc_math_function(name = "fabsf")
1723+
16991724
libc_math_function(name = "fabsl")
1725+
17001726
libc_math_function(name = "fabsf128")
17011727

17021728
libc_math_function(name = "fdim")
1729+
17031730
libc_math_function(name = "fdimf")
1731+
17041732
libc_math_function(name = "fdiml")
1733+
17051734
libc_math_function(name = "fdimf128")
17061735

17071736
libc_math_function(
@@ -1729,7 +1758,6 @@ libc_math_function(
17291758

17301759
libc_math_function(name = "ceilf128")
17311760

1732-
17331761
libc_math_function(
17341762
name = "floor",
17351763
specializations = [
@@ -1747,11 +1775,15 @@ libc_math_function(
17471775
)
17481776

17491777
libc_math_function(name = "floorl")
1778+
17501779
libc_math_function(name = "floorf128")
17511780

17521781
libc_math_function(name = "ldexp")
1782+
17531783
libc_math_function(name = "ldexpf")
1784+
17541785
libc_math_function(name = "ldexpl")
1786+
17551787
libc_math_function(name = "ldexpf128")
17561788

17571789
libc_math_function(
@@ -1771,6 +1803,7 @@ libc_math_function(
17711803
)
17721804

17731805
libc_math_function(name = "truncl")
1806+
17741807
libc_math_function(name = "truncf128")
17751808

17761809
libc_math_function(
@@ -1790,6 +1823,7 @@ libc_math_function(
17901823
)
17911824

17921825
libc_math_function(name = "roundl")
1826+
17931827
libc_math_function(name = "roundf128")
17941828

17951829
libc_math_function(
@@ -1807,8 +1841,11 @@ libc_math_function(
18071841
)
18081842

18091843
libc_math_function(name = "frexp")
1844+
18101845
libc_math_function(name = "frexpf")
1846+
18111847
libc_math_function(name = "frexpl")
1848+
18121849
libc_math_function(name = "frexpf128")
18131850

18141851
libc_math_function(name = "hypot")
@@ -1821,31 +1858,47 @@ libc_math_function(
18211858
)
18221859

18231860
libc_math_function(name = "logb")
1861+
18241862
libc_math_function(name = "logbf")
1863+
18251864
libc_math_function(name = "logbl")
1865+
18261866
libc_math_function(name = "logbf128")
18271867

18281868
libc_math_function(name = "modf")
1869+
18291870
libc_math_function(name = "modff")
1871+
18301872
libc_math_function(name = "modfl")
1873+
18311874
libc_math_function(name = "modff128")
18321875

18331876
libc_math_function(name = "remquo")
1877+
18341878
libc_math_function(name = "remquof")
1879+
18351880
libc_math_function(name = "remquol")
18361881

18371882
libc_math_function(name = "remainder")
1883+
18381884
libc_math_function(name = "remainderf")
1885+
18391886
libc_math_function(name = "remainderl")
18401887

18411888
libc_math_function(name = "fmin")
1889+
18421890
libc_math_function(name = "fminf")
1891+
18431892
libc_math_function(name = "fminl")
1893+
18441894
libc_math_function(name = "fminf128")
18451895

18461896
libc_math_function(name = "fmax")
1897+
18471898
libc_math_function(name = "fmaxf")
1899+
18481900
libc_math_function(name = "fmaxl")
1901+
18491902
libc_math_function(name = "fmaxf128")
18501903

18511904
libc_math_function(
@@ -1928,38 +1981,64 @@ libc_math_function(
19281981
)
19291982

19301983
libc_math_function(name = "copysign")
1984+
19311985
libc_math_function(name = "copysignf")
1986+
19321987
libc_math_function(name = "copysignl")
1933-
libc_math_function(name = "copysignf128")
1988+
1989+
libc_math_function(
1990+
name = "copysignf128",
1991+
additional_deps = [
1992+
":llvm_libc_types_float128",
1993+
],
1994+
)
19341995

19351996
libc_math_function(name = "ilogb")
1997+
19361998
libc_math_function(name = "ilogbf")
1999+
19372000
libc_math_function(name = "ilogbl")
2001+
19382002
libc_math_function(name = "ilogbf128")
19392003

19402004
libc_math_function(name = "rint")
2005+
19412006
libc_math_function(name = "rintf")
2007+
19422008
libc_math_function(name = "rintl")
2009+
19432010
libc_math_function(name = "rintf128")
19442011

19452012
libc_math_function(name = "lrint")
2013+
19462014
libc_math_function(name = "lrintf")
2015+
19472016
libc_math_function(name = "lrintl")
2017+
19482018
libc_math_function(name = "lrintf128")
19492019

19502020
libc_math_function(name = "llrint")
2021+
19512022
libc_math_function(name = "llrintf")
2023+
19522024
libc_math_function(name = "llrintl")
2025+
19532026
libc_math_function(name = "llrintf128")
19542027

19552028
libc_math_function(name = "lround")
2029+
19562030
libc_math_function(name = "lroundf")
2031+
19572032
libc_math_function(name = "lroundl")
2033+
19582034
libc_math_function(name = "lroundf128")
19592035

19602036
libc_math_function(name = "llround")
2037+
19612038
libc_math_function(name = "llroundf")
2039+
19622040
libc_math_function(name = "llroundl")
2041+
19632042
libc_math_function(name = "llroundf128")
19642043

19652044
libc_math_function(
@@ -1995,20 +2074,29 @@ libc_math_function(
19952074
)
19962075

19972076
libc_math_function(name = "nearbyint")
2077+
19982078
libc_math_function(name = "nearbyintf")
2079+
19992080
libc_math_function(name = "nearbyintl")
20002081

20012082
libc_math_function(name = "nextafter")
2083+
20022084
libc_math_function(name = "nextafterf")
2085+
20032086
libc_math_function(name = "nextafterl")
2087+
20042088
libc_math_function(name = "nextafterf128")
20052089

20062090
libc_math_function(name = "nexttoward")
2091+
20072092
libc_math_function(name = "nexttowardf")
2093+
20082094
libc_math_function(name = "nexttowardl")
20092095

20102096
libc_math_function(name = "scalbn")
2097+
20112098
libc_math_function(name = "scalbnf")
2099+
20122100
libc_math_function(name = "scalbnl")
20132101

20142102
############################## inttypes targets ##############################
@@ -2590,6 +2678,10 @@ libc_function(
25902678
name = "open",
25912679
srcs = ["src/fcntl/linux/open.cpp"],
25922680
hdrs = ["src/fcntl/open.h"],
2681+
target_compatible_with = select({
2682+
"@platforms//os:linux": [],
2683+
"//conditions:default": ["@platforms//:incompatible"],
2684+
}),
25932685
deps = [
25942686
":__support_common",
25952687
":__support_osutil_syscall",
@@ -2601,6 +2693,10 @@ libc_function(
26012693
name = "openat",
26022694
srcs = ["src/fcntl/linux/openat.cpp"],
26032695
hdrs = ["src/fcntl/openat.h"],
2696+
target_compatible_with = select({
2697+
"@platforms//os:linux": [],
2698+
"//conditions:default": ["@platforms//:incompatible"],
2699+
}),
26042700
deps = [
26052701
":__support_common",
26062702
":__support_osutil_syscall",
@@ -2680,6 +2776,10 @@ libc_function(
26802776
name = "dup3",
26812777
srcs = ["src/unistd/linux/dup3.cpp"],
26822778
hdrs = ["src/unistd/dup3.h"],
2779+
target_compatible_with = select({
2780+
"@platforms//os:linux": [],
2781+
"//conditions:default": ["@platforms//:incompatible"],
2782+
}),
26832783
deps = [
26842784
":__support_common",
26852785
":__support_osutil_syscall",
@@ -2849,6 +2949,10 @@ libc_function(
28492949
name = "pread",
28502950
srcs = ["src/unistd/linux/pread.cpp"],
28512951
hdrs = ["src/unistd/pread.h"],
2952+
target_compatible_with = select({
2953+
"@platforms//os:linux": [],
2954+
"//conditions:default": ["@platforms//:incompatible"],
2955+
}),
28522956
deps = [
28532957
":__support_common",
28542958
":__support_osutil_syscall",
@@ -2860,6 +2964,10 @@ libc_function(
28602964
name = "pwrite",
28612965
srcs = ["src/unistd/linux/pwrite.cpp"],
28622966
hdrs = ["src/unistd/pwrite.h"],
2967+
target_compatible_with = select({
2968+
"@platforms//os:linux": [],
2969+
"//conditions:default": ["@platforms//:incompatible"],
2970+
}),
28632971
deps = [
28642972
":__support_common",
28652973
":__support_osutil_syscall",
@@ -3263,6 +3371,10 @@ libc_function(
32633371
name = "rename",
32643372
srcs = ["src/stdio/linux/rename.cpp"],
32653373
hdrs = ["src/stdio/rename.h"],
3374+
target_compatible_with = select({
3375+
"@platforms//os:linux": [],
3376+
"//conditions:default": ["@platforms//:incompatible"],
3377+
}),
32663378
deps = [
32673379
":__support_common",
32683380
":__support_osutil_syscall",
@@ -3301,6 +3413,10 @@ libc_function(
33013413
name = "epoll_wait",
33023414
srcs = ["src/sys/epoll/linux/epoll_wait.cpp"],
33033415
hdrs = ["src/sys/epoll/epoll_wait.h"],
3416+
target_compatible_with = select({
3417+
"@platforms//os:linux": [],
3418+
"//conditions:default": ["@platforms//:incompatible"],
3419+
}),
33043420
weak = True,
33053421
deps = [
33063422
":__support_osutil_syscall",
@@ -3312,6 +3428,10 @@ libc_function(
33123428
name = "epoll_pwait",
33133429
srcs = ["src/sys/epoll/linux/epoll_pwait.cpp"],
33143430
hdrs = ["src/sys/epoll/epoll_pwait.h"],
3431+
target_compatible_with = select({
3432+
"@platforms//os:linux": [],
3433+
"//conditions:default": ["@platforms//:incompatible"],
3434+
}),
33153435
weak = True,
33163436
deps = [
33173437
":__support_osutil_syscall",

0 commit comments

Comments
 (0)