Skip to content

Commit e7c8dac

Browse files
committed
handle the case where Julia is unable to discover the version of libstdc++
1 parent dc55bd5 commit e7c8dac

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
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 libstdcxx 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: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,18 @@ function get_libstdcxx_version_bound()
6464
)
6565
# Get the libstdcxx version that is currently loaded in this Julia process
6666
loaded_libstdcxx_version = Base.BinaryPlatforms.detect_libstdcxx_version()
67-
# Map it through to get a GCC version; if the version is unknown, we simply return
68-
# the highest GCC version we know about, which should be a fairly safe choice.
69-
max_version = get(vers_mapping, loaded_libstdcxx_version.patch, vers_mapping[maximum(keys(vers_mapping))])
70-
cxx_version = ">=3.4,<=$(max_version.major).$(max_version.minor)"
71-
get(ENV, "JULIA_PYTHONCALL_LIBSTDCXX_VERSION_BOUND", cxx_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)
77+
return nothing
78+
end
7279
end
7380

7481
function init_context()
@@ -102,7 +109,11 @@ function init_context()
102109
else
103110
if Sys.islinux()
104111
cxx_version = get_libstdcxx_version_bound()
105-
CondaPkg.add("libstdcxx-ng", version=cxx_version, channel="conda-forge", temp=true, file=joinpath(@__DIR__, "..", "..", "CondaPkg.toml"), resolve=false)
112+
if cxx_version !== nothing
113+
CondaPkg.add("libstdcxx-ng", version=cxx_version, channel="conda-forge", temp=true, file=joinpath(@__DIR__, "..", "..", "CondaPkg.toml"), resolve=false)
114+
end
115+
# if cxx_version is nothing, then we assume that Julia does not link against libstdcxx-ng, and so we do not
116+
# enforce a version bound.
106117
end
107118
# By default, we use Python installed by CondaPkg.
108119
exe_path = Sys.iswindows() ? joinpath(CondaPkg.envdir(), "python.exe") : joinpath(CondaPkg.envdir(), "bin", "python")

0 commit comments

Comments
 (0)