Skip to content

Commit 981baac

Browse files
committed
build_native: factor out --vendor option
1 parent 62739f9 commit 981baac

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

setupsrc/pypdfium2_setup/build_native.py

Lines changed: 24 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,13 @@ 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")
310315

311316
if build_ver is None:
312317
build_ver = SBUILD_NATIVE_PIN
@@ -329,7 +334,7 @@ def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_pat
329334
deps_fields = ["build", "abseil", "fast_float"]
330335
if IS_ANDROID:
331336
deps_fields.append("catapult")
332-
if IS_CIBUILDWHEEL:
337+
if "icu" in vendor_deps:
333338
deps_fields.append("icu")
334339
if with_tests:
335340
deps_fields += ("gtest", "test_fonts")
@@ -338,10 +343,10 @@ def main(build_ver=None, with_tests=False, n_jobs=None, compiler=None, clang_pat
338343

339344
mkdir(SOURCES_DIR)
340345
full_ver = get_sources(
341-
deps_info, build_ver, with_tests, compiler, clang_path, single_lib, reset
346+
deps_info, build_ver, with_tests, compiler, clang_path, single_lib, reset, vendor_deps
342347
)
343348
setup_compiler(config, compiler, clang_path)
344-
prepare(config, build_dir)
349+
prepare(config, build_dir, vendor_deps)
345350
build(with_tests, build_dir, n_jobs)
346351
if with_tests:
347352
test(build_dir)
@@ -392,9 +397,18 @@ def parse_args(argv):
392397
action = "store_true",
393398
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.",
394399
)
400+
parser.add_argument(
401+
"--vendor",
402+
dest = "vendor_deps",
403+
nargs = "*",
404+
action = "extend",
405+
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."
406+
)
395407
args = parser.parse_args(argv)
396408
if args.compiler:
397409
args.compiler = Compiler[args.compiler]
410+
if args.vendor_deps:
411+
args.vendor_deps = set(args.vendor_deps)
398412
return args
399413

400414

0 commit comments

Comments
 (0)