Skip to content

Commit cd729c0

Browse files
linesightclaude
andcommitted
Report CEF API hash and version from CEF's cef_api_hash.h macros
GetVersion() previously reported the API hash from values that cmake_prepare_pyx.py parsed out of CEF's generated cef_api_versions.h and prepended to the module as __cef_api_hash_*__. Read the hash from CEF's CEF_API_HASH_PLATFORM macro directly instead, via the new src/extern/cef/cef_api_hash.pxd, so the compiler supplies the value for whatever API version the module is built against. CEF_API_HASH_UNIVERSAL is deprecated and equal to the platform hash, so both keys report the same value. Also expose the compiled CEF_API_VERSION as cef_api_version in GetVersion(). Remove the now-unused header parsing (get_cef_api_hash / get_host_os_macro) and the --cef-api-versions-header build plumbing from cmake_prepare_pyx.py and CMakeLists.txt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d60ab4c commit cd729c0

4 files changed

Lines changed: 13 additions & 63 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ add_custom_command(
113113
--out "${PYX_STAGE_DIR}"
114114
--pyversion "${PYVERSION}"
115115
--cef-version-header "${_cef_ver_header}"
116-
--cef-api-versions-header "${CEF_ROOT}/include/cef_api_versions.h"
117116
DEPENDS
118117
${_pyx_src_files}
119118
"${CMAKE_SOURCE_DIR}/tools/cmake_prepare_pyx.py"
120-
"${CEF_ROOT}/include/cef_api_versions.h"
121119
COMMENT "Preparing .pyx files -> ${PYX_STAGE_DIR}"
122120
VERBATIM
123121
)

src/cefpython.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ IF UNAME_SYSNAME == "Linux":
227227
cimport x11
228228

229229
from cef_string cimport *
230+
from cef_api_hash cimport *
230231
cdef extern from *:
231232
# noinspection PyUnresolvedReferences
232233
ctypedef CefString ConstCefString "const CefString"
@@ -1071,14 +1072,15 @@ cpdef object GetAppSetting(object key):
10711072
return None
10721073

10731074
cpdef dict GetVersion():
1074-
# These variable are set when building the module.
10751075
# noinspection PyUnresolvedReferences
1076+
api_hash = (<bytes>CEF_API_HASH_PLATFORM).decode("utf-8")
10761077
return dict(
10771078
version=__version__,
10781079
chrome_version=__chrome_version__,
10791080
cef_version=__cef_version__,
1080-
cef_api_hash_platform=__cef_api_hash_platform__,
1081-
cef_api_hash_universal=__cef_api_hash_universal__,
1081+
cef_api_version=CEF_API_VERSION,
1082+
cef_api_hash_platform=api_hash,
1083+
cef_api_hash_universal=api_hash,
10821084
cef_commit_hash=__cef_commit_hash__,
10831085
cef_commit_number=__cef_commit_number__,
10841086
)

src/extern/cef/cef_api_hash.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2026 CEF Python, see the Authors file.
2+
# All rights reserved. Licensed under BSD 3-clause license.
3+
# Project website: https://github.com/cztomczak/cefpython
4+
5+
# CEF's compiled API version and its hash, read by GetVersion().
6+
cdef extern from "include/cef_api_hash.h":
7+
int CEF_API_VERSION
8+
const char* CEF_API_HASH_PLATFORM

tools/cmake_prepare_pyx.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,6 @@
2020
import cef_version
2121

2222

23-
# The build compiles with CEF's default API version, which cef_api_hash.h sets
24-
# to CEF_API_VERSION_EXPERIMENTAL (999999) when CEF_API_VERSION is not defined.
25-
CEF_API_VERSION_EXPERIMENTAL = 999999
26-
27-
28-
def get_host_os_macro():
29-
"""Return the CEF OS_* macro for the build host (builds are always native)."""
30-
if sys.platform.startswith("win"):
31-
return "OS_WIN"
32-
if sys.platform == "darwin":
33-
return "OS_MAC"
34-
return "OS_LINUX"
35-
36-
37-
def get_cef_api_hash(api_versions_header, api_version, os_macro):
38-
"""Extract the CEF API hash for a version+platform from cef_api_versions.h.
39-
40-
That generated header defines the hash per platform, e.g.:
41-
#if defined(OS_WIN)
42-
#define CEF_API_HASH_999999 "..."
43-
#elif defined(OS_MAC)
44-
#define CEF_API_HASH_999999 "..."
45-
#elif defined(OS_LINUX)
46-
#define CEF_API_HASH_999999 "..."
47-
#endif
48-
Each hash define is immediately preceded by its platform guard, so pick the
49-
one whose guard matches the build host. This replaces hand-copying the hash
50-
into src/version/cef_version_*.h (the hash is authoritative here).
51-
"""
52-
define = "CEF_API_HASH_{}".format(api_version)
53-
with open(api_versions_header, "r") as f:
54-
lines = f.read().splitlines()
55-
guard_re = re.compile(r"\s*#(?:if|elif)\s+defined\((OS_\w+)\)")
56-
define_re = re.compile(
57-
r'\s*#define\s+' + re.escape(define) + r'\s+"([0-9a-fA-F]+)"')
58-
for i, line in enumerate(lines):
59-
m = define_re.match(line)
60-
if not m or i == 0:
61-
continue
62-
guard = guard_re.match(lines[i - 1])
63-
if guard and guard.group(1) == os_macro:
64-
return m.group(1)
65-
raise RuntimeError(
66-
"Could not find {define} for {os} in {path}".format(
67-
define=define, os=os_macro, path=api_versions_header))
68-
69-
7023
def except_all_missing(content):
7124
"""Return the line number of a cdef/cpdef returning a C type (built-in,
7225
pointer, template or reference) whose signature declares no exception
@@ -101,9 +54,6 @@ def main():
10154
parser.add_argument("--out", required=True, help="Stage output directory")
10255
parser.add_argument("--pyversion", required=True, help="e.g. 310")
10356
parser.add_argument("--cef-version-header", required=True)
104-
parser.add_argument("--cef-api-versions-header", required=True,
105-
help="Path to CEF's generated cef_api_versions.h "
106-
"(in CEF_ROOT/include); source of the API hash.")
10757
args = parser.parse_args()
10858

10959
src_dir = args.src
@@ -121,18 +71,10 @@ def main():
12171
build=ver["CHROME_VERSION_BUILD"],
12272
patch=ver["CHROME_VERSION_PATCH"],
12373
)
124-
# API hash comes from CEF's generated cef_api_versions.h, not from a value
125-
# hand-copied into cef_version_*.h. CEF_API_HASH_UNIVERSAL is deprecated and
126-
# upstream defines it as the same value as the platform hash.
127-
api_hash = get_cef_api_hash(args.cef_api_versions_header,
128-
CEF_API_VERSION_EXPERIMENTAL,
129-
get_host_os_macro())
13074
module_vars = (
13175
'__version__ = "{v}"\n'.format(v=version_str)
13276
+ '__chrome_version__ = "{v}"\n'.format(v=chrome_ver)
13377
+ '__cef_version__ = "{v}"\n'.format(v=ver["CEF_VERSION"])
134-
+ '__cef_api_hash_platform__ = "{v}"\n'.format(v=api_hash)
135-
+ '__cef_api_hash_universal__ = "{v}"\n'.format(v=api_hash)
13678
+ '__cef_commit_hash__ = "{v}"\n'.format(v=ver["CEF_COMMIT_HASH"])
13779
+ '__cef_commit_number__ = "{v}"\n'.format(v=ver["CEF_COMMIT_NUMBER"])
13880
)

0 commit comments

Comments
 (0)