summaryrefslogtreecommitdiff
path: root/app-text/pdfium/pdfium-7802.ebuild
blob: 1abc2710205cbd5a414291aa1f9ce242b823b155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="Google's PDF rendering engine (standalone source build)"
HOMEPAGE="https://pdfium.googlesource.com"

inherit git-r3 ninja-utils

CHROMIUM_VERSION="147.0.${PV}.0"
TEST_FONT="cd96fc55dc243f6c6f4cb63ad117cad6cd48dceb"

EGIT_REPO_URI="https://pdfium.googlesource.com/pdfium.git"
EGIT_BRANCH="chromium/${PV}"
EGIT_COMMIT="2558d5d970fb3bf6c45e8580c20df91fb9c23ddd"

SRC_URI="
	https://raw.githubusercontent.com/chromium/chromium/${CHROMIUM_VERSION}/tools/generate_shim_headers/generate_shim_headers.py
	test? ( https://chromium-fonts.storage.googleapis.com/${TEST_FONT} -> chromium-testfonts-${TEST_FONT}.tar.gz )"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64"
IUSE="test"
RESTRICT="!test? ( test )"

BDEPEND="
	dev-build/gn
	test? (
		dev-cpp/gtest
		dev-cpp/simdutf
	)
"
DEPEND="
	dev-cpp/fast_float
	dev-libs/glib
	dev-libs/icu
	media-libs/freetype
	media-libs/harfbuzz
	media-libs/lcms
	media-libs/libjpeg-turbo
	media-libs/libpng
	media-libs/openjpeg
	virtual/zlib
"
RDEPEND="${DEPEND}"
PATCHES=(
	"${FILESDIR}"/public_headers.patch
	"${FILESDIR}"/shared_library.patch
)

CHROMIUM_REPO="https://chromium.googlesource.com"

src_unpack() {
	# pdfium
	git-r3_src_unpack

	EGIT_BRANCH=""

	# build
	EGIT_REPO_URI="${CHROMIUM_REPO}"/chromium/src/build
	EGIT_CHECKOUT_DIR="${S}"/build
	EGIT_COMMIT=$(awk -F\' '$2 == "build_revision" && NF == 5 {print $4}' "${S}"/DEPS)
	git-r3_src_unpack

	# abseil-cpp
	EGIT_REPO_URI="${CHROMIUM_REPO}"/chromium/src/third_party/abseil-cpp
	EGIT_CHECKOUT_DIR="${S}"/third_party/abseil-cpp
	EGIT_COMMIT=$(awk -F\' '$2 == "abseil_revision" && NF == 5 {print $4}' "${S}"/DEPS)
	git-r3_src_unpack

	if use test; then
		# gtest
		EGIT_REPO_URI="${CHROMIUM_REPO}"/external/github.com/google/googletest
		EGIT_CHECKOUT_DIR="${S}"/third_party/googletest/src
		EGIT_COMMIT=$(awk -F\' '$2 == "gtest_revision" && NF == 5 {print $4}' "${S}"/DEPS)
		git-r3_src_unpack

		# test_fonts
		EGIT_REPO_URI="${CHROMIUM_REPO}"/chromium/src/third_party/test_fonts
		EGIT_CHECKOUT_DIR="${S}"/third_party/test_fonts
		EGIT_COMMIT=$(awk -F\' '$2 == "test_fonts_revision" && NF == 5 {print $4}' "${S}"/DEPS)
		git-r3_src_unpack

		tar xf "${DISTDIR}"/chromium-testfonts-${TEST_FONT}.tar.gz -C "${S}"/third_party/test_fonts || die
	else
		# Remove test dependencies
		sed -i \
			-e '/\/\/third_party\/test_fonts/d' \
			-e '/\/\/third_party\/simdutf/d' \
			"${S}"/testing/BUILD.gn || die
	fi

	# generate_shim_headers
	mkdir -p "${S}"/tools/generate_shim_headers || die
	cp "${DISTDIR}"/generate_shim_headers.py "${S}"/tools/generate_shim_headers || die
}

src_prepare() {
	default

	# Unbundle packages
	local unbundle=(
		icu
		simdutf
	)

	for pkg in "${unbundle[@]}"; do
		mkdir -p third_party/"${pkg}" || die
		ln -sf "${S}/build/linux/unbundle/${pkg}.gn" "${S}/third_party/${pkg}/BUILD.gn" || die
	done

	# Use system fast_float
	mkdir -p third_party/fast_float/src/include/
	ln -sf /usr/include/fast_float third_party/fast_float/src/include/
}

src_configure() {
	echo "build_with_chromium = false" > "${S}"/build/config/gclient_args.gni

	# Define GN build arguments
	local gn_args=(
		"clang_use_chrome_plugins=false"
		"is_clang=false"
		"use_lld=false"
		"is_debug=false"
		"pdf_enable_v8=false"
		"pdf_enable_xfa=false"
		"is_component_build=false"
		"pdf_is_standalone=true"
		"treat_warnings_as_errors=false"
		"use_custom_libcxx=false"
		"use_glib=true"
		"pdf_use_partition_alloc=false"
		"pdf_use_skia=false"
		"use_sysroot=false"
		"use_system_freetype=true"
		"pdf_bundle_freetype=false"
		"use_remoteexec=false"
		"use_system_harfbuzz=true"
		"use_system_lcms2=true"
		"use_system_libjpeg=true"
		"use_system_libopenjpeg2=true"
		"use_system_libpng=true"
		"use_system_zlib=true"
	)
	# Generate build files using GN
	gn gen out/Release --args="${gn_args[*]}" || die
}

src_compile() {
	local -a targets=( pdfium )
	if use test ; then
		targets+=( pdfium_unittests )
	fi

	eninja -C out/Release ${targets[@]} || die
}

src_test() {
	local skip_tests=(
		# May fail with system zlib (produces different results)
		FlateModule.Encode
		# May fail with use_custom_libcxx=false
		RetainPtr.SetContains
	)
	local test_filter="-$(IFS=:; printf '%s' "${skip_tests[*]}")"

	out/Release/pdfium_unittests --gtest_filter="${test_filter}" || die "Tests failed!"
}

src_install() {
	# Manual installation of headers and library
	dolib.so out/Release/libpdfium.so

	insinto /usr/include/pdfium
	doins public/*.h
	insinto /usr/include/pdfium/cpp
	doins public/cpp/*.h

	dodir /usr/$(get_libdir)/pkgconfig
	sed \
		-e "s/@VERSION@/${CHROMIUM_VERSION}/" \
		"${FILESDIR}"/libpdfium.pc.in > "${ED}/usr/$(get_libdir)/pkgconfig/libpdfium.pc" || die
}