Skip to content

Commit 9f3739e

Browse files
author
Christopher Doris
committed
tidy get_libdstdcxx_version_bound
1 parent 5047f00 commit 9f3739e

File tree

2 files changed

+51
-39
lines changed

2 files changed

+51
-39
lines changed

docs/src/pythoncall.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ If `conda`, `mamba` or `micromamba` is not in your `PATH` you will also need to
287287

288288
#### If you installed a newer version of libstdc++
289289
PythonCall injects a dependency to bound the allowed versions of the `libstdcxx-ng`
290-
Conda package. It finds the bound by runtime discovery of the libstdc++ version. To
290+
Conda package. It finds the bound by runtime discovery of the libstdc++ version. To
291291
override this value, use:
292292

293293
```julia

src/cpython/context.jl

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,60 @@ end
3434
# the one linked in Julia. This is platform/version dependent, so needs to
3535
# occur at runtime.
3636
#
37-
# Allow the user to override the default. This is useful when the version
38-
# of libstdcxx linked in Julia is customized in the local installation of
39-
# Julia.
40-
#
41-
# To figure out cxx_version for a given Julia version, run
42-
# strings /path/to/julia/lib/julia/libstdc++.so.6 | grep GLIBCXX
43-
# then look at
44-
# https://gcc.gnu.org/onlinedocs/gcc-12.1.0/libstdc++/manual/manual/abi.html
45-
# for the highest GCC version compatible with the highest GLIBCXX version.
37+
# The following lists the mapping from GLIBCXX versions to GCC versions.
38+
# Start with GCC 4.8, as it's extremely difficult to build Julia with anything older.
39+
# See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.
40+
# See https://gcc.gnu.org/develop.html#timeline.
41+
# 3.4.18 => 4.8.0 - 4.8.2
42+
# 3.4.19 => 4.8.3 - 4.8.5
43+
# 3.4.20 => 4.9.0 - 4.9.4
44+
# 3.4.21 => 5.1.0 - 5.5.0
45+
# 3.4.22 => 6.1.0 - 6.5.0
46+
# 3.4.23 => 7.1.0 - 7.1.0
47+
# 3.4.24 => 7.2.0 - 7.5.0
48+
# 3.4.25 => 8.1.0 - 8.5.0
49+
# 3.4.26 => 9.1.0 - 9.1.0
50+
# 3.4.27 => 9.2.0 - 9.2.0
51+
# 3.4.28 => 9.3.0 - 9.5.0
52+
# 3.4.29 => 11.1.0 - 11.3.0
53+
# 3.4.30 => 12.1.0 - 12.2.0
54+
# 3.4.31 => 13.1.0 - 13.1.0
4655
function get_libstdcxx_version_bound()
47-
# This list comes from: https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html
48-
# Start with GCC 4.8, as it's extremely difficult to build Julia with anything older
49-
vers_mapping = Dict(
50-
18 => v"4.8.0",
51-
19 => v"4.8.3",
52-
20 => v"4.9.0",
53-
21 => v"5.1.0",
54-
22 => v"6.1.0",
55-
23 => v"7.1.0",
56-
24 => v"7.2.0",
57-
25 => v"8.1.0",
58-
26 => v"9.1.0",
59-
27 => v"9.2.0",
60-
28 => v"9.5.0",
61-
29 => v"11.3.0",
62-
30 => v"12.2.0",
63-
31 => v"13.1.0",
64-
)
65-
# Get the libstdcxx version that is currently loaded in this Julia process
56+
bound = get(ENV, "JULIA_PYTHONCALL_LIBSTDCXX_VERSION_BOUND", "")
57+
if bound != ""
58+
return bound
59+
end
6660
loaded_libstdcxx_version = Base.BinaryPlatforms.detect_libstdcxx_version()
67-
68-
if loaded_libstdcxx_version !== nothing
69-
# Map it through to get a GCC version; if the version is unknown, we simply return
70-
# the highest GCC version we know about, which should be a fairly safe choice.
71-
max_version = get(vers_mapping, loaded_libstdcxx_version.patch, vers_mapping[maximum(keys(vers_mapping))])
72-
return get(ENV, "JULIA_PYTHONCALL_LIBSTDCXX_VERSION_BOUND", ">=3.4,<=$(max_version.major).$(max_version.minor)")
73-
elseif haskey(ENV, "JULIA_PYTHONCALL_LIBSTDCXX_VERSION_BOUND")
74-
return ENV["JULIA_PYTHONCALL_LIBSTDCXX_VERSION_BOUND"]
75-
else
76-
# Julia does not link against any version of libstdc++ known to Julia (e.g. using clang instead, or something not in the 3.4.x series)
61+
if loaded_libstdcxx_version === nothing
7762
return nothing
63+
elseif loaded_libstdcxx_version v"3.4.31"
64+
bound = "13.1"
65+
elseif loaded_libstdcxx_version v"3.4.30"
66+
bound = "12.2"
67+
elseif loaded_libstdcxx_version v"3.4.29"
68+
bound = "11.3"
69+
elseif loaded_libstdcxx_version v"3.4.28"
70+
bound = "9.5"
71+
elseif loaded_libstdcxx_version v"3.4.27"
72+
bound = "9.2"
73+
elseif loaded_libstdcxx_version v"3.4.26"
74+
bound = "9.1"
75+
elseif loaded_libstdcxx_version v"3.4.25"
76+
bound = "8.5"
77+
elseif loaded_libstdcxx_version v"3.4.24"
78+
bound = "7.5"
79+
elseif loaded_libstdcxx_version v"3.4.23"
80+
bound = "7.1"
81+
elseif loaded_libstdcxx_version v"3.4.22"
82+
bound = "6.5"
83+
elseif loaded_libstdcxx_version v"3.4.21"
84+
bound = "5.5"
85+
elseif loaded_libstdcxx_version v"3.4.20"
86+
bound = "4.9"
87+
else
88+
bound = "4.8"
7889
end
90+
return ">=3.4,<=$bound"
7991
end
8092

8193
function init_context()

0 commit comments

Comments
 (0)