sizeof(long) and universal builds

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

sizeof(long) and universal builds

Mojca Miklavec-2
Hi,

While checking some patches of a library I decided to try whether the
library would build universally. The configure.ac part contains:

    AC_COMPILE_CHECK_SIZEOF([long])

and that happily fails with

    checking size of long... configure: error: cannot determine a size for long

when setting

    CXXFLAGS="-arch i386 -arch x86_64"

What's the correct way to handle universal builds in that respect? Or
is it that is simply cannot be done?

Thank you,
    Mojca


PS: here's the relevant commit:
https://github.com/gdraheim/zziplib/commit/75ddc796529b191437514be2bbf6a2f561a74a6f
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(long) and universal builds

Michael Dickens-4
In the past, I've handled this situation by using the muniversal PortGroup, so that the sizeof is correct for each build independent of the other. - MLD

On Thu, Mar 1, 2018, at 2:40 PM, Mojca Miklavec wrote:

> While checking some patches of a library I decided to try whether the
> library would build universally. The configure.ac part contains:
>
>     AC_COMPILE_CHECK_SIZEOF([long])
>
> and that happily fails with
>
>     checking size of long... configure: error: cannot determine a size for long
>
> when setting
>
>     CXXFLAGS="-arch i386 -arch x86_64"
>
> What's the correct way to handle universal builds in that respect? Or
> is it that is simply cannot be done?
>
> Thank you,
>     Mojca
>
>
> PS: here's the relevant commit:
> https://github.com/gdraheim/zziplib/commit/75ddc796529b191437514be2bbf6a2f561a74a6f
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(long) and universal builds

Mojca Miklavec-2
On 1 March 2018 at 20:42, Michael Dickens wrote:
> In the past, I've handled this situation by using the muniversal PortGroup, so that the sizeof is correct for each build independent of the other. - MLD

I'm aware of that. I was wondering if there was some *proper* solution
that could allow compiling just once.

Mojca

> On Thu, Mar 1, 2018, at 2:40 PM, Mojca Miklavec wrote:
>> While checking some patches of a library I decided to try whether the
>> library would build universally. The configure.ac part contains:
>>
>>     AC_COMPILE_CHECK_SIZEOF([long])
>>
>> and that happily fails with
>>
>>     checking size of long... configure: error: cannot determine a size for long
>>
>> when setting
>>
>>     CXXFLAGS="-arch i386 -arch x86_64"
>>
>> What's the correct way to handle universal builds in that respect? Or
>> is it that is simply cannot be done?
>>
>> Thank you,
>>     Mojca
>>
>>
>> PS: here's the relevant commit:
>> https://github.com/gdraheim/zziplib/commit/75ddc796529b191437514be2bbf6a2f561a74a6f
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(long) and universal builds

Michael Dickens-4
Since the port is using GNU Autotools, AC_COMPILE_CHECK_SIZEOF will return one of 2 values depending on which -arch flag is used / set / set first / some random reason; it cannot return both values. Hence why using muniversal if truly in doubt.

The best solution is to use pre-sized types such as uint64_t or the like. There's just no good reason to need sizeof(long) unless it is used to set things such as uint64_t ...

... which is exactly what zziplib seems to do; see also:
* < https://github.com/gdraheim/zziplib/search?q=ZZIP_SIZEOF_SHORT >
* < https://github.com/gdraheim/zziplib/search?q=ZZIP_SIZEOF_INT >
* < https://github.com/gdraheim/zziplib/search?q=ZZIP_SIZEOF_LONG >
which all point (for Darwin) to this file:
< https://github.com/gdraheim/zziplib/blob/master/zzip/stdint.h >
which tries to define "uint*_t" and "int*_t".

This file includes, in this order, the first available of:
{{{
#include <stdint.h>
-or-
#include <sys/int_types.h>
-or-
#include <inttypes.h>
}}}
before using the ZZIP_SIZEOF_LONG (etc). Since at least one of these #includes is available on all Darwin, the *_SIZEOF_* aren't even used. Not the best configure.ac programming, IMHO.

I'm guessing that zziplib uses the uint*_t & int*_t internally, which if so then it's safe to use +universal for this port without using muniversal or any special trickery.

Hope this helps! - MLD

On Thu, Mar 1, 2018, at 4:27 PM, Mojca Miklavec wrote:

> On 1 March 2018 at 20:42, Michael Dickens wrote:
> > In the past, I've handled this situation by using the muniversal PortGroup, so that the sizeof is correct for each build independent of the other. - MLD
>
> I'm aware of that. I was wondering if there was some *proper* solution
> that could allow compiling just once.
>
> Mojca
>
> > On Thu, Mar 1, 2018, at 2:40 PM, Mojca Miklavec wrote:
> >> While checking some patches of a library I decided to try whether the
> >> library would build universally. The configure.ac part contains:
> >>
> >>     AC_COMPILE_CHECK_SIZEOF([long])
> >>
> >> and that happily fails with
> >>
> >>     checking size of long... configure: error: cannot determine a size for long
> >>
> >> when setting
> >>
> >>     CXXFLAGS="-arch i386 -arch x86_64"
> >>
> >> What's the correct way to handle universal builds in that respect? Or
> >> is it that is simply cannot be done?
> >>
> >> Thank you,
> >>     Mojca
> >>
> >>
> >> PS: here's the relevant commit:
> >> https://github.com/gdraheim/zziplib/commit/75ddc796529b191437514be2bbf6a2f561a74a6f
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(long) and universal builds

Joshua Root-8
In reply to this post by Mojca Miklavec-2
On 2018-3-2 08:27 , Mojca Miklavec wrote:
> On 1 March 2018 at 20:42, Michael Dickens wrote:
>> In the past, I've handled this situation by using the muniversal PortGroup, so that the sizeof is correct for each build independent of the other. - MLD
>
> I'm aware of that. I was wondering if there was some *proper* solution
> that could allow compiling just once.

Quite a few ports avoid having to use muniversal with a small ed script
that is applied to config.h in post-configure. You could also patch
config.h.in and remove the check from the configure script to avoid the
failure (though I'm not sure why it's failing rather than simply
erroneously producing a single value.)

Examples of the ed script approach: glib2, lzo, flac.

BTW, checking the size of types by compiling a program at configure time
should be avoided in general because it also makes cross-compilation
difficult.

- Josh
Reply | Threaded
Open this post in threaded view
|

Re: sizeof(long) and universal builds

Mojca Miklavec-2
On 2 March 2018 at 07:15, Joshua Root wrote:

> On 2018-3-2 08:27 , Mojca Miklavec wrote:
>> On 1 March 2018 at 20:42, Michael Dickens wrote:
>>> In the past, I've handled this situation by using the muniversal PortGroup, so that the sizeof is correct for each build independent of the other. - MLD
>>
>> I'm aware of that. I was wondering if there was some *proper* solution
>> that could allow compiling just once.
>
> Quite a few ports avoid having to use muniversal with a small ed script
> that is applied to config.h in post-configure. You could also patch
> config.h.in and remove the check from the configure script to avoid the
> failure (though I'm not sure why it's failing rather than simply
> erroneously producing a single value.)
>
> Examples of the ed script approach: glib2, lzo, flac.
>
> BTW, checking the size of types by compiling a program at configure time
> should be avoided in general because it also makes cross-compilation
> difficult.

This one was now fixed upstream:
https://github.com/gdraheim/zziplib/commit/9c3d8567d928d04a9ca5a540b494b99c03c8b99e

Thanks for hints,
Mojca