Fixed the 32-bit Windows Python wheels by statically linking libgcc.

After some debugging I was able to determine that the Win32 DLL was failing to load libgcc_s_sjlj-1.dll.  If we statically link libgcc instead, there should be no runtime dependency on libgcc.

PiperOrigin-RevId: 448338965
pull/13171/head
Joshua Haberman 3 years ago committed by Copybara-Service
parent 1cf8214e4d
commit 483cea085e
  1. 11
      .github/workflows/python_tests.yml
  2. 4
      python/dist/BUILD.bazel
  3. 10
      python/protobuf.c
  4. 6
      python/py_extension.bzl

@ -55,11 +55,10 @@ jobs:
- { os: macos-12, python-version: "3.10", architecture: x64 }
# Windows uses the full API up until Python 3.10, so each of these
# jobs tests a distinct binary wheel.
# TODO(b/231485326): fix the win32 wheels to load properly.
# - { os: windows-2019, python-version: "3.7", architecture: x86 }
# - { os: windows-2019, python-version: "3.8", architecture: x86 }
# - { os: windows-2019, python-version: "3.9", architecture: x86 }
# - { os: windows-2019, python-version: "3.10", architecture: x86 }
- { os: windows-2019, python-version: "3.7", architecture: x86 }
- { os: windows-2019, python-version: "3.8", architecture: x86 }
- { os: windows-2019, python-version: "3.9", architecture: x86 }
- { os: windows-2019, python-version: "3.10", architecture: x86 }
- { os: windows-2019, python-version: "3.7", architecture: x64 }
- { os: windows-2019, python-version: "3.8", architecture: x64 }
- { os: windows-2019, python-version: "3.9", architecture: x64 }
@ -92,7 +91,7 @@ jobs:
- name: Install Protobuf Wheels
run: pip install -vvv --no-index --find-links wheels protobuf protobuftests
- name: Test that module is importable
run: python -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)'
run: python -v -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)'
if: ${{ !matrix.pure_python }}
- name: Run the unit tests
run: |

@ -165,7 +165,7 @@ py_dist(
binary_wheel = ":binary_wheel",
full_api_cpus = [
# TODO(b/231485326): fix win32 build
# "win32",
"win32",
"win64",
],
# Windows needs version-specific wheels until 3.10.
@ -182,7 +182,7 @@ py_dist(
# details).
limited_api_wheels = {
# TODO(b/231485326): fix win32 build
# "win32": "310",
"win32": "310",
"win64": "310",
"linux-x86_64": "37",
"linux-aarch_64": "37",

@ -131,10 +131,14 @@ PyUpb_WeakMap* PyUpb_WeakMap_New(void) {
void PyUpb_WeakMap_Free(PyUpb_WeakMap* map) { upb_Arena_Free(map->arena); }
// To give better entropy in the table key, we shift away low bits that are
// always zero.
static const int PyUpb_PtrShift = (sizeof(void*) == 4) ? 2 : 3;
uintptr_t PyUpb_WeakMap_GetKey(const void* key) {
uintptr_t n = (uintptr_t)key;
assert((n & 7) == 0);
return n >> 3;
assert((n & ((1 << PyUpb_PtrShift) - 1)) == 0);
return n >> PyUpb_PtrShift;
}
void PyUpb_WeakMap_Add(PyUpb_WeakMap* map, const void* key, PyObject* py_obj) {
@ -170,7 +174,7 @@ bool PyUpb_WeakMap_Next(PyUpb_WeakMap* map, const void** key, PyObject** obj,
uintptr_t u_key;
upb_value val;
if (!upb_inttable_next2(&map->table, &u_key, &val, iter)) return false;
*key = (void*)(u_key << 3);
*key = (void*)(u_key << PyUpb_PtrShift);
*obj = upb_value_getptr(val);
return true;
}

@ -17,7 +17,11 @@ def py_extension(name, srcs, copts, deps = []):
srcs = srcs,
copts = copts + ["-fvisibility=hidden"],
linkopts = selects.with_or({
("//python/dist:osx-x86_64_cpu", "//python/dist:osx-aarch64_cpu"): ["-undefined", "dynamic_lookup"],
(
"//python/dist:osx-x86_64_cpu",
"//python/dist:osx-aarch64_cpu",
): ["-undefined", "dynamic_lookup"],
"//python/dist:win32_cpu": ["-static-libgcc"],
"//conditions:default": [],
}),
linkshared = True,

Loading…
Cancel
Save