Skip to content

Commit af1a620

Browse files
committed
Windows: /NODEFAULTLIB:pythonXY_d.lib; Android: hoist pythonStagingRoot
Windows: Py_NO_LINK_LIB is only honored by Python 3.14+'s pyconfig.h — 3.12 and 3.13 don't guard the `pragma comment(lib, "pythonXY_d.lib")` auto-link directive with that macro, so the Debug pragma fired regardless and the link failed with LNK1104. Add `/NODEFAULTLIB:pythonXY_d.lib` at link time to both serious_python_windows_plugin and flet_bridge — works across every supported Python version. Keep the Py_NO_LINK_LIB define too, for 3.14+ cleanliness. Android: gradle errored with "unknown property 'pythonStagingRoot'" because the variable was defined after the `android {}` block but referenced inside it (in the cmake.arguments expression). Hoist the definition above `android {}`.
1 parent dd7b729 commit af1a620

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/serious_python_bridge/android/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ rootProject.allprojects {
2525
apply plugin: 'com.android.library'
2626
apply plugin: 'de.undercouch.download'
2727

28+
// Hoisted before `android { ... }` so the cmake.arguments block below can
29+
// reference it. Mirrors the same expression used later for the extract task.
30+
def pythonStagingRoot = new File(buildDir, 'python-dist')
31+
2832
android {
2933
namespace "com.flet.serious_python_bridge"
3034

@@ -80,8 +84,8 @@ def pythonCacheDir = new File(
8084
// tarball that serious_python_android uses. We extract into a build-time
8185
// scratch dir (not jniLibs/) because we do NOT want to ship libpython
8286
// ourselves — serious_python_android ships it; we just link against it at
83-
// build time.
84-
def pythonStagingRoot = new File(buildDir, 'python-dist')
87+
// build time. (`pythonStagingRoot` is defined above the android{} block so
88+
// it can be passed into the cmake arguments.)
8589

8690
// Single tarball contains all 4 Android ABIs' Python installs WITH headers
8791
// and the libpython3.so abi3 stub. The python-android-dart variant is just

src/serious_python_bridge/native/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ if(WIN32)
5555
# Debug builds, which makes MSVC auto-link the Debug variant of libpython
5656
# even though we explicitly linked python3.lib above. python-build-standalone
5757
# doesn't ship a Debug lib, so the link fails (LNK1104). Py_NO_LINK_LIB
58-
# suppresses that pragma (Python 3.12+).
58+
# suppresses the pragma in Python 3.14+, but 3.12 and 3.13 pyconfig.h don't
59+
# honor it — use /NODEFAULTLIB:pythonXY_d.lib to explicitly exclude the
60+
# Debug lib at link time. Works on every supported version.
5961
target_compile_definitions(flet_bridge PRIVATE Py_NO_LINK_LIB)
62+
if(Python3_VERSION_MAJOR AND Python3_VERSION_MINOR)
63+
target_link_options(flet_bridge PRIVATE
64+
"/NODEFAULTLIB:python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}_d.lib"
65+
)
66+
endif()
6067
endif()

src/serious_python_windows/windows/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,19 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
7676
# python-build-standalone also doesn't ship a Debug variant in the same shape,
7777
# so a single Release Python is the consistent ABI target.
7878
#
79-
# Py_NO_LINK_LIB (set on the plugin target) suppresses pyconfig.h's
80-
# `#pragma comment(lib, "pythonXY_d.lib")` that fires in Debug builds, so the
81-
# explicit link to pythonXY.lib below is honored.
79+
# In Debug Flutter builds, pyconfig.h emits `#pragma comment(lib,
80+
# "pythonXY_d.lib")` to ask MSVC to auto-link the Debug Python lib. That lib
81+
# isn't shipped by python-build-standalone, so the link fails with LNK1104.
82+
# Py_NO_LINK_LIB (Python 3.14+) would suppress that pragma but 3.12 and 3.13
83+
# pyconfig.h doesn't honor it — so use /NODEFAULTLIB to explicitly exclude
84+
# the Debug lib request at link time. Works across all supported versions.
8285
target_link_libraries(${PLUGIN_NAME} PRIVATE
8386
"${PYTHON_PACKAGE}/libs/python${PYTHON_VERSION_NODOT}.lib"
8487
)
8588
target_compile_definitions(${PLUGIN_NAME} PRIVATE Py_NO_LINK_LIB)
89+
target_link_options(${PLUGIN_NAME} PRIVATE
90+
"/NODEFAULTLIB:python${PYTHON_VERSION_NODOT}_d.lib"
91+
)
8692

8793
# List of absolute paths to libraries that should be bundled with the plugin.
8894
# This list could contain prebuilt libraries, or libraries created by an

0 commit comments

Comments
 (0)