Skip to content
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

Support dynamically linking against system double-conversion library #508

Merged
merged 6 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Expand Up @@ -124,3 +124,39 @@ Linux 5.0.0-1032-azure x86_64 #34-Ubuntu SMP Mon Feb 10 19:37:25 UTC 2020
| Complex object | | | | | |
| encode | 533 | 582 | | 408 | 431 |
| decode | 466 | 454 | | 154 | 164 |

## Build options

For those with particular needs, such as Linux distribution packagers, several
build options are provided in the form of environment variables.

### Debugging symbols

#### UJSON_BUILD_NO_STRIP

By default, debugging symbols are stripped on Linux platforms. Setting this
environment variable with a value of `1` or `True` disables this behavior.

### Using an external or system copy of the double-conversion library

These two environment variables are typically used together, something like:

```sh
export UJSON_BUILD_DC_INCLUDES='/usr/include/double-conversion'
export UJSON_BUILD_DC_LIBS='-ldouble-conversion'
```

Users planning to link against an external shared library should be aware of
the ABI-compatibility requirements this introduces when upgrading system
libraries or copying compiled wheels to other machines.

#### UJSON_BUILD_DC_INCLUDES

One or more directories, delimited by `os.pathsep` (same as the `PATH`
environment variable), in which to look for `double-conversion` header files;
the default is to use the bundled copy.

#### UJSON_BUILD_DC_LIBS

Compiler flags needed to link the `double-conversion` library; the default
is to use the bundled copy.
16 changes: 12 additions & 4 deletions setup.py
@@ -1,10 +1,18 @@
import platform
import shlex
from glob import glob
from os import environ
from os import environ, pathsep

from setuptools import Extension, setup

dconv_source_files = glob("./deps/double-conversion/double-conversion/*.cc")
dconv_includes = environ.get(
"UJSON_BUILD_DC_INCLUDES",
"./deps/double-conversion/double-conversion",
).split(pathsep)
musicinmybrain marked this conversation as resolved.
Show resolved Hide resolved
dconv_libs = shlex.split(environ.get("UJSON_BUILD_DC_LIBS", ""))
dconv_source_files = []
if not dconv_libs:
dconv_source_files.extend(glob("./deps/double-conversion/double-conversion/*.cc"))
dconv_source_files.append("./lib/dconv_wrapper.cc")

if platform.system() == "Linux" and environ.get("UJSON_BUILD_NO_STRIP", "0") not in (
Expand All @@ -25,9 +33,9 @@
"./lib/ultrajsonenc.c",
"./lib/ultrajsondec.c",
],
include_dirs=["./python", "./lib", "./deps/double-conversion/double-conversion"],
include_dirs=["./python", "./lib"] + dconv_includes,
extra_compile_args=["-D_GNU_SOURCE"],
extra_link_args=["-lstdc++", "-lm"] + strip_flags,
extra_link_args=["-lstdc++", "-lm"] + dconv_libs + strip_flags,
)

with open("python/version_template.h") as f:
Expand Down