Skip to content

Commit fd4ae72

Browse files
add zstd and ncurses packages (#14)
1 parent dfa87aa commit fd4ae72

File tree

8 files changed

+303
-0
lines changed

8 files changed

+303
-0
lines changed

ncurses/build.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
VERSION="6.5"
8+
INSTALL_DIR="$DIR/ncurses/install"
9+
10+
# Idempotent: skip if already built
11+
if [ -f "$INSTALL_DIR/lib/libncurses.a" ]; then
12+
echo "ncurses already present, skipping build."
13+
exit 0
14+
fi
15+
16+
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
17+
18+
# Download
19+
TARBALL="ncurses-${VERSION}.tar.gz"
20+
if [ ! -f "$TARBALL" ]; then
21+
curl -fsSL "https://ftp.gnu.org/gnu/ncurses/${TARBALL}" -o "$TARBALL"
22+
fi
23+
24+
# Extract
25+
if [ ! -d "ncurses-${VERSION}" ]; then
26+
tar xf "$TARBALL"
27+
fi
28+
29+
# Build
30+
PREFIX="$DIR/build/prefix"
31+
mkdir -p "$DIR/build"
32+
33+
cd "ncurses-${VERSION}"
34+
./configure \
35+
--prefix="$PREFIX" \
36+
--without-shared \
37+
--with-normal \
38+
--without-debug \
39+
--without-cxx \
40+
--without-cxx-binding \
41+
--without-ada \
42+
--without-manpages \
43+
--without-progs \
44+
--without-tests \
45+
--without-dlsym \
46+
--enable-overwrite
47+
48+
make -j"$NJOBS"
49+
# Only install libs and headers; skip terminfo database (fails on macOS CI)
50+
make install.libs install.includes
51+
cd "$DIR"
52+
53+
# Copy to package install dir
54+
rm -rf "$INSTALL_DIR"
55+
mkdir -p "$INSTALL_DIR"/{lib,include}
56+
57+
# Libraries (ncurses 6.x builds wide-char by default; provide as libncurses.a)
58+
cp "$PREFIX/lib/libncursesw.a" "$INSTALL_DIR/lib/libncurses.a" 2>/dev/null \
59+
|| cp "$PREFIX/lib/libncurses.a" "$INSTALL_DIR/lib/"
60+
61+
# Headers (--enable-overwrite puts them directly in include/)
62+
cp "$PREFIX/include/ncurses.h" "$INSTALL_DIR/include/"
63+
cp "$PREFIX/include/curses.h" "$INSTALL_DIR/include/"
64+
cp "$PREFIX/include/ncurses_dll.h" "$INSTALL_DIR/include/"
65+
cp "$PREFIX/include/unctrl.h" "$INSTALL_DIR/include/"
66+
cp "$PREFIX/include/term.h" "$INSTALL_DIR/include/"
67+
cp "$PREFIX/include/termcap.h" "$INSTALL_DIR/include/"
68+
69+
# Clean up
70+
rm -rf "ncurses-${VERSION}" "$TARBALL" "$DIR/build"
71+
72+
echo "Installed ncurses to $INSTALL_DIR"
73+
du -sh "$INSTALL_DIR"

ncurses/ncurses/__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, "libncurses.a")), "libncurses.a not found"
10+
assert os.path.isfile(os.path.join(INCLUDE_DIR, "ncurses.h")), "ncurses.h not found"

ncurses/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 = "ncurses"
7+
version = "6.5"
8+
description = "ncurses terminal library (static build)"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["ncurses*"]
13+
14+
[tool.setuptools.package-data]
15+
ncurses = ["install/**/*"]

ncurses/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 BuildNcurses(build_py):
14+
"""Run build.sh to compile ncurses 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, "ncurses", "install", "lib", "libncurses.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": BuildNcurses}
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()

zstd/build.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
VERSION="1.5.6"
8+
INSTALL_DIR="$DIR/zstd/install"
9+
10+
# Idempotent: skip if already built
11+
if [ -f "$INSTALL_DIR/lib/libzstd.a" ]; then
12+
echo "zstd already present, skipping build."
13+
exit 0
14+
fi
15+
16+
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
17+
18+
# Clone
19+
if [ ! -d "zstd-src" ]; then
20+
git clone --depth 1 --branch "v${VERSION}" https://github.com/facebook/zstd.git zstd-src
21+
fi
22+
23+
# Build
24+
PREFIX="$DIR/build/prefix"
25+
mkdir -p "$DIR/build"
26+
27+
cmake -S zstd-src/build/cmake -B "$DIR/build" \
28+
-DCMAKE_BUILD_TYPE=MinSizeRel \
29+
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
30+
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
31+
-DCMAKE_INSTALL_LIBDIR=lib \
32+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
33+
-DZSTD_BUILD_PROGRAMS=OFF \
34+
-DZSTD_BUILD_TESTS=OFF \
35+
-DZSTD_BUILD_CONTRIB=OFF \
36+
-DZSTD_BUILD_SHARED=OFF \
37+
-DZSTD_BUILD_STATIC=ON
38+
39+
cmake --build "$DIR/build" -j"$NJOBS"
40+
cmake --install "$DIR/build"
41+
42+
# Copy to package install dir
43+
rm -rf "$INSTALL_DIR"
44+
mkdir -p "$INSTALL_DIR"/{lib,include}
45+
46+
# Library
47+
cp "$PREFIX/lib/libzstd.a" "$INSTALL_DIR/lib/"
48+
49+
# Headers
50+
cp "$PREFIX/include/zstd.h" "$INSTALL_DIR/include/"
51+
cp "$PREFIX/include/zstd_errors.h" "$INSTALL_DIR/include/"
52+
cp "$PREFIX/include/zdict.h" "$INSTALL_DIR/include/"
53+
54+
# Clean up
55+
rm -rf zstd-src "$DIR/build"
56+
57+
echo "Installed zstd to $INSTALL_DIR"
58+
du -sh "$INSTALL_DIR"

zstd/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 = "zstd"
7+
version = "1.5.6"
8+
description = "Zstandard compression library (static build)"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["zstd*"]
13+
14+
[tool.setuptools.package-data]
15+
zstd = ["install/**/*"]

zstd/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 BuildZstd(build_py):
14+
"""Run build.sh to compile zstd 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, "zstd", "install", "lib", "libzstd.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": BuildZstd}
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()

zstd/zstd/__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, "libzstd.a")), "libzstd.a not found"
10+
assert os.path.isfile(os.path.join(INCLUDE_DIR, "zstd.h")), "zstd.h not found"

0 commit comments

Comments
 (0)