Skip to content

Commit 741a008

Browse files
committed
build_native: factor out --vendor option
1 parent 62739f9 commit 741a008

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

setupsrc/pypdfium2_setup/build_native.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
abseil = _CR_PREFIX + "chromium/src/third_party/abseil-cpp",
2424
fast_float = _CR_PREFIX + "external/github.com/fastfloat/fast_float",
2525
catapult = _CR_PREFIX + "catapult", # android
26-
icu = _CR_PREFIX + "chromium/deps/icu", # cibuildwheel
26+
icu = _CR_PREFIX + "chromium/deps/icu", # for cibuildwheel
2727
gtest = _CR_PREFIX + "external/github.com/google/googletest",
2828
test_fonts = _CR_PREFIX + "chromium/src/third_party/test_fonts",
2929
)
@@ -156,7 +156,7 @@ def autopatch_dir(dir, globexpr, pattern, repl, is_regex, exp_count=None):
156156
autopatch(file, pattern, repl, is_regex, exp_count)
157157

158158

159-
def get_sources(deps_info, short_ver, with_tests, compiler, clang_path, single_lib, reset):
159+
def get_sources(deps_info, short_ver, with_tests, compiler, clang_path, single_lib, reset, vendor_deps):
160160

161161
assert not IGNORE_FULLVER
162162
full_ver, pdfium_rev, chromium_rev = handle_sbuild_vers(short_ver)
@@ -227,7 +227,7 @@ def get_sources(deps_info, short_ver, with_tests, compiler, clang_path, single_l
227227
_fetch_dep(deps_info, "fast_float", PDFIUM_3RDPARTY/"fast_float"/"src")
228228
if IS_ANDROID:
229229
_fetch_dep(deps_info, "catapult", PDFIUM_3RDPARTY/"catapult")
230-
if IS_CIBUILDWHEEL:
230+
if "icu" in vendor_deps:
231231
_fetch_dep(deps_info, "icu", PDFIUM_3RDPARTY/"icu")
232232
if with_tests:
233233
_fetch_dep(deps_info, "gtest", PDFIUM_3RDPARTY/"googletest"/"src")
@@ -236,13 +236,12 @@ def get_sources(deps_info, short_ver, with_tests, compiler, clang_path, single_l
236236
return full_ver
237237

238238

239-
def prepare(config_dict, build_dir):
239+
def prepare(config_dict, build_dir, vendor_deps):
240240
# Create an empty gclient config
241241
(PDFIUM_DIR/"build"/"config"/"gclient_args.gni").touch(exist_ok=True)
242-
if not IS_CIBUILDWHEEL:
242+
if "icu" not in vendor_deps:
243243
# Unbundle ICU
244244
# alternatively, we could call build/linux/unbundle/replace_gn_files.py --system-libraries icu
245-
# Don't do this with cibuildwheel, the libicu pulled in via auditwheel is quite big.
246245
(PDFIUM_3RDPARTY/"icu").mkdir(exist_ok=True)
247246
shutil.copyfile(
248247
PDFIUM_DIR/"build"/"linux"/"unbundle"/"icu.gn",
@@ -306,7 +305,15 @@ def setup_compiler(config, compiler, clang_path):
306305
assert False, f"Unhandled compiler {compiler}"
307306

308307

309-
def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_path=None, single_lib=False, reset=False):
308+
def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_path=None, single_lib=False, reset=False, vendor_deps=None):
309+
310+
if vendor_deps is None:
311+
vendor_deps = set()
312+
# Vendor ICU in cibuildwheel by default, the libicudata pulled in from the system is quite big. This reduces wheel size by about 10 MB.
313+
if IS_CIBUILDWHEEL:
314+
vendor_deps.add("icu")
315+
316+
print(vendor_deps)
310317

311318
if build_ver is None:
312319
build_ver = SBUILD_NATIVE_PIN
@@ -329,7 +336,7 @@ def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_pat
329336
deps_fields = ["build", "abseil", "fast_float"]
330337
if IS_ANDROID:
331338
deps_fields.append("catapult")
332-
if IS_CIBUILDWHEEL:
339+
if "icu" in vendor_deps:
333340
deps_fields.append("icu")
334341
if with_tests:
335342
deps_fields += ("gtest", "test_fonts")
@@ -338,10 +345,10 @@ def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_pat
338345

339346
mkdir(SOURCES_DIR)
340347
full_ver = get_sources(
341-
deps_info, build_ver, with_tests, compiler, clang_path, single_lib, reset
348+
deps_info, build_ver, with_tests, compiler, clang_path, single_lib, reset, vendor_deps
342349
)
343350
setup_compiler(config, compiler, clang_path)
344-
prepare(config, build_dir)
351+
prepare(config, build_dir, vendor_deps)
345352
build(with_tests, build_dir, n_jobs)
346353
if with_tests:
347354
test(build_dir)
@@ -392,9 +399,18 @@ def parse_args(argv):
392399
action = "store_true",
393400
help = "Whether to create a single DLL that bundles the dependency libraries. Otherwise, separate DLLs will be used. Note, the corresponding patch will only be applied if pdfium is downloaded anew or reset, else the existing state is used.",
394401
)
402+
parser.add_argument(
403+
"--vendor",
404+
dest = "vendor_deps",
405+
nargs = "*",
406+
action = "extend",
407+
help = "Dependencies to vendor. Note, this only supports libraries where there is a specific reason to vendor despite the native build. Currently this means 'icu' only ('libc++' may be added in the future). For an exhaustive vendored build, use build_toolchained.py. Pass --vendor without arguments to drop default vendorings, if any."
408+
)
395409
args = parser.parse_args(argv)
396410
if args.compiler:
397411
args.compiler = Compiler[args.compiler]
412+
if args.vendor_deps:
413+
args.vendor_deps = set(args.vendor_deps)
398414
return args
399415

400416

0 commit comments

Comments
 (0)