Skip to content

Commit 408cc4b

Browse files
add json11 package (#33)
* add libyuv package * update libyuv to upstream 1922 * add json11 package
1 parent 9e9a5b5 commit 408cc4b

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

json11/build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
VERSION="db00e9369a92aa74bf630a2ffb092a4b0b132c01"
8+
INSTALL_DIR="$DIR/json11/install"
9+
VERSION_FILE="$INSTALL_DIR/VERSION"
10+
11+
# Idempotent: skip if already built at this source revision.
12+
if [ -f "$INSTALL_DIR/lib/libjson11.a" ] && [ -f "$INSTALL_DIR/include/json11/json11.hpp" ] && \
13+
[ -f "$VERSION_FILE" ] && [ "$(cat "$VERSION_FILE")" = "$VERSION" ]; then
14+
echo "json11 already present, skipping build."
15+
exit 0
16+
fi
17+
18+
if [ ! -d "$DIR/json11-src/.git" ]; then
19+
git clone https://github.com/dropbox/json11.git json11-src
20+
fi
21+
22+
git -C json11-src fetch --force origin
23+
git -C json11-src checkout --force "$VERSION"
24+
25+
BUILD_DIR="$DIR/build"
26+
rm -rf "$BUILD_DIR" "$INSTALL_DIR"
27+
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include/json11"
28+
29+
CXX="${CXX:-c++}"
30+
AR="${AR:-ar}"
31+
32+
"$CXX" -std=c++11 -fPIC -O2 -c "$DIR/json11-src/json11.cpp" -o "$BUILD_DIR/json11.o"
33+
"$AR" rcs "$INSTALL_DIR/lib/libjson11.a" "$BUILD_DIR/json11.o"
34+
cp "$DIR/json11-src/json11.hpp" "$INSTALL_DIR/include/json11/json11.hpp"
35+
echo "$VERSION" > "$VERSION_FILE"
36+
37+
# Keep workspace small and deterministic across builds.
38+
rm -rf "$DIR/json11-src" "$BUILD_DIR"
39+
40+
echo "Installed json11 to $INSTALL_DIR"
41+
du -sh "$INSTALL_DIR"

json11/json11/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
DIR = os.path.join(os.path.dirname(__file__), "install")
4+
LIB_DIR = os.path.join(DIR, "lib")
5+
INCLUDE_DIR = os.path.join(DIR, "include")
6+
7+
8+
def smoketest():
9+
assert os.path.isfile(os.path.join(LIB_DIR, "libjson11.a")), "libjson11.a not found"
10+
assert os.path.isfile(os.path.join(INCLUDE_DIR, "json11", "json11.hpp")), "json11/json11.hpp not found"

json11/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "json11"
7+
version = "20170411.0"
8+
description = "json11 JSON parser library (static build)"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["json11*"]
13+
14+
[tool.setuptools.package-data]
15+
json11 = ["install/**/*"]

json11/setup.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from setuptools.command.build_py import build_py
6+
7+
try:
8+
from wheel.bdist_wheel import bdist_wheel
9+
except ImportError:
10+
bdist_wheel = None
11+
12+
13+
class BuildJson11(build_py):
14+
"""Run build.sh to compile json11 before collecting package data."""
15+
16+
def run(self):
17+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
18+
marker = os.path.join(pkg_dir, "json11", "install", "lib", "libjson11.a")
19+
20+
if not os.path.exists(marker):
21+
build_script = os.path.join(pkg_dir, "build.sh")
22+
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
23+
24+
super().run()
25+
26+
27+
cmdclass = {"build_py": BuildJson11}
28+
29+
if bdist_wheel is not None:
30+
31+
class PlatformWheel(bdist_wheel):
32+
"""Produce a platform-specific, Python-version-agnostic wheel."""
33+
34+
def finalize_options(self):
35+
super().finalize_options()
36+
self.root_is_pure = False
37+
38+
def get_tag(self):
39+
system = platform.system()
40+
machine = platform.machine()
41+
42+
if system == "Linux":
43+
plat = f"linux_{machine}"
44+
elif system == "Darwin":
45+
plat = "macosx_11_0_arm64"
46+
else:
47+
plat = f"{system.lower()}_{machine}"
48+
49+
return "py3", "none", plat
50+
51+
cmdclass["bdist_wheel"] = PlatformWheel
52+
53+
54+
def setup():
55+
from setuptools import setup as _setup
56+
57+
_setup(cmdclass=cmdclass)
58+
59+
60+
if __name__ == "__main__":
61+
setup()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"ffmpeg",
88
"gcc-arm-none-eabi",
99
"git-lfs",
10+
"json11",
1011
"libjpeg",
1112
"libyuv",
1213
"ncurses",

0 commit comments

Comments
 (0)