Bug#971249: [Pkg-samba-maint] Bug#971249: waf: CHECK_VALUEOF does not work during cross compilation

2022-05-08 Thread Andrew Bartlett
On Fri, 2022-05-06 at 11:40 +0300, Michael Tokarev wrote:
> On Mon, 28 Sep 2020 06:53:03 +0200 Helmut Grohne 
> wrote:
> > Source: tevent
> > Version: 0.10.2-1
> > Tags: patch upstream
> > User: debian-cr...@lists.debian.org
> > Usertags: ftcbfs
> > 
> > Thank you for applying my previous cross build patches. My previous
> > installment ended with:
> > 
> > > 5. waf has a mandatory run test for determining whether mkstemp
> > > works.
> > > 6. probably more
> > 
> > I've now looked into this and think that there are two bigger steps
> > to
> > solve these. In the "probably more" department, there is a
> > recurring
> > scheme of using a "CHECK_VALUEOF". It is used to determine the
> > value of
> > an integer. If that value happens to be a compile time constant, it
> > can
> > be determined using bisection. waf already does something similar
> > in
> > CHECK_SIZEOF. I've implemented it for CHECK_VALUEOF and it now
> > works
> > similar to autoconf's AC_COMPUTE_INT. In particular, it only does
> > the
> > expensive bisection during cross compilation. In a native build, it
> > continues to use the quick run test it did before. I've attached a
> > patch
> > for this.
> 
> Umm. waf in samba is doing many "bad" things which can be done in a
> more
> efficient way not requiring to run compiled binaries. Yes,
> sizeof(foo) is
> a good example, valueof is another example.
> 
> I think it is too much work to patch all these things out in debian.
> It might be a good idea to try to ping upstream about this, maybe
> they'll
> include similar change(s) to make cross-compilations easier.  But
> probably
> not in Debian.

Samba regularly accepts changes to improve cross-compilation.  We test
a lame cross-compilation mode in our autobuild and would love to have
both an improved test (that is more realistic) and any improvements our
user community can find. 

> I'd not spend more time on trying to make waf-based samba builds to
> be
> cross-compilable, unless upstream is actually willing to accept the
> work somehow. So far, it seems like upstream isn't willing even to
> accept simple spelling fixes.

We regularly accept patches that are correctly signed off and submitted
to GitLab per https://wiki.samba.org/index.php/Contribute

> FWIW, Helmut, what do you think about using qemu-user[-static] to
> help
> cross-compiling stuff? It should significantly help in situations
> like
> this one, to be able to run the small test binaries in an emulated
> mode,
> provided you do have the foreign libs installed on the system.  Yes
> it
> is not the fastest, but for sizeof/valueof tests like this it will
> Just Work, hopefully...

This would seem to be the best route forward, per:

https://wiki.samba.org/index.php/Waf#Using_--cross-execute

Andrew Bartlett

-- 
Andrew Bartlett (he/him)   https://samba.org/~abartlet/
Samba Team Member (since 2001) https://samba.org
Samba Team Lead, Catalyst IT   https://catalyst.net.nz/services/samba

Samba Development and Support, Catalyst IT - Expert Open Source
Solutions



Bug#971249: waf: CHECK_VALUEOF does not work during cross compilation

2022-05-06 Thread Michael Tokarev

On Mon, 28 Sep 2020 06:53:03 +0200 Helmut Grohne  wrote:

Source: tevent
Version: 0.10.2-1
Tags: patch upstream
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

Thank you for applying my previous cross build patches. My previous
installment ended with:

> 5. waf has a mandatory run test for determining whether mkstemp works.
> 6. probably more

I've now looked into this and think that there are two bigger steps to
solve these. In the "probably more" department, there is a recurring
scheme of using a "CHECK_VALUEOF". It is used to determine the value of
an integer. If that value happens to be a compile time constant, it can
be determined using bisection. waf already does something similar in
CHECK_SIZEOF. I've implemented it for CHECK_VALUEOF and it now works
similar to autoconf's AC_COMPUTE_INT. In particular, it only does the
expensive bisection during cross compilation. In a native build, it
continues to use the quick run test it did before. I've attached a patch
for this.


Umm. waf in samba is doing many "bad" things which can be done in a more
efficient way not requiring to run compiled binaries. Yes, sizeof(foo) is
a good example, valueof is another example.

I think it is too much work to patch all these things out in debian.
It might be a good idea to try to ping upstream about this, maybe they'll
include similar change(s) to make cross-compilations easier.  But probably
not in Debian.

I'd not spend more time on trying to make waf-based samba builds to be
cross-compilable, unless upstream is actually willing to accept the
work somehow. So far, it seems like upstream isn't willing even to
accept simple spelling fixes.

