Skip to content

Commit

Permalink
(Linux) - new build scripts, amazing improvement. #37
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Aug 5, 2022
1 parent 26b8d63 commit a2515e4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 46 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ _# Changelog

All notable changes to this project will be documented in this file.

## [0.6.0 - 2022-08-xx]
## [0.6.0 - 2022-08-06]

This release is fully compatible with previous versions if you was not using `AVIF` decoding.
This release is fully compatible with previous versions if you was not using `AVIF` decoding before.

### Added

Expand All @@ -21,6 +21,9 @@ This release is fully compatible with previous versions if you was not using `AV
### Fixed

- Better compatibility with `pillow_avif` package.
- (Linux) Wheels size decreased significantly(almost in `2x`).
- (Linux) Building from source is a bit simpler, you can build it with your custom libraries from now.
- (Linux) Great speed boost for encoding with new build type(it is as fast now as in Windows builds).

## [0.5.1 - 2022-07-30]

Expand Down
133 changes: 89 additions & 44 deletions libheif/build_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
INSTALL_DIR_LIBS = environ.get("INSTALL_DIR_LIBS", "/usr")


PH_LIGHT_VERSION = sys.maxsize <= 2**32 or getenv("PH_LIGHT", "0") != "0"


def download_file(url: str, out_path: str) -> bool:
n_download_clients = 2
for _ in range(2):
Expand Down Expand Up @@ -106,14 +109,15 @@ def build_tool_linux(url: str, name: str, min_version: str, configure_args: list


def build_tools_linux(musl: bool = False):
build_tool_linux(
"https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz",
"pkg-config",
"0.29.2" if not musl else "",
configure_args=["--with-internal-glib"],
)
build_tool_linux("https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz", "autoconf", "2.71")
build_tool_linux("https://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz", "automake", "1.16.5")
if machine().find("armv7") != -1:
build_tool_linux(
"https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz",
"pkg-config",
"0.29.1" if not musl else "",
configure_args=["--with-internal-glib"],
)
build_tool_linux("https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz", "autoconf", "2.69")
build_tool_linux("https://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz", "automake", "1.16.1")
build_tool_linux("https://github.com/Kitware/CMake/archive/refs/tags/v3.22.3.tar.gz", "cmake", "3.16.1")
build_tool_linux(
"https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz", "nasm", "2.15.05", chmod="774"
Expand Down Expand Up @@ -142,9 +146,9 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
_lib_path = path.join(BUILD_DIR_LIBS, name)
if path.isdir(_lib_path):
print(f"Cache found for {name}", flush=True)
chdir(path.join(_lib_path, "build")) if name == "aom" else chdir(_lib_path)
chdir(path.join(_lib_path, "build")) if name != "x265" else chdir(_lib_path)
else:
_hide_build_process = False
_hide_build_process = True
if name == "aom":
_build_path = path.join(_lib_path, "build")
makedirs(_build_path)
Expand All @@ -157,16 +161,12 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
else:
download_extract_to(url, _lib_path)
chdir(_lib_path)
if name == "libde265":
run(["./autogen.sh"], check=True)
print(f"Preconfiguring {name}...", flush=True)
if name == "aom":
cmake_args = "-DENABLE_TESTS=0 -DENABLE_TOOLS=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0".split()
cmake_args += "-DENABLE_TESTDATA=0 -DCONFIG_AV1_ENCODER=1 -DCMAKE_BUILD_TYPE=Release".split()
cmake_args += "-DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=1".split()
cmake_args += f"-DCMAKE_INSTALL_PREFIX={INSTALL_DIR_LIBS} ../aom".split()
run(["cmake"] + cmake_args, check=True)
_hide_build_process = True
elif name == "x265":
cmake_high_bits = "-DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF".split()
cmake_high_bits += "-DENABLE_SHARED=OFF -DENABLE_CLI=OFF".split()
Expand All @@ -185,16 +185,17 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
cmake_args += ["-G", "Unix Makefiles"]
cmake_args += "-DLINKED_10BIT=ON -DLINKED_12BIT=ON -DEXTRA_LINK_FLAGS=-L.".split()
cmake_args += "-DEXTRA_LIB='x265_main10.a;x265_main12.a'".split()
run(["cmake"] + cmake_args, check=True)
_hide_build_process = True
else:
configure_args = f"--prefix {INSTALL_DIR_LIBS}".split()
if name == "libde265":
configure_args += "--disable-sherlock265 --disable-dec265 --disable-dependency-tracking".split()
elif name == "libheif":
configure_args += "--disable-examples --disable-go".split()
configure_args += "--disable-gdk-pixbuf --disable-visibility".split()
run(["./configure"] + configure_args, check=True)
mkdir("build")
chdir("build")
cmake_args = f"-DCMAKE_INSTALL_PREFIX={INSTALL_DIR_LIBS} ..".split()
cmake_args += ["-DCMAKE_BUILD_TYPE=Release"]
if name == "libheif":
cmake_args += "-DWITH_EXAMPLES=OFF -DWITH_RAV1E=OFF -DWITH_DAV1D=OFF".split()
_hide_build_process = False
if musl:
cmake_args += [f"-DCMAKE_INSTALL_LIBDIR={INSTALL_DIR_LIBS}/lib"]
run(["cmake"] + cmake_args, check=True)
print(f"{name} configured. building...", flush=True)
if _hide_build_process:
run_print_if_error("make -j4".split())
Expand All @@ -209,34 +210,78 @@ def build_lib_linux(url: str, name: str, musl: bool = False):


def build_libs_linux() -> str:
_install_flag = path.join(BUILD_DIR_PREFIX, "was_installed.flag")
if path.isfile(_install_flag):
print("Tools & Libraries already installed.", flush=True)
return INSTALL_DIR_LIBS
_is_musllinux = is_musllinux()
if is_library_installed("heif") or is_library_installed("libheif"):
print("libheif is already present.")
return INSTALL_DIR_LIBS
_original_dir = getcwd()
try:
build_tools_linux(_is_musllinux)
if sys.maxsize > 2**32 and getenv("PH_LIGHT") is None:
if not is_library_installed("x265"):
if not PH_LIGHT_VERSION:
build_lib_linux(
"https://bitbucket.org/multicoreware/x265_git/get/master.tar.gz",
"x265",
_is_musllinux,
)
else:
print("x265 already installed.")
if not is_library_installed("aom"):
if not PH_LIGHT_VERSION:
build_lib_linux("https://aomedia.googlesource.com/aom/+archive/v3.4.0.tar.gz", "aom", _is_musllinux)
else:
print("aom already installed.")
if not is_library_installed("libde265") and not is_library_installed("de265"):
if machine().find("armv7") == -1:
build_lib_linux(
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
"libde265",
_is_musllinux,
)
else:
build_lib_linux_armv7(
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
"libde265",
_is_musllinux,
)
else:
print("libde265 already installed.")
if machine().find("armv7") == -1:
build_lib_linux(
"https://bitbucket.org/multicoreware/x265_git/get/master.tar.gz",
"x265",
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
"libheif",
_is_musllinux,
)
else:
build_lib_linux_armv7(
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
"libheif",
_is_musllinux,
)
if not is_library_installed("aom"):
if machine().find("armv7") == -1 and getenv("PH_LIGHT") is None:
build_lib_linux("https://aomedia.googlesource.com/aom/+archive/v3.4.0.tar.gz", "aom", _is_musllinux)
build_lib_linux(
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
"libde265",
_is_musllinux,
)
build_lib_linux(
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
"libheif",
_is_musllinux,
)
open(_install_flag, "w").close()
finally:
chdir(_original_dir)
return INSTALL_DIR_LIBS


def build_lib_linux_armv7(url: str, name: str, musl: bool = False):
_lib_path = path.join(BUILD_DIR_LIBS, name)
download_extract_to(url, _lib_path)
chdir(_lib_path)
if name == "libde265":
run(["./autogen.sh"], check=True)
print(f"Preconfiguring {name}...", flush=True)
configure_args = f"--prefix {INSTALL_DIR_LIBS}".split()
if name == "libde265":
configure_args += "--disable-sherlock265 --disable-dec265 --disable-dependency-tracking".split()
elif name == "libheif":
configure_args += "--disable-examples --disable-go".split()
configure_args += "--disable-gdk-pixbuf --disable-visibility".split()
run(["./configure"] + configure_args, check=True)
print(f"{name} configured. building...", flush=True)
run("make -j4".split(), check=True)
print(f"{name} build success.", flush=True)
run("make install".split(), check=True)
if musl:
run(f"ldconfig {INSTALL_DIR_LIBS}/lib".split(), check=True)
else:
run("ldconfig", check=True)

0 comments on commit a2515e4

Please sign in to comment.