Skip to contentSkip to conversation

package/python3: fix build in static-only configurations

PATCH In review Shubham Chakraborty 2 participants 4 messages Apr 3 – Apr 20 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/python3: fix build in static-only configurations

When BR2_STATIC_LIBS=y is enabled, python3 does not produce shared libraries (.so files). The target installation hook PYTHON3_ENSURE_LIBPYTHON_STRIPPED fails because it tries to chmod non-existent .so files.

Wrap the chmod command in a conditional check to ensure it only runs if the shared libraries are actually present.

---
 package/python3/python3.mk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
package/python3/python3.mk +3 -1
index 07cba7c02d..2514dea5b0 100644
@@ -229,7 +229,9 @@ PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
 # Make sure libpython gets stripped out on target
 #
 define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
-	chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
+	if [ -e $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so ]; then \
+		chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so; \
+	fi
 endef
 
 PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
Signature · 6 lines
2.53.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Hi Shubham,

Quoted 4 lines · Shubham Chakraborty

When BR2_STATIC_LIBS=y is enabled, python3 does not produce shared libraries (.so files). The target installation hook PYTHON3_ENSURE_LIBPYTHON_STRIPPED fails because it tries to chmod non-existent .so files.

The target python3 package actually requres dynamic libraries to be enabled since: https://gitlab.com/buildroot.org/buildroot/-/commit/54915af7c75851318385affd037c7718e10f2665

It's not clear from that commit what was broken, but apparently the build was broken for static only configurations.

If this is no longer the case, or if this was the only problem, these changes also need to be undone.

Ideally we'd also add a runtime test for a static-only python build.

Quoted 6 lines

Wrap the chmod command in a conditional check to ensure it only runs if the shared libraries are actually present.

---

[...]

Best,
Marcus
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

A message that is not in the archive (sent off-list or not yet received): CABvxksxUY9ZC=PPSXdrjs8Vq5p12YJxWLHKWWJJZF-X=UvaheQ@mail.gmail.com

#3 lore raw

Hi Shubham,

please keep the list in CC in your replies.

Quoted 6 lines · Shubham Chakraborty

Hi Marcus,

I investigated the original reason for disabling static Python 3 support (commit 54915af7). At the time, the issue was that the interpreter attempted to load standard library modules dynamically, which fails in static-only configurations.

From my testing, this limitation can be partially addressed.

Quoted 7 lines

I was able to build and run a statically linked Python interpreter using |--disable-shared| and |--with-static-libpython|. By configuring | Modules/Setup.local|, several standard library extension modules (e.g. | math|, |_json|, |_struct|, hashing modules) can be built-in, avoiding the need for dynamic loading with musl libc.

I validated this on AArch64 using QEMU. The interpreter starts correctly, and built-in modules work as expected. Basic operations and selected imports succeed in this configuration.

However, this setup is not yet fully equivalent to a standard Python environment. Some parts of the standard library and general script execution still require further validation, and third-party C extensions are not automatically supported (they would require manual inclusion in |Setup.local|).

Based on this, it appears that partial support for static-only Python 3 may be feasible, but additional work is needed to determine whether it is robust enough to re-enable in Buildroot.

I think the question here is: would anyone want this? Do you have a usecase for this?

Quoted 2 lines

If this direction is of interest, I can continue investigating and prepare a patch series that:

I'm confused now. You tried to fix a static-only python3 build failure, which is not something that buildroot currently supports/allows. How did you even encounter that? What is your reason to work on that?

Quoted 10 lines

* Re-enables python3 with |BR2_STATIC_LIBS=y| (if deemed acceptable)
* Adjusts module configuration to minimize reliance on dynamic loading
* Adds a runtime test to better assess static Python behavior

Please let me know how you would prefer to proceed.

Best regards,
Shubham

Marcus
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw

Hi Marcus,

This mostly comes from a practical need on my side.

I maintain a small repo of statically compiled binaries that I use inside Android apps, where keeping runtime dependencies minimal is pretty important. For that setup, I’m using musl and targeting fully static builds. While doing this, I ran into the Python3 build failure in Buildroot, which is what led me to dig into it a bit more.

From what I’ve tested so far, it looks like a usable static interpreter is possible for more constrained scenarios—especially if the required modules are built in and there’s no need for dynamically loaded third-party extensions.

Since I rely on static linking for portability and simplicity in my workflow, having something like this working is quite useful for me. That’s why I wanted to check whether the earlier limitations could be relaxed at least partially.

Best regards,
Shubham

Quoted 50 lines · Marcus Hoffmann,

Hi Shubham,

please keep the list in CC in your replies.

Quoted 25 lines · Shubham Chakraborty

Hi Marcus,

I investigated the original reason for disabling static Python 3 support (commit 54915af7). At the time, the issue was that the interpreter attempted to load standard library modules dynamically, which fails in static-only configurations.

From my testing, this limitation can be partially addressed.

I was able to build and run a statically linked Python interpreter using

|--disable-shared| and |--with-static-libpython|. By configuring |
Modules/Setup.local|, several standard library extension modules (e.g. |
math|, |_json|, |_struct|, hashing modules) can be built-in, avoiding

the need for dynamic loading with musl libc.

I validated this on AArch64 using QEMU. The interpreter starts correctly, and built-in modules work as expected. Basic operations and selected imports succeed in this configuration.

However, this setup is not yet fully equivalent to a standard Python environment. Some parts of the standard library and general script execution still require further validation, and third-party C extensions are not automatically supported (they would require manual inclusion in |Setup.local|).

Quoted 3 lines

Based on this, it appears that partial support for static-only Python 3 may be feasible, but additional work is needed to determine whether it is robust enough to re-enable in Buildroot.

I think the question here is: would anyone want this? Do you have a usecase for this?

Quoted 3 lines

If this direction is of interest, I can continue investigating and prepare a patch series that:

I'm confused now. You tried to fix a static-only python3 build failure, which is not something that buildroot currently supports/allows. How did you even encounter that? What is your reason to work on that?

Quoted 5 lines

* Re-enables python3 with |BR2_STATIC_LIBS=y| (if deemed acceptable)
* Adjusts module configuration to minimize reliance on dynamic loading
* Adds a runtime test to better assess static Python behavior

Quoted 7 lines
Quoted 5 lines

Please let me know how you would prefer to proceed.

Best regards,
Shubham

Marcus

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot