Skip to content

Commit

Permalink
Support dynamically linking against system double-conversion library (#…
Browse files Browse the repository at this point in the history
…508)

Add env vars to build with system double-conversion. Fixes #376 and is useful to Linux distribution packagers.

New environment variables UJSON_BUILD_DC_INCLUDES and UJSON_BUILD_DC_LIBS allow overriding the include path for double-conversion and adding linker flags for an external double-conversion library. They should generally be used together.
  • Loading branch information
musicinmybrain committed Feb 17, 2022
1 parent 7f269a4 commit fbae6a3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
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.
20 changes: 16 additions & 4 deletions setup.py
@@ -1,10 +1,22 @@
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 = [
dir
for dir in environ.get(
"UJSON_BUILD_DC_INCLUDES",
"./deps/double-conversion/double-conversion",
).split(pathsep)
if dir
]
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 +37,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

0 comments on commit fbae6a3

Please sign in to comment.