Skip to content

Commit 7cc6c67

Browse files
committed
Build libcxx against a newer minimum macOS version
Also fix all the plumbing for `os_version` in our build system
1 parent 79ceb33 commit 7cc6c67

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

BinaryBuilderPlatformExtensions.jl/src/Utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export gcc_platform, gcc_target_triplet
66
Strip out any tags that are not the basic annotations like `libc` and `call_abi`.
77
"""
88
function gcc_platform(p::Platform)
9-
keeps = ("libc", "call_abi", "os_version")
9+
keeps = ("libc", "call_abi")
1010
filtered_tags = Dict{Symbol,String}(Symbol(k) => v for (k, v) in tags(p) if k keeps)
1111
return Platform(arch(p)::String, os(p)::String; filtered_tags...)
1212
end

BinaryBuilderSources.jl/src/JLLSource.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function JLLSource(package::PkgSpec, platform::AbstractPlatform; target = "")
2424
noabspath!(target)
2525
return JLLSource(
2626
package,
27-
platform,
27+
# Make sure our artifact matching happens as if we're a host platform,
28+
# e.g. `os_version` gets interpreted as a lower bound, etc...
29+
HostPlatform(platform),
2830
string(target),
2931
String[],
3032
)

BinaryBuilderToolchains.jl/src/toolchains/CToolchain.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,7 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
266266
target=sysroot_path,
267267
)]
268268
elseif os(platform.target) == "macos"
269-
if macos_version(platform.target) !== nothing
270-
if macos_version(platform.target) > v"11.1"
271-
throw(ArgumentError("We need to upgrade our macOSSDK_jll to support such a new version: $(triplet(platform.target))"))
272-
end
273-
end
274-
libc_jlls = [JLLSource(
269+
macos_sdk_jll = JLLSource(
275270
"macOSSDK_jll",
276271
platform.target;
277272
repo=Pkg.Types.GitRepo(
@@ -280,7 +275,13 @@ function jll_source_selection(vendor::Symbol, platform::CrossPlatform,
280275
),
281276
version=v"11.1",
282277
target=sysroot_path,
283-
)]
278+
)
279+
if macos_version(platform.target) !== nothing
280+
if VersionNumber(macos_version(platform.target)) > macos_sdk_jll.package.version
281+
throw(ArgumentError("We need to upgrade our macOSSDK_jll to support such a new version: $(triplet(platform.target))"))
282+
end
283+
end
284+
libc_jlls = [macos_sdk_jll]
284285
elseif os(platform.target) == "windows"
285286
libc_jlls = [JLLSource(
286287
"Mingw_jll",
@@ -685,7 +686,7 @@ function toolchain_env(toolchain::CToolchain, deployed_prefix::String)
685686

686687
# We can have multiple wrapper prefixes, we always use the longest one
687688
# as that's typically the most specific.
688-
wrapper_prefixes = replace.(toolchain.wrapper_prefixes, ("\${triplet}" => triplet(toolchain.platform.target),))
689+
wrapper_prefixes = replace.(toolchain.wrapper_prefixes, ("\${triplet}" => triplet(gcc_platform(toolchain.platform.target)),))
689690
wrapper_prefix = wrapper_prefixes[argmax(length.(wrapper_prefixes))]
690691
for env_prefix in toolchain.env_prefixes
691692
set_envvars(env_prefix, wrapper_prefix)
@@ -754,7 +755,7 @@ function make_tool_wrappers(toolchain, output_dir, tool, tool_target;
754755
post_func::Function = identity,
755756
toolchain_prefix::String = "\$(dirname \"\${WRAPPER_DIR}\")")
756757
for wrapper_prefix in toolchain.wrapper_prefixes
757-
tool_prefixed = string(replace(wrapper_prefix, "\${triplet}" => triplet(toolchain.platform.target)), tool)
758+
tool_prefixed = string(replace(wrapper_prefix, "\${triplet}" => triplet(gcc_platform(toolchain.platform.target))), tool)
758759
compiler_wrapper(wrapper,
759760
post_func,
760761
joinpath(output_dir, "$(tool_prefixed)"),

bootstrap/LLVM/libcxx.jl

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
include("llvm_common.jl")
2+
using BinaryBuilderPlatformExtensions: macos_kernel_version
3+
4+
platforms = supported_platforms()
5+
platforms = map(platforms) do p
6+
# x86_64-apple-darwin needs to target at least 10.13
7+
if Sys.isapple(p) && arch(p) == "x86_64"
8+
p["os_version"] = string(macos_kernel_version("10.13"))
9+
end
10+
return p
11+
end
212

313
build_tarballs(;
414
src_name = "LLVMLibcxx",
515
src_version = llvm_version,
616
sources = llvm_sources,
717
script = llvm_script_prefix * raw"""
818
# Configure libcxx
9-
CMAKE_FLAGS+=("-DLIBCXX_INCLUDE_BENCHMARKS=OFF")
10-
CMAKE_FLAGS+=("-DLIBCXX_HAS_ATOMIC_LIB=NO")
1119
CMAKE_FLAGS+=("-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind")
1220
21+
# Use lld to dodge annoying symbol resolution issues on mingw
22+
CMAKE_FLAGS+=("-DLLVM_USE_LINKER=lld")
23+
1324
if [[ "${target}" == *musl* ]]; then
1425
CMAKE_FLAGS+=("-DLIBCXX_HAS_MUSL_LIBC=ON")
1526
fi
1627
28+
# Tell HandleCompilerRT.cmake that we're compiling for macOS
29+
if [[ "${target}" == *darwin* ]]; then
30+
ln -s "$($CC -print-sysroot)" "/tmp/MacOSX.sdk"
31+
CMAKE_FLAGS+=( "-DCMAKE_OSX_SYSROOT=/tmp/MacOSX.sdk/" )
32+
33+
# I don't know why this isn't working, some kind of bug?
34+
CMAKE_FLAGS+=( "-DCXX_SUPPORTS_FNO_EXCEPTIONS_FLAG=TRUE" )
35+
fi
36+
1737
# Configure libcxxabi
1838
CMAKE_FLAGS+=( "-DLIBCXX_USE_COMPILER_RT=ON" )
1939
CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_SHARED=ON" )
2040
CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_STATIC=ON" )
2141
CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON" )
2242
CMAKE_FLAGS+=( "-DLIBCXX_INSTALL_MODULES=ON" )
23-
if [[ "${target}" == *mingw* ]]; then
24-
CMAKE_FLAGS+=( "-DLIBCXX_HAS_WIN32_THREAD_API=ON" )
25-
CMAKE_FLAGS+=( "-DLIBCXXABI_HAS_WIN32_THREAD_API=ON" )
26-
CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON" )
27-
CMAKE_FLAGS+=( "-DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF" )
28-
fi
43+
#CMAKE_FLAGS+=("-DLIBCXX_HAS_ATOMIC_LIB=NO")
44+
CMAKE_FLAGS+=( "-DLIBCXX_CXX_ABI=libcxxabi" )
45+
#if [[ "${target}" == *mingw* ]]; then
46+
#CMAKE_FLAGS+=( "-DLIBCXX_HAS_WIN32_THREAD_API=ON" )
47+
#CMAKE_FLAGS+=( "-DLIBCXXABI_HAS_WIN32_THREAD_API=ON" )
48+
#CMAKE_FLAGS+=( "-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON" )
49+
#CMAKE_FLAGS+=( "-DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF" )
50+
#fi
2951
3052
CMAKE_FLAGS+=( "-DLIBCXXABI_USE_COMPILER_RT=ON" )
3153
CMAKE_FLAGS+=( "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" )
@@ -39,20 +61,20 @@ build_tarballs(;
3961
CMAKE_FLAGS+=( "-DLIBUNWIND_ENABLE_STATIC=ON" )
4062
4163
# configure, build, install!
42-
mkcd build
64+
mkcd "${WORKSPACE}/srcdir/build"
4365
${CMAKE} ${WORKSPACE}/srcdir/llvm-project/runtimes "${CMAKE_FLAGS[@]}"
4466
ninja
4567
ninja install
4668
""",
47-
platforms=supported_platforms(),
69+
platforms,
4870
host,
4971
# We need python, and we need to build with clang
5072
host_dependencies = [JLLSource("Python_jll")],
5173
target_dependencies = [
5274
JLLSource(
5375
"Zlib_jll";
5476
repo=Pkg.Types.GitRepo(
55-
rev="bb2/GCC",
77+
rev="main",
5678
source="https://github.com/staticfloat/Zlib_jll.jl",
5779
),
5880
),
@@ -77,7 +99,6 @@ build_tarballs(;
7799
""",
78100
[
79101
LibraryProduct("libc++", :libcxx),
80-
#LibraryProduct("libc++abi", :libcxxabi),
81102
],
82103
get_default_target_spec(build_config);
83104
platform,

bootstrap/LLVM/llvm_common.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,10 @@ CMAKE_FLAGS+=(
247247
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
248248
-DLLVM_ENABLE_LIBEDIT=OFF
249249
-DLLVM_ENABLE_TERMINFO=OFF
250+
-DLLVM_ENABLE_LIBXML2=OFF
250251
-DLLVM_HAVE_LIBXAR=OFF
251252
)
252253
253-
# Turn off XML2
254-
CMAKE_FLAGS+=(-DLLVM_ENABLE_LIBXML2=OFF)
255-
256254
# Manually point to `zlib`, because it doesn't find it automatically properly.
257255
export LDFLAGS="-L ${host_shlibdir}"
258256

0 commit comments

Comments
 (0)