sizeof(long) and universal builds

Michael Dickens michaelld at macports.org
Thu Mar 1 21:48:49 UTC 2018


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


More information about the macports-dev mailing list