mirror of
https://github.com/ultrajson/ultrajson.git
synced 2024-05-04 15:06:03 +02:00
Support dynamically linking against system double-conversion library (#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.
This commit is contained in:
parent
7f269a4818
commit
fbae6a31ce
36
README.md
36
README.md
|
@ -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 | | | | | |
|
| Complex object | | | | | |
|
||||||
| encode | 533 | 582 | | 408 | 431 |
|
| encode | 533 | 582 | | 408 | 431 |
|
||||||
| decode | 466 | 454 | | 154 | 164 |
|
| 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
setup.py
20
setup.py
|
@ -1,10 +1,22 @@
|
||||||
import platform
|
import platform
|
||||||
|
import shlex
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import environ
|
from os import environ, pathsep
|
||||||
|
|
||||||
from setuptools import Extension, setup
|
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")
|
dconv_source_files.append("./lib/dconv_wrapper.cc")
|
||||||
|
|
||||||
if platform.system() == "Linux" and environ.get("UJSON_BUILD_NO_STRIP", "0") not in (
|
if platform.system() == "Linux" and environ.get("UJSON_BUILD_NO_STRIP", "0") not in (
|
||||||
|
@ -25,9 +37,9 @@ module1 = Extension(
|
||||||
"./lib/ultrajsonenc.c",
|
"./lib/ultrajsonenc.c",
|
||||||
"./lib/ultrajsondec.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_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:
|
with open("python/version_template.h") as f:
|
||||||
|
|
Loading…
Reference in New Issue