Skip to content

Commit a2515e4

Browse files
committed
(Linux) - new build scripts, amazing improvement. #37
1 parent 26b8d63 commit a2515e4

File tree

2 files changed

+94
-46
lines changed

2 files changed

+94
-46
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ _# Changelog
22

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

5-
## [0.6.0 - 2022-08-xx]
5+
## [0.6.0 - 2022-08-06]
66

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

99
### Added
1010

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

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

2528
## [0.5.1 - 2022-07-30]
2629

libheif/build_libs.py

Lines changed: 89 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
INSTALL_DIR_LIBS = environ.get("INSTALL_DIR_LIBS", "/usr")
1111

1212

13+
PH_LIGHT_VERSION = sys.maxsize <= 2**32 or getenv("PH_LIGHT", "0") != "0"
14+
15+
1316
def download_file(url: str, out_path: str) -> bool:
1417
n_download_clients = 2
1518
for _ in range(2):
@@ -106,14 +109,15 @@ def build_tool_linux(url: str, name: str, min_version: str, configure_args: list
106109

107110

108111
def build_tools_linux(musl: bool = False):
109-
build_tool_linux(
110-
"https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz",
111-
"pkg-config",
112-
"0.29.2" if not musl else "",
113-
configure_args=["--with-internal-glib"],
114-
)
115-
build_tool_linux("https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz", "autoconf", "2.71")
116-
build_tool_linux("https://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz", "automake", "1.16.5")
112+
if machine().find("armv7") != -1:
113+
build_tool_linux(
114+
"https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz",
115+
"pkg-config",
116+
"0.29.1" if not musl else "",
117+
configure_args=["--with-internal-glib"],
118+
)
119+
build_tool_linux("https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz", "autoconf", "2.69")
120+
build_tool_linux("https://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz", "automake", "1.16.1")
117121
build_tool_linux("https://github.com/Kitware/CMake/archive/refs/tags/v3.22.3.tar.gz", "cmake", "3.16.1")
118122
build_tool_linux(
119123
"https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.gz", "nasm", "2.15.05", chmod="774"
@@ -142,9 +146,9 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
142146
_lib_path = path.join(BUILD_DIR_LIBS, name)
143147
if path.isdir(_lib_path):
144148
print(f"Cache found for {name}", flush=True)
145-
chdir(path.join(_lib_path, "build")) if name == "aom" else chdir(_lib_path)
149+
chdir(path.join(_lib_path, "build")) if name != "x265" else chdir(_lib_path)
146150
else:
147-
_hide_build_process = False
151+
_hide_build_process = True
148152
if name == "aom":
149153
_build_path = path.join(_lib_path, "build")
150154
makedirs(_build_path)
@@ -157,16 +161,12 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
157161
else:
158162
download_extract_to(url, _lib_path)
159163
chdir(_lib_path)
160-
if name == "libde265":
161-
run(["./autogen.sh"], check=True)
162164
print(f"Preconfiguring {name}...", flush=True)
163165
if name == "aom":
164166
cmake_args = "-DENABLE_TESTS=0 -DENABLE_TOOLS=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0".split()
165167
cmake_args += "-DENABLE_TESTDATA=0 -DCONFIG_AV1_ENCODER=1 -DCMAKE_BUILD_TYPE=Release".split()
166168
cmake_args += "-DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=1".split()
167169
cmake_args += f"-DCMAKE_INSTALL_PREFIX={INSTALL_DIR_LIBS} ../aom".split()
168-
run(["cmake"] + cmake_args, check=True)
169-
_hide_build_process = True
170170
elif name == "x265":
171171
cmake_high_bits = "-DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF".split()
172172
cmake_high_bits += "-DENABLE_SHARED=OFF -DENABLE_CLI=OFF".split()
@@ -185,16 +185,17 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
185185
cmake_args += ["-G", "Unix Makefiles"]
186186
cmake_args += "-DLINKED_10BIT=ON -DLINKED_12BIT=ON -DEXTRA_LINK_FLAGS=-L.".split()
187187
cmake_args += "-DEXTRA_LIB='x265_main10.a;x265_main12.a'".split()
188-
run(["cmake"] + cmake_args, check=True)
189-
_hide_build_process = True
190188
else:
191-
configure_args = f"--prefix {INSTALL_DIR_LIBS}".split()
192-
if name == "libde265":
193-
configure_args += "--disable-sherlock265 --disable-dec265 --disable-dependency-tracking".split()
194-
elif name == "libheif":
195-
configure_args += "--disable-examples --disable-go".split()
196-
configure_args += "--disable-gdk-pixbuf --disable-visibility".split()
197-
run(["./configure"] + configure_args, check=True)
189+
mkdir("build")
190+
chdir("build")
191+
cmake_args = f"-DCMAKE_INSTALL_PREFIX={INSTALL_DIR_LIBS} ..".split()
192+
cmake_args += ["-DCMAKE_BUILD_TYPE=Release"]
193+
if name == "libheif":
194+
cmake_args += "-DWITH_EXAMPLES=OFF -DWITH_RAV1E=OFF -DWITH_DAV1D=OFF".split()
195+
_hide_build_process = False
196+
if musl:
197+
cmake_args += [f"-DCMAKE_INSTALL_LIBDIR={INSTALL_DIR_LIBS}/lib"]
198+
run(["cmake"] + cmake_args, check=True)
198199
print(f"{name} configured. building...", flush=True)
199200
if _hide_build_process:
200201
run_print_if_error("make -j4".split())
@@ -209,34 +210,78 @@ def build_lib_linux(url: str, name: str, musl: bool = False):
209210

210211

211212
def build_libs_linux() -> str:
212-
_install_flag = path.join(BUILD_DIR_PREFIX, "was_installed.flag")
213-
if path.isfile(_install_flag):
214-
print("Tools & Libraries already installed.", flush=True)
215-
return INSTALL_DIR_LIBS
216213
_is_musllinux = is_musllinux()
214+
if is_library_installed("heif") or is_library_installed("libheif"):
215+
print("libheif is already present.")
216+
return INSTALL_DIR_LIBS
217217
_original_dir = getcwd()
218218
try:
219219
build_tools_linux(_is_musllinux)
220-
if sys.maxsize > 2**32 and getenv("PH_LIGHT") is None:
220+
if not is_library_installed("x265"):
221+
if not PH_LIGHT_VERSION:
222+
build_lib_linux(
223+
"https://bitbucket.org/multicoreware/x265_git/get/master.tar.gz",
224+
"x265",
225+
_is_musllinux,
226+
)
227+
else:
228+
print("x265 already installed.")
229+
if not is_library_installed("aom"):
230+
if not PH_LIGHT_VERSION:
231+
build_lib_linux("https://aomedia.googlesource.com/aom/+archive/v3.4.0.tar.gz", "aom", _is_musllinux)
232+
else:
233+
print("aom already installed.")
234+
if not is_library_installed("libde265") and not is_library_installed("de265"):
235+
if machine().find("armv7") == -1:
236+
build_lib_linux(
237+
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
238+
"libde265",
239+
_is_musllinux,
240+
)
241+
else:
242+
build_lib_linux_armv7(
243+
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
244+
"libde265",
245+
_is_musllinux,
246+
)
247+
else:
248+
print("libde265 already installed.")
249+
if machine().find("armv7") == -1:
221250
build_lib_linux(
222-
"https://bitbucket.org/multicoreware/x265_git/get/master.tar.gz",
223-
"x265",
251+
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
252+
"libheif",
253+
_is_musllinux,
254+
)
255+
else:
256+
build_lib_linux_armv7(
257+
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
258+
"libheif",
224259
_is_musllinux,
225260
)
226-
if not is_library_installed("aom"):
227-
if machine().find("armv7") == -1 and getenv("PH_LIGHT") is None:
228-
build_lib_linux("https://aomedia.googlesource.com/aom/+archive/v3.4.0.tar.gz", "aom", _is_musllinux)
229-
build_lib_linux(
230-
"https://github.com/strukturag/libde265/releases/download/v1.0.8/libde265-1.0.8.tar.gz",
231-
"libde265",
232-
_is_musllinux,
233-
)
234-
build_lib_linux(
235-
"https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz",
236-
"libheif",
237-
_is_musllinux,
238-
)
239-
open(_install_flag, "w").close()
240261
finally:
241262
chdir(_original_dir)
242263
return INSTALL_DIR_LIBS
264+
265+
266+
def build_lib_linux_armv7(url: str, name: str, musl: bool = False):
267+
_lib_path = path.join(BUILD_DIR_LIBS, name)
268+
download_extract_to(url, _lib_path)
269+
chdir(_lib_path)
270+
if name == "libde265":
271+
run(["./autogen.sh"], check=True)
272+
print(f"Preconfiguring {name}...", flush=True)
273+
configure_args = f"--prefix {INSTALL_DIR_LIBS}".split()
274+
if name == "libde265":
275+
configure_args += "--disable-sherlock265 --disable-dec265 --disable-dependency-tracking".split()
276+
elif name == "libheif":
277+
configure_args += "--disable-examples --disable-go".split()
278+
configure_args += "--disable-gdk-pixbuf --disable-visibility".split()
279+
run(["./configure"] + configure_args, check=True)
280+
print(f"{name} configured. building...", flush=True)
281+
run("make -j4".split(), check=True)
282+
print(f"{name} build success.", flush=True)
283+
run("make install".split(), check=True)
284+
if musl:
285+
run(f"ldconfig {INSTALL_DIR_LIBS}/lib".split(), check=True)
286+
else:
287+
run("ldconfig", check=True)

0 commit comments

Comments
 (0)