Skip to contentSkip to conversation

package/pkg-meson.mk: set Python sysconfigdata

PATCH New Arnout Vandecappelle (Essensium/Mind) 2 participants 7 messages Aug 4, 2019 – Oct 15, 2019 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

meson has support for Python dependencies, to e.g. build Python modules. It parses Python's sysconfig module to find the appropriate configuration variables. However, the sysconfig module is the one for the host, _not_ for the target. Therefore, wrong values may be set. Many of them get overridden anyway by the cross-compilation.conf. One particular one that is problematic is that it uses the python-XXX.pc pkg-config file for the host instead of the target, because it explicitly sets the PKG_CONFIG_LIBDIR found in sysconfig.

Use the same trick as for python package: pass PYTHONPATH, PYTHONNOUSERSITE and _PYTHON_SYSCONFIGDATA_NAME in the environment to point to staging instead of host. This ensures the sysconfig from the target is used instead of the one from the host.

An alternative would be to patch meson to not use the PKG_CONFIG_LIBDIR from sysconfig. However, it is likely that other problems will pop up at some point because of using the wrong sysconfig.

Note that this approach will still break things when meson needs to build something for the host during a target build.

Cc Adam Duskett <[email protected]>
Cc Eric Le Bihan <[email protected]>
Cc Peter Seiderer <[email protected]>
Cc James Hilliard <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
The setting of _PYTHON_SYSCONFIGDATA_NAME is different from the one in pkg-python.mk. I don't understand how that definition could work: for Python2, it is empty, so sysconfig tries to import a module with name "". So apparently the call paths used by meson and by setuptools/distutils are slightly different.

---
 package/pkg-meson.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-meson.mk +3 -0
index 0b811d1cc0..3f875c08ce 100644
@@ -81,6 +81,9 @@ define $(2)_CONFIGURE_CMDS
 	    -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
 	    package/meson/cross-compilation.conf.in \
 	    > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
+	_PYTHON_SYSCONFIGDATA_NAME="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \
+	PYTHONPATH="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PYTHON3_PATH),$$(PYTHON_PATH))" \
+	PYTHONNOUSERSITE=1 \
 	PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
 		--prefix=/usr \
 		--libdir=lib \
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

All;

Quoted 53 lines · Arnout Vandecappelle (Essensium/Mind)

meson has support for Python dependencies, to e.g. build Python modules. It parses Python's sysconfig module to find the appropriate configuration variables. However, the sysconfig module is the one for the host, _not_ for the target. Therefore, wrong values may be set. Many of them get overridden anyway by the cross-compilation.conf. One particular one that is problematic is that it uses the python-XXX.pc pkg-config file for the host instead of the target, because it explicitly sets the PKG_CONFIG_LIBDIR found in sysconfig.

Use the same trick as for python package: pass PYTHONPATH, PYTHONNOUSERSITE and _PYTHON_SYSCONFIGDATA_NAME in the environment to point to staging instead of host. This ensures the sysconfig from the target is used instead of the one from the host.

An alternative would be to patch meson to not use the PKG_CONFIG_LIBDIR from sysconfig. However, it is likely that other problems will pop up at some point because of using the wrong sysconfig.

Note that this approach will still break things when meson needs to build something for the host during a target build.

Cc Adam Duskett <[email protected]>
Cc Eric Le Bihan <[email protected]>
Cc Peter Seiderer <[email protected]>
Cc James Hilliard <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
The setting of _PYTHON_SYSCONFIGDATA_NAME is different from the one in pkg-python.mk. I don't understand how that definition could work: for Python2, it is empty, so sysconfig tries to import a module with name "". So apparently the call paths used by meson and by setuptools/distutils are slightly different.

---
 package/pkg-meson.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-meson.mk +3 -1
index 0b811d1cc0..3f875c08ce 100644
@@ -81,6 +81,9 @@ define $(2)_CONFIGURE_CMDS
            -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
            package/meson/cross-compilation.conf.in \
            > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
+       _PYTHON_SYSCONFIGDATA_NAME="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \
+       PYTHONPATH="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PYTHON3_PATH),$$(PYTHON_PATH))" \
+       PYTHONNOUSERSITE=1 \
        PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
                --prefix=/usr \
                --libdir=lib \
--
Quoted 2 lines

2.21.0

Not only does this work, it also fixes cross-compiled python libraries names built by meson (such as the new versions of python-gobject)

#2 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

All;

Any update on this patch? Now that libglib 2.62.0 is in Buildroot, I will need to submit a new patch set, which requires this patch.

Thanks!

Adam

Quoted 65 lines · Adam Duskett

All;

Quoted 53 lines · Arnout Vandecappelle (Essensium/Mind)

meson has support for Python dependencies, to e.g. build Python modules. It parses Python's sysconfig module to find the appropriate configuration variables. However, the sysconfig module is the one for the host, _not_ for the target. Therefore, wrong values may be set. Many of them get overridden anyway by the cross-compilation.conf. One particular one that is problematic is that it uses the python-XXX.pc pkg-config file for the host instead of the target, because it explicitly sets the PKG_CONFIG_LIBDIR found in sysconfig.

Use the same trick as for python package: pass PYTHONPATH, PYTHONNOUSERSITE and _PYTHON_SYSCONFIGDATA_NAME in the environment to point to staging instead of host. This ensures the sysconfig from the target is used instead of the one from the host.

An alternative would be to patch meson to not use the PKG_CONFIG_LIBDIR from sysconfig. However, it is likely that other problems will pop up at some point because of using the wrong sysconfig.

Note that this approach will still break things when meson needs to build something for the host during a target build.

Cc Adam Duskett <[email protected]>
Cc Eric Le Bihan <[email protected]>
Cc Peter Seiderer <[email protected]>
Cc James Hilliard <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
The setting of _PYTHON_SYSCONFIGDATA_NAME is different from the one in pkg-python.mk. I don't understand how that definition could work: for Python2, it is empty, so sysconfig tries to import a module with name "". So apparently the call paths used by meson and by setuptools/distutils are slightly different.

---
 package/pkg-meson.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-meson.mk +3 -1
index 0b811d1cc0..3f875c08ce 100644
@@ -81,6 +81,9 @@ define $(2)_CONFIGURE_CMDS
            -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
            package/meson/cross-compilation.conf.in \
            > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
+       _PYTHON_SYSCONFIGDATA_NAME="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \
+       PYTHONPATH="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PYTHON3_PATH),$$(PYTHON_PATH))" \
+       PYTHONNOUSERSITE=1 \
        PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
                --prefix=/usr \
                --libdir=lib \
--
Quoted 2 lines

2.21.0

Not only does this work, it also fixes cross-compiled python libraries names built by meson (such as the new versions of python-gobject)

#3 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

Sorry;

I will need to submit a new gobject-introspection patch set; which requires this patch.

Adam

Quoted 76 lines · Adam Duskett

All;

Any update on this patch? Now that libglib 2.62.0 is in Buildroot, I will need to submit a new patch set, which requires this patch.

Thanks!

Adam

Quoted 65 lines · Adam Duskett

All;

Quoted 53 lines · Arnout Vandecappelle (Essensium/Mind)

meson has support for Python dependencies, to e.g. build Python modules. It parses Python's sysconfig module to find the appropriate configuration variables. However, the sysconfig module is the one for the host, _not_ for the target. Therefore, wrong values may be set. Many of them get overridden anyway by the cross-compilation.conf. One particular one that is problematic is that it uses the python-XXX.pc pkg-config file for the host instead of the target, because it explicitly sets the PKG_CONFIG_LIBDIR found in sysconfig.

Use the same trick as for python package: pass PYTHONPATH, PYTHONNOUSERSITE and _PYTHON_SYSCONFIGDATA_NAME in the environment to point to staging instead of host. This ensures the sysconfig from the target is used instead of the one from the host.

An alternative would be to patch meson to not use the PKG_CONFIG_LIBDIR from sysconfig. However, it is likely that other problems will pop up at some point because of using the wrong sysconfig.

Note that this approach will still break things when meson needs to build something for the host during a target build.

Cc Adam Duskett <[email protected]>
Cc Eric Le Bihan <[email protected]>
Cc Peter Seiderer <[email protected]>
Cc James Hilliard <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
The setting of _PYTHON_SYSCONFIGDATA_NAME is different from the one in pkg-python.mk. I don't understand how that definition could work: for Python2, it is empty, so sysconfig tries to import a module with name "". So apparently the call paths used by meson and by setuptools/distutils are slightly different.

---
 package/pkg-meson.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-meson.mk +3 -1
index 0b811d1cc0..3f875c08ce 100644
@@ -81,6 +81,9 @@ define $(2)_CONFIGURE_CMDS
            -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
            package/meson/cross-compilation.conf.in \
            > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
+       _PYTHON_SYSCONFIGDATA_NAME="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \
+       PYTHONPATH="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PYTHON3_PATH),$$(PYTHON_PATH))" \
+       PYTHONNOUSERSITE=1 \
        PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
                --prefix=/usr \
                --libdir=lib \
--
Quoted 2 lines

2.21.0

Not only does this work, it also fixes cross-compiled python libraries names built by meson (such as the new versions of python-gobject)

#4 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

All;

I inadvertently found an issue with this patch.
If the user has not selected python or python3, _PYTHON_SYSCONFIGDATA_NAME will be passed as an empty string, which causes libglib2 to fail during the configuration step. Apparently, all of my previous testings were done with python3 enabled, and I didn't notice!

Adam

Quoted 85 lines · Adam Duskett

Sorry;

I will need to submit a new gobject-introspection patch set; which requires this patch.

Adam

Quoted 76 lines · Adam Duskett

All;

Any update on this patch? Now that libglib 2.62.0 is in Buildroot, I will need to submit a new patch set, which requires this patch.

Thanks!

Adam

Quoted 65 lines · Adam Duskett

All;

Quoted 53 lines · Arnout Vandecappelle (Essensium/Mind)

meson has support for Python dependencies, to e.g. build Python modules. It parses Python's sysconfig module to find the appropriate configuration variables. However, the sysconfig module is the one for the host, _not_ for the target. Therefore, wrong values may be set. Many of them get overridden anyway by the cross-compilation.conf. One particular one that is problematic is that it uses the python-XXX.pc pkg-config file for the host instead of the target, because it explicitly sets the PKG_CONFIG_LIBDIR found in sysconfig.

Use the same trick as for python package: pass PYTHONPATH, PYTHONNOUSERSITE and _PYTHON_SYSCONFIGDATA_NAME in the environment to point to staging instead of host. This ensures the sysconfig from the target is used instead of the one from the host.

An alternative would be to patch meson to not use the PKG_CONFIG_LIBDIR from sysconfig. However, it is likely that other problems will pop up at some point because of using the wrong sysconfig.

Note that this approach will still break things when meson needs to build something for the host during a target build.

Cc Adam Duskett <[email protected]>
Cc Eric Le Bihan <[email protected]>
Cc Peter Seiderer <[email protected]>
Cc James Hilliard <[email protected]>
Cc Yann E. MORIN <[email protected]>

---
The setting of _PYTHON_SYSCONFIGDATA_NAME is different from the one in pkg-python.mk. I don't understand how that definition could work: for Python2, it is empty, so sysconfig tries to import a module with name "". So apparently the call paths used by meson and by setuptools/distutils are slightly different.

---
 package/pkg-meson.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-meson.mk +3 -1
index 0b811d1cc0..3f875c08ce 100644
@@ -81,6 +81,9 @@ define $(2)_CONFIGURE_CMDS
            -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
            package/meson/cross-compilation.conf.in \
            > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
+       _PYTHON_SYSCONFIGDATA_NAME="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \
+       PYTHONPATH="$$(if $$(BR2_PACKAGE_PYTHON3),$$(PYTHON3_PATH),$$(PYTHON_PATH))" \
+       PYTHONNOUSERSITE=1 \
        PATH=$$(BR_PATH) $$($$(PKG)_CONF_ENV) $$(MESON) \
                --prefix=/usr \
                --libdir=lib \
--
Quoted 2 lines

2.21.0

Not only does this work, it also fixes cross-compiled python libraries names built by meson (such as the new versions of python-gobject)

#5 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

Quoted 5 lines · Adam Duskett

All;

I inadvertently found an issue with this patch.
If the user has not selected python or python3, _PYTHON_SYSCONFIGDATA_NAME will be passed as an empty string,

That's weird...

+ _PYTHON_SYSCONFIGDATA_NAME="$$(if
$$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \

If python3 is not selected, it should be set to _sysonfigdata... I don't
remember how extensively I tested that situation, but I definitely did take it into account!

Regards,
Arnout

Quoted 4 lines

which
causes libglib2 to fail during the configuration step. Apparently, all of my previous testings were done with python3 enabled, and I didn't notice!

[snip]

#6 lore raw

PATCH 1/1 package/pkg-meson.mk: set Python sysconfigdata

If you look at the Yocto project, it seems like they intentionally unset _PYTHON_SYSCONFIGDATA_NAME when compiling libglib2.

Quoted 28 lines · Arnout Vandecappelle
Quoted 5 lines · Adam Duskett

All;

I inadvertently found an issue with this patch.
If the user has not selected python or python3, _PYTHON_SYSCONFIGDATA_NAME will be passed as an empty string,

That's weird...

+ _PYTHON_SYSCONFIGDATA_NAME="$$(if
$$(BR2_PACKAGE_PYTHON3),$$(PKG_PYTHON_SYSCONFIGDATA_NAME),_sysconfigdata)" \

If python3 is not selected, it should be set to _sysonfigdata... I don't
remember how extensively I tested that situation, but I definitely did take it into account!

Regards,
Arnout

Quoted 4 lines

which
causes libglib2 to fail during the configuration step. Apparently, all of my previous testings were done with python3 enabled, and I didn't notice!

[snip]