Skip to content

Commit

Permalink
continue on refbindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Nov 27, 2023
1 parent 0822682 commit 808de33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ As pypdfium2 requires a C extension and has custom setup code, there are some sp
- It is possible to prepend `prepared!` to install with existing platform files instead of generating on the fly; the value will be used for metadata / file inclusion. This can be helpful when installing in an isolated env where ctypesgen is not available, but it is not desirable to use the reference bindings (e.g. conda).
* `$PYPDFIUM_MODULES=[raw,helpers]` defines the modules to include. Metadata adapts dynamically.
- May be used by packagers to decouple raw bindings and helpers, which can be important if packaging against system pdfium.
- May be used by packagers to decouple raw bindings and helpers, which may be relevant if packaging against system pdfium.
- Would also allow to install only the raw module without helpers, or only helpers with a custom raw module.
* `$PDFIUM_BINDINGS=reference` allows to override ctypesgen and use the reference bindings file `autorelease/bindings.py` instead.
Expand Down
6 changes: 1 addition & 5 deletions setupsrc/pypdfium2_setup/autorelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ def run_local(*args, **kws):


def update_refbindings(version):
# We endeavor to make the reference bindings as universal and robust as possible.
# Thanks to symbol guards, we can define all standalone feature flags.
# We don't currently define flags that depend on external headers, though it should be possible in principle by adding them to $CPATH (or equivalent). Further, if we could get OS headers, this might even allow for cross-compilation with OS flags (e.g. _WIN32).
# Note that Skia is currently a standalone flag because pdfium only provides a typedef void* for a Skia canvas and casts internally
RefBindingsFile.unlink()
build_pdfium_bindings(version, guard_symbols=True, flags=["V8", "XFA", "SKIA"], allow_system_despite_libdirs=True)
build_pdfium_bindings(version, guard_symbols=True, flags=REFBINDINGS_FLAGS, allow_system_despite_libdirs=True)
shutil.copyfile(DataDir_Bindings/BindingsFN, RefBindingsFile)
assert RefBindingsFile.exists()

Expand Down
23 changes: 18 additions & 5 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
ReleaseInfoURL = ReleaseURL.replace("github.com/", "api.github.com/repos/").replace("download/", "tags/")


# We endeavor to make the reference bindings as universal and robust as possible.
# Thanks to symbol guards, we can define all standalone feature flags.
# We don't currently define flags that depend on external headers, though it should be possible in principle by adding them to $CPATH (or equivalent). Further, if we could get OS headers, this might even allow for cross-compilation with OS flags (e.g. _WIN32).
# Note that Skia is currently a standalone flag because pdfium only provides a typedef void* for a Skia canvas and casts internally
REFBINDINGS_FLAGS = ["V8", "XFA", "SKIA"]


# TODO make SysNames/ExtPlats/PlatNames iterable, consider StrEnum or something

class SysNames:
Expand Down Expand Up @@ -421,7 +428,7 @@ def run_ctypesgen(target_dir, headers_dir, flags=[], guard_symbols=False, compil
bindings.write_text(text)


def build_pdfium_bindings(version, headers_dir=None, **kwargs):
def build_pdfium_bindings(version, headers_dir=None, flags=[], **kwargs):
defaults = dict(flags=[], run_lds=["."], guard_symbols=False)
for k, v in defaults.items():
kwargs.setdefault(k, v)
Expand All @@ -431,13 +438,19 @@ def build_pdfium_bindings(version, headers_dir=None, **kwargs):
if not headers_dir:
headers_dir = DataDir_Bindings / "headers"

# TODO move refbindings handling into run_ctypesgen on behalf of sourcebuild?
# quick and dirty patch to allow using the pre-built bindings instead of calling ctypesgen
# TODO move handler into run_ctypesgen on behalf of sourcebuild?
if BindTarget == BindTarget_Ref:
print("Using refbindings as requested by env var. Note that this will bypass all bindings params (e.g. flags). The refbindings try to be as universal as possible, though.", file=sys.stderr)
print("Using reference bindings as requested by env var. This will bypass all bindings params.", file=sys.stderr)
record = read_json(AR_RecordFile)
bindings_ver = record["pdfium"]
if bindings_ver != version:
print(f"Warning: ABI version mismatch (bindings {bindings_ver}, binary target {version}). This is potentially unsafe!", file=sys.stderr)
flags_diff = set(flags).difference(REFBINDINGS_FLAGS)
if flags_diff: # == not set(...).issubset(...)
print(f"Warning: The following requested flags are not available in the reference bindings and will be discarded: {flags_diff}")
shutil.copyfile(RefBindingsFile, DataDir_Bindings/BindingsFN)
ar_record = read_json(AR_RecordFile)
write_json(ver_path, dict(version=ar_record["pdfium"], flags=[], run_lds=["."], source="reference"))
write_json(ver_path, dict(version=bindings_ver, flags=REFBINDINGS_FLAGS, run_lds=["."], source="reference"))
return

curr_info = dict(
Expand Down

0 comments on commit 808de33

Please sign in to comment.