Skip to content

Commit 32e3e13

Browse files
committed
Only apply the extra flags if we have confirmed that the compiler is Xcode's clang
1 parent 7d29ef8 commit 32e3e13

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed

src/PackageCompiler.jl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ using p7zip_jll: p7zip_path
1414

1515
export create_sysimage, create_app, create_library
1616

17-
include("juliaconfig.jl")
17+
# Vendored:
1818
include("../ext/TerminalSpinners.jl")
19+
20+
# Source code for this package:
21+
include("juliaconfig.jl")
1922
include("library_selection.jl")
23+
include("xcode.jl")
2024

2125

2226
##############
@@ -712,7 +716,7 @@ function create_sysimg_from_object_file(object_files::Vector{String},
712716
mkpath(dirname(sysimage_path))
713717
# Prevent compiler from stripping all symbols from the shared lib.
714718
if Sys.isapple()
715-
if _xcode_clt_major_version() > 14
719+
if _is_xcode_clt_and_is_gte_xcode_15()
716720
o_file_flags = `-Wl,-all_load $object_files -Wl,-ld_classic`
717721
else
718722
o_file_flags = `-Wl,-all_load $object_files`
@@ -726,24 +730,6 @@ function create_sysimg_from_object_file(object_files::Vector{String},
726730
return nothing
727731
end
728732

729-
function _xcode_clt_major_version()
730-
cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
731-
@debug "_xcode_clt_major_version(): Attempting to run command" cmd
732-
# The `ignorestatus` allows us to proceed (with a warning) if
733-
# the command does not run successfully.
734-
output = strip(read(ignorestatus(cmd), String)) * "\n"
735-
r = r"version: (.*)\n"
736-
m = match(r, output)
737-
if isnothing(m)
738-
@warn "Could not determine the version of the Command Line Tools, assuming greater than 14"
739-
major_version_str = "15"
740-
else
741-
major_version_str = split(m[1], '.')[1]
742-
end
743-
major_version_int = parse(Int, major_version_str)
744-
return major_version_int
745-
end
746-
747733
function get_extra_linker_flags(version, compat_level, soname)
748734
current_ver_arg = ``
749735
compat_ver_arg = ``

src/xcode.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Get the compiler command from `get_compiler_cmd()`, and run `cc --version`, and parse the
2+
# output to determine whether or not the compiler is an Xcode Clang.
3+
function _is_xcode_clt()
4+
cmd = `$(get_compiler_cmd()) --version`
5+
@debug "_active_compiler_is_xcode_clt(): Attempting to run command" cmd
6+
output = "\n" * strip(read(ignorestatus(cmd), String)) * "\n"
7+
is_apple_clang = occursin(r"Apple clang version", output)
8+
installed_dir_m = match(r"\nInstalledDir: ([\w\/]*?)\n", output)
9+
if isnothing(installed_dir_m)
10+
return false
11+
end
12+
installed_dir_str = strip(installed_dir[1])
13+
is_xcode_app = startswith(installed_dir_str, "/Applications/Xcode.app/")
14+
is_xcode_clt = startswith(installed_dir_str, "/Library/Developer/CommandLineTools/")
15+
res = is_apple_clang && (is_xcode_app || is_xcode_clt)
16+
end
17+
18+
# Run `pkgutil` to get the version number of the Xcode CLT (Command Line Tools), and return
19+
# the major version number as an integer.
20+
function _xcode_clt_major_version()
21+
cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
22+
@debug "_xcode_clt_major_version(): Attempting to run command" cmd
23+
# The `ignorestatus` allows us to proceed if the command does
24+
# not run successfully.
25+
output = "\n" * strip(read(ignorestatus(cmd), String)) * "\n"
26+
r = r"version: (.*)\n"
27+
m = match(r, output)
28+
if isnothing(m)
29+
major_version_str = nothing
30+
else
31+
major_version_str = split(m[1], '.')[1]
32+
end
33+
major_version_int = parse(Int, major_version_str)
34+
return major_version_int
35+
end
36+
37+
# Return true iff the Xcode CLT version is >= 15.
38+
# "gte" = greater than or equal to.
39+
function _is_gte_xcode_15()
40+
major_version_int = _xcode_clt_major_version()
41+
isnothing(major_version_int) && return nothing
42+
return major_version_int >= 15
43+
end
44+
45+
# Return true iff the compiler is Xcode Clang AND the Xcode CLT version is >= 15.
46+
#
47+
# If the user sets the JULIA_PACKAGECOMPILER_XCODE_CLT_MAJOR_VERSION environment variable,
48+
# we skip our attempt at auto-detection, and instead use whatever value the user gave us.
49+
function _is_xcode_clt_and_is_gte_xcode_15()
50+
str = strip(get(ENV, "JULIA_PACKAGECOMPILER_XCODE_CLT_MAJOR_VERSION", ""))
51+
ver_int = tryparse(Int, str)
52+
(ver_int isa Int) && return ver_int
53+
if _is_xcode_clt()
54+
b = _is_gte_xcode_15()
55+
if isnothing(b)
56+
@warn "Could not determine the version of the Command Line Tools, assuming less than or equal to 14"
57+
end
58+
return b
59+
else
60+
false
61+
end
62+
end

0 commit comments

Comments
 (0)