FWIW, Helmut, what do you think about using qemu-user[-static] to help
cross-compiling stuff? It should significantly help in situations like
this one, to be able to run the small test binaries in an emulated mode,
provided you do have the foreign libs installed on the system.  Yes it
is not the fastest, but for sizeof/valueof tests like this it will
Just Work, hopefully...

Thanks,

/mjt



Bug#971249: waf: CHECK_VALUEOF does not work during cross compilation

2020-09-27 Thread Helmut Grohne
Source: tevent
Version: 0.10.2-1
Tags: patch upstream
User: debian-cr...@lists.debian.org
Usertags: ftcbfs

Thank you for applying my previous cross build patches. My previous
installment ended with:

> 5. waf has a mandatory run test for determining whether mkstemp works.
> 6. probably more

I've now looked into this and think that there are two bigger steps to
solve these. In the "probably more" department, there is a recurring
scheme of using a "CHECK_VALUEOF". It is used to determine the value of
an integer. If that value happens to be a compile time constant, it can
be determined using bisection. waf already does something similar in
CHECK_SIZEOF. I've implemented it for CHECK_VALUEOF and it now works
similar to autoconf's AC_COMPUTE_INT. In particular, it only does the
expensive bisection during cross compilation. In a native build, it
continues to use the quick run test it did before. I've attached a patch
for this.

For the mkstemp thingy there is little we can do. You cannot check this
property without running code. So during cross compilation, all you can
do is assume that it works. I think the solution will be adding

--cross-compile --cross-answers=somefile

to the waf invocation and having it tell that mkstemp works. This is
also is similar to what autoconf does except that autoconf has
centralized this answer file into a cross-config package. Does that work
for you?

Therefore please consider applying this patch for CHECK_VALUEOF,
preferrably upstream it. For making it work in the packaging, one must
pass --cross-compile to waf. You can do so using the following snippet:

$(if $(filter $(DEB_BUILD_ARCH),$(DEB_HOST_ARCH)),,--cross-compile)

Thank you

Helmut
--- tevent-0.10.2.orig/buildtools/wafsamba/samba_autoconf.py
+++ tevent-0.10.2/buildtools/wafsamba/samba_autoconf.py
@@ -348,16 +348,72 @@
 v_define = define
 if v_define is None:
 v_define = 'VALUEOF_%s' % v.upper().replace(' ', '_')
-if CHECK_CODE(conf,
-  'printf("%%u", (unsigned)(%s))' % v,
-  define=v_define,
-  execute=True,
-  define_ret=True,
-  quote=False,
-  headers=headers,
-  local_include=False,
-  msg="Checking value of %s" % v):
-return int(conf.env[v_define])
+if conf.env.CROSS_COMPILE:
+negative = CHECK_CODE(conf,
+'static int test_array[1 - 2 * !((%s) < 0)];' % v,
+define=v_define + "_negative",
+quote=False, addmain=False, link=False,
+headers=headers,
+local_include=False,
+msg="Checking if %s is negative" % v)
+positive = CHECK_CODE(conf,
+'static int test_array[1 - 2 * !((%s) > 0)];' % v,
+define=v_define + "_positive",
+quote=False, addmain=False, link=False,
+headers=headers,
+local_include=False,
+msg="Checking if %s is positive" % v)
+zero = CHECK_CODE(conf,
+'static int test_array[1 - 2 * !((%s) == 0)];' % v,
+define=v_define + "_zero",
+quote=False, addmain=False, link=False,
+headers=headers,
+local_include=False,
+msg="Checking if %s is zero" % v)
+if zero + positive + negative != 1:
+Logs.warn("Couldn't determine value of '%s'" % v)
+return None
+if zero:
+return 0
+upper_bound = 1
+comp = ">=" if negative else "<="
+sign = -1 if negative else 1
+while not CHECK_CODE(conf,
+'static int test_array[1 - 2 * !((%s) %s %d)];' %
+ (v, comp, sign * upper_bound),
+define=v_define + "_le_%d" % upper_bound,
+quote=False, addmain=False, link=False,
+headers=headers,
+local_include=False,
+msg="Checking if %s %s %d" % (v, comp, sign * upper_bound)):
+upper_bound *= 2
+lower_bound = upper_bound // 2
+while lower_bound + 1 < upper_bound:
+mid = (lower_bound + upper_bound) // 2
+if CHECK_CODE(conf,
+'static int test_array[1 - 2 * !((%s) %s %d)];' %
+ (v, comp, sign * mid),
+define=v_define + "_le_%d" % upper_bound,
+quote=False, addmain=False, link=False,
+headers=headers,
+local_include=False,
+msg="Checking if %s %s %d" % (v, comp, sign * mid)):
+upper_bound = mid
+else:
+lower_bound = mid
+conf.DEFINE(v_define, upper_bound)
+return upper_bound
+else:
+if CHECK_CODE(conf,
+  'printf("%%u", (unsigned)(%s))' % v,
+  define=v_define,
+