Skip to contentSkip to conversation

package/swig: add host-swig wrapper script

PATCH Applied Peter Korsgaard 2 participants 3 messages Jan 24 – Feb 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/swig: add host-swig wrapper script

Swig has a compiled in absolute path to its data files, which can be overridden using the SWIG_LIB environment variable:

https://github.com/swig/swig/blob/v4.1.1/Source/Modules/main.cxx#L931-L945

This unfortunately means that host-swig misbehaves when used in the SDK, as this points to the ${HOST_DIR}/bin of the build, which may not be available when the SDK is used.

The issue was reported upstream but rejected in
https://github.com/swig/swig/issues/253, so instead add a wrapper script which calculates a sensible SWIG_LIB relative to the wrapper location unless SWIG_LIB is set, similar to how we do it for E.G. gcc or pkgconf.

---
 package/swig/swig-wrapper.in |  8 ++++++++
 package/swig/swig.mk         | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 package/swig/swig-wrapper.in
package/swig/swig-wrapper.in new file +8 -0
new file mode 100644
index 0000000000..68be44231f
@@ -0,0 +1,8 @@
+#!/bin/sh
+# wrapper to make swig relocatable
+
+if [ -z "${SWIG_LIB}" ]; then
+    export SWIG_LIB=${0%/*}/../share/swig/@SWIG_VERSION@
+fi
+
+exec "${0}.br_real" "$@"
package/swig/swig.mk +15 -0
index ad585c3f97..71e5e05f96 100644
@@ -15,6 +15,21 @@ HOST_SWIG_CONF_OPTS = \
 SWIG_LICENSE = GPL-3.0+, BSD-2-Clause, BSD-3-Clause
 SWIG_LICENSE_FILES = LICENSE LICENSE-GPL LICENSE-UNIVERSITIES
 
+# Swig has a compiled in absolute path to its data files, so it does
+# not work when copied somewhere else for the SDK. Issue was reported
+# upstream but rejected in https://github.com/swig/swig/issues/253 so
+# instead add a wrapper to work around this
+
+define HOST_SWIG_INSTALL_WRAPPER
+	mv -f $(HOST_DIR)/bin/swig $(HOST_DIR)/bin/swig.br_real
+	$(INSTALL) -m 0755 -D package/swig/swig-wrapper.in \
+		$(HOST_DIR)/bin/swig
+	$(SED) 's,@SWIG_VERSION@,$(SWIG_VERSION),g' \
+		$(HOST_DIR)/bin/swig
+endef
+
+HOST_SWIG_POST_INSTALL_HOOKS += HOST_SWIG_INSTALL_WRAPPER
+
 # CMake looks first at swig3.0, then swig2.0 and then swig. However,
 # when doing the search, it will look into the PATH for swig2.0 first,
 # and then for swig.
Signature · 6 lines
2.47.3

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

"Peter" == Peter Korsgaard <[email protected]> writes:

Swig has a compiled in absolute path to its data files, which can be overridden using the SWIG_LIB environment variable:

https://github.com/swig/swig/blob/v4.1.1/Source/Modules/main.cxx#L931-L945

This unfortunately means that host-swig misbehaves when used in the SDK, as this points to the ${HOST_DIR}/bin of the build, which may not be available when the SDK is used.

The issue was reported upstream but rejected in
https://github.com/swig/swig/issues/253, so instead add a wrapper script which calculates a sensible SWIG_LIB relative to the wrapper location unless SWIG_LIB is set, similar to how we do it for E.G. gcc or pkgconf.

---
 package/swig/swig-wrapper.in |  8 ++++++++
 package/swig/swig.mk         | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 package/swig/swig-wrapper.in
package/swig/swig-wrapper.in new file +0 -0
new file mode 100644
index 0000000000..68be44231f

package/swig/swig-wrapper.in line 5

Quoted 5 lines
package/swig/swig-wrapper.in new file +5 -0
@@ -0,0 +1,8 @@
+#!/bin/sh
+# wrapper to make swig relocatable
+
+if [ -z "${SWIG_LIB}" ]; then
+    export SWIG_LIB=${0%/*}/../share/swig/@SWIG_VERSION@

Added quotes around this to make shellcheck happy and committed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Peter Korsgaard

In reply of:

Quoted 9 lines

Swig has a compiled in absolute path to its data files, which can be overridden using the SWIG_LIB environment variable:

https://github.com/swig/swig/blob/v4.1.1/Source/Modules/main.cxx#L931-L945

This unfortunately means that host-swig misbehaves when used in the SDK, as this points to the ${HOST_DIR}/bin of the build, which may not be available when the SDK is used.

Quoted 6 lines

The issue was reported upstream but rejected in
https://github.com/swig/swig/issues/253, so instead add a wrapper script which calculates a sensible SWIG_LIB relative to the wrapper location unless SWIG_LIB is set, similar to how we do it for E.G. gcc or pkgconf.

Applied to 2025.02.x & 2025.11.x. Thanks

Quoted 53 lines
---
 package/swig/swig-wrapper.in |  8 ++++++++
 package/swig/swig.mk         | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 package/swig/swig-wrapper.in
package/swig/swig-wrapper.in new file +8 -0
new file mode 100644
index 0000000000..68be44231f
@@ -0,0 +1,8 @@
+#!/bin/sh
+# wrapper to make swig relocatable
+
+if [ -z "${SWIG_LIB}" ]; then
+    export SWIG_LIB=${0%/*}/../share/swig/@SWIG_VERSION@
+fi
+
+exec "${0}.br_real" "$@"
package/swig/swig.mk +15 -0
index ad585c3f97..71e5e05f96 100644
@@ -15,6 +15,21 @@ HOST_SWIG_CONF_OPTS = \
 SWIG_LICENSE = GPL-3.0+, BSD-2-Clause, BSD-3-Clause
 SWIG_LICENSE_FILES = LICENSE LICENSE-GPL LICENSE-UNIVERSITIES
 
+# Swig has a compiled in absolute path to its data files, so it does
+# not work when copied somewhere else for the SDK. Issue was reported
+# upstream but rejected in https://github.com/swig/swig/issues/253 so
+# instead add a wrapper to work around this
+
+define HOST_SWIG_INSTALL_WRAPPER
+	mv -f $(HOST_DIR)/bin/swig $(HOST_DIR)/bin/swig.br_real
+	$(INSTALL) -m 0755 -D package/swig/swig-wrapper.in \
+		$(HOST_DIR)/bin/swig
+	$(SED) 's,@SWIG_VERSION@,$(SWIG_VERSION),g' \
+		$(HOST_DIR)/bin/swig
+endef
+
+HOST_SWIG_POST_INSTALL_HOOKS += HOST_SWIG_INSTALL_WRAPPER
+
 # CMake looks first at swig3.0, then swig2.0 and then swig. However,
 # when doing the search, it will look into the PATH for swig2.0 first,
 # and then for swig.
Signature · 6 lines
2.47.3

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

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