Skip to content

libstdcxx version-bounds #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/src/pythoncall.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ into it. If you want to use a pre-existing Conda environment, see the previous s
If `conda`, `mamba` or `micromamba` is not in your `PATH` you will also need to set
`JULIA_CONDAPKG_EXE` to its path.

#### If you installed a newer version of libstdc++
On Linux, Julia comes bundled with its own copy of *libstdc++*. Therefore, when interacting with
CondaPkg, PythonCall injects a dependency to bound the allowed versions of the `libstdcxx-ng`
Conda package. To override this value (e.g. if the user replaced the bundled libstdc++ with something
newer), use:

```julia
[PythonCall]
ENV["JULIA_CONDAPKG_LIBSTDCXX_VERSION_BOUND"] = ">=3.4,<=12"
```

To figure out installed version, run
```bash
strings /path/to/julia/lib/julia/libstdc++.so.6 | grep GLIBCXX
```
Then look at <https://gcc.gnu.org/onlinedocs/gcc-12.1.0/libstdc++/manual/manual/abi.html>
for the GCC version compatible with the GLIBCXX version.

## [Installing Python packages](@id python-deps)

Assuming you haven't [opted out](@ref pythoncall-config), PythonCall uses
Expand Down
43 changes: 26 additions & 17 deletions src/cpython/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ function _atpyexit()
return
end

# By default, ensure libstdc++ in the Conda environment is compatible with
# the one linked in Julia. This is platform/version dependent, so needs to
# occur at runtime.
#
# Allow the user to override the default. This is useful when the version
# of libstdcxx linked in Julia is customized in the local installation of
# Julia.
#
# To figure out cxx_version for a given Julia version, run
# strings /path/to/julia/lib/julia/libstdc++.so.6 | grep GLIBCXX
# then look at
# https://gcc.gnu.org/onlinedocs/gcc-12.1.0/libstdc++/manual/manual/abi.html
# for the highest GCC version compatible with the highest GLIBCXX version.
function get_libstdcxx_version_bound()
if Base.VERSION <= v"1.6.2"
# GLIBCXX_3.4.26
cxx_version = ">=3.4,<9.2"
else
# GLIBCXX_3.4.29
# checked up to v1.8.0
cxx_version = ">=3.4,<11.4"
end
get(ENV, "JULIA_CONDAPKG_LIBSTDCXX_VERSION_BOUND", cxx_version)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an option to PythonCall, please rename the env var to JULIA_PYTHONCALL_....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks.

end

function init_context()

CTX.is_embedded = haskey(ENV, "JULIA_PYTHONCALL_LIBPTR")
Expand Down Expand Up @@ -60,23 +85,7 @@ function init_context()
exe_path::String
else
if Sys.islinux()
# Ensure libstdc++ in the Conda environment is compatible with the one
# linked in Julia. This is platform/version dependent, so needs to occur at
# runtime.
#
# To figure out cxx_version for a given Julia version, run
# strings /path/to/julia/lib/julia/libstdc++.so.6 | grep GLIBCXX
# then look at
# https://gcc.gnu.org/onlinedocs/gcc-12.1.0/libstdc++/manual/manual/abi.html
# for the highest GCC version compatible with the highest GLIBCXX version.
if Base.VERSION <= v"1.6.2"
# GLIBCXX_3.4.26
cxx_version = ">=3.4,<9.2"
else
# GLIBCXX_3.4.29
# checked up to v1.8.0
cxx_version = ">=3.4,<11.4"
end
cxx_version = get_libstdcxx_version_bound()
CondaPkg.add("libstdcxx-ng", version=cxx_version, channel="conda-forge", temp=true, file=joinpath(@__DIR__, "..", "..", "CondaPkg.toml"), resolve=false)
end
# By default, we use Python installed by CondaPkg.
Expand Down
14 changes: 14 additions & 0 deletions test/context.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@testitem "libstdc++ version" begin
cxxversion = PythonCall.get_libstdcxx_version_bound()

if VERSION <= v"1.6.2"
@test cxxversion == ">=3.4,<9.2"
else
@test cxxversion == ">=3.4,<11.4"
end

ENV["JULIA_CONDAPKG_LIBSTDCXX_VERSION_BOUND"] = ">=3.4,<=12"

cxxversion = PythonCall.get_libstdcxx_version_bound()
@test cxxversion == ">3.4,<=12"
end