add json11 package (#33)
* add libyuv package * update libyuv to upstream 1922 * add json11 package
This commit is contained in:
41
json11/build.sh
Executable file
41
json11/build.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
|
||||
cd "$DIR"
|
||||
|
||||
VERSION="db00e9369a92aa74bf630a2ffb092a4b0b132c01"
|
||||
INSTALL_DIR="$DIR/json11/install"
|
||||
VERSION_FILE="$INSTALL_DIR/VERSION"
|
||||
|
||||
# Idempotent: skip if already built at this source revision.
|
||||
if [ -f "$INSTALL_DIR/lib/libjson11.a" ] && [ -f "$INSTALL_DIR/include/json11/json11.hpp" ] && \
|
||||
[ -f "$VERSION_FILE" ] && [ "$(cat "$VERSION_FILE")" = "$VERSION" ]; then
|
||||
echo "json11 already present, skipping build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d "$DIR/json11-src/.git" ]; then
|
||||
git clone https://github.com/dropbox/json11.git json11-src
|
||||
fi
|
||||
|
||||
git -C json11-src fetch --force origin
|
||||
git -C json11-src checkout --force "$VERSION"
|
||||
|
||||
BUILD_DIR="$DIR/build"
|
||||
rm -rf "$BUILD_DIR" "$INSTALL_DIR"
|
||||
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include/json11"
|
||||
|
||||
CXX="${CXX:-c++}"
|
||||
AR="${AR:-ar}"
|
||||
|
||||
"$CXX" -std=c++11 -fPIC -O2 -c "$DIR/json11-src/json11.cpp" -o "$BUILD_DIR/json11.o"
|
||||
"$AR" rcs "$INSTALL_DIR/lib/libjson11.a" "$BUILD_DIR/json11.o"
|
||||
cp "$DIR/json11-src/json11.hpp" "$INSTALL_DIR/include/json11/json11.hpp"
|
||||
echo "$VERSION" > "$VERSION_FILE"
|
||||
|
||||
# Keep workspace small and deterministic across builds.
|
||||
rm -rf "$DIR/json11-src" "$BUILD_DIR"
|
||||
|
||||
echo "Installed json11 to $INSTALL_DIR"
|
||||
du -sh "$INSTALL_DIR"
|
||||
10
json11/json11/__init__.py
Normal file
10
json11/json11/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
|
||||
DIR = os.path.join(os.path.dirname(__file__), "install")
|
||||
LIB_DIR = os.path.join(DIR, "lib")
|
||||
INCLUDE_DIR = os.path.join(DIR, "include")
|
||||
|
||||
|
||||
def smoketest():
|
||||
assert os.path.isfile(os.path.join(LIB_DIR, "libjson11.a")), "libjson11.a not found"
|
||||
assert os.path.isfile(os.path.join(INCLUDE_DIR, "json11", "json11.hpp")), "json11/json11.hpp not found"
|
||||
15
json11/pyproject.toml
Normal file
15
json11/pyproject.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=64", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "json11"
|
||||
version = "20170411.0"
|
||||
description = "json11 JSON parser library (static build)"
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
include = ["json11*"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
json11 = ["install/**/*"]
|
||||
61
json11/setup.py
Normal file
61
json11/setup.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
from setuptools.command.build_py import build_py
|
||||
|
||||
try:
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
except ImportError:
|
||||
bdist_wheel = None
|
||||
|
||||
|
||||
class BuildJson11(build_py):
|
||||
"""Run build.sh to compile json11 before collecting package data."""
|
||||
|
||||
def run(self):
|
||||
pkg_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
marker = os.path.join(pkg_dir, "json11", "install", "lib", "libjson11.a")
|
||||
|
||||
if not os.path.exists(marker):
|
||||
build_script = os.path.join(pkg_dir, "build.sh")
|
||||
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
|
||||
|
||||
super().run()
|
||||
|
||||
|
||||
cmdclass = {"build_py": BuildJson11}
|
||||
|
||||
if bdist_wheel is not None:
|
||||
|
||||
class PlatformWheel(bdist_wheel):
|
||||
"""Produce a platform-specific, Python-version-agnostic wheel."""
|
||||
|
||||
def finalize_options(self):
|
||||
super().finalize_options()
|
||||
self.root_is_pure = False
|
||||
|
||||
def get_tag(self):
|
||||
system = platform.system()
|
||||
machine = platform.machine()
|
||||
|
||||
if system == "Linux":
|
||||
plat = f"linux_{machine}"
|
||||
elif system == "Darwin":
|
||||
plat = "macosx_11_0_arm64"
|
||||
else:
|
||||
plat = f"{system.lower()}_{machine}"
|
||||
|
||||
return "py3", "none", plat
|
||||
|
||||
cmdclass["bdist_wheel"] = PlatformWheel
|
||||
|
||||
|
||||
def setup():
|
||||
from setuptools import setup as _setup
|
||||
|
||||
_setup(cmdclass=cmdclass)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup()
|
||||
Reference in New Issue
Block a user