[PATCH 2 of 2] build: add qemu-wrapper support for cross-compiling

aduskett at gmail.com aduskett at gmail.com
Fri Jun 25 21:13:49 UTC 2021


# HG changeset patch
# User Adam Duskett <aduskett at gmail.com>
# Date 1624654367 25200
#      Fri Jun 25 13:52:47 2021 -0700
# Node ID 54c1ab7fb6aec6f52946ee751160b139c485f620
# Parent  e6d0b8882618fd43f4b97a6d0e708de9b82d44e5
build: add qemu-wrapper support for cross-compiling

Because unit doesn't use a traditional build system like autotools,
cmake, or meson, cross-compiling support has several major issues.

The largest issue is that the configure system builds test
application to determin compiler and system features, which, if
cross-compiling, will not run on the host pc due to the architecture
being different.

The proper fix would be to switch the build system to CMake or Meson,
but in the meantime adding support for a qemu wrapper is the best
alternative.

When --autotest-qemu-wrapper is provided as a configure option,
auto/feature will use the wrapper to run the cross-compiled autotest
application.

diff -r e6d0b8882618 -r 54c1ab7fb6ae auto/feature
--- a/auto/feature	Fri Jun 25 13:46:21 2021 -0700
+++ b/auto/feature	Fri Jun 25 13:52:47 2021 -0700
@@ -47,14 +47,18 @@
 
 
 if [ -x $NXT_AUTOTEST ]; then
+    NXT_AUTOTEST_RUN="$NXT_AUTOTEST"
+    if [ "$AUTOTEST_QEMU_WRAPPER" != "none" ]; then
+      NXT_AUTOTEST_RUN="$AUTOTEST_QEMU_WRAPPER $NXT_AUTOTEST"
+    fi
 
     case "$nxt_feature_run" in
 
         value)
-            if /bin/sh -c "($NXT_AUTOTEST)" >> $NXT_AUTOCONF_ERR 2>&1; then
+            if /bin/sh -c "($NXT_AUTOTEST_RUN)" >> $NXT_AUTOCONF_ERR 2>&1; then
                 $echo >> $NXT_AUTOCONF_ERR
                 nxt_found=yes
-                nxt_feature_value=`$NXT_AUTOTEST`
+                nxt_feature_value=`$NXT_AUTOTEST_RUN`
                 $echo " $nxt_feature_value"
                 if [ -n "$nxt_feature_name" ]; then
                     cat << END >> $NXT_AUTO_CONFIG_H
@@ -71,7 +75,7 @@
         ;;
 
         yes)
-            if /bin/sh -c "($NXT_AUTOTEST)" >> $NXT_AUTOCONF_ERR 2>&1; then
+            if /bin/sh -c "($NXT_AUTOTEST_RUN)" >> $NXT_AUTOCONF_ERR 2>&1; then
                 $echo " found"
                 nxt_found=yes
                 if [ -n "$nxt_feature_name" ]; then
diff -r e6d0b8882618 -r 54c1ab7fb6ae auto/options
--- a/auto/options	Fri Jun 25 13:46:21 2021 -0700
+++ b/auto/options	Fri Jun 25 13:52:47 2021 -0700
@@ -50,6 +50,7 @@
     esac
 
     case "$nxt_option" in
+        --autotest-qemu-wrapper=*)       AUTOTEST_QEMU_WRAPPER="$value"      ;;
         --cc=*)                          CC="$value"                         ;;
         --cc-opt=*)                      NXT_CC_OPT="$value"                 ;;
         --host-cc=*)                     HOST_CC="$value"                    ;;
diff -r e6d0b8882618 -r 54c1ab7fb6ae auto/save
--- a/auto/save	Fri Jun 25 13:46:21 2021 -0700
+++ b/auto/save	Fri Jun 25 13:52:47 2021 -0700
@@ -7,6 +7,7 @@
 
 NXT_SYSTEM='$NXT_SYSTEM'
 
+AUTOTEST_QEMU_WRAPPER='$AUTOTEST_QEMU_WRAPPER'
 CC='$CC'
 HOST_CC='$HOST_CC'
 CFLAGS='$CFLAGS'
diff -r e6d0b8882618 -r 54c1ab7fb6ae configure
--- a/configure	Fri Jun 25 13:46:21 2021 -0700
+++ b/configure	Fri Jun 25 13:52:47 2021 -0700
@@ -30,7 +30,7 @@
 
 CC=${CC:-cc}
 HOST_CC=${HOST_CC:-cc}
-
+AUTOTEST_QEMU_WRAPPER=${AUTOTEST_QEMU_WRAPPER:-"none"}
 NXT_DAEMON=unitd
 NXT_BINDIR="bin"
 NXT_SBINDIR="sbin"



More information about the unit mailing list