Bug 39493 - 32-bit build fails with MacOSX10.7.sdk
Summary: 32-bit build fails with MacOSX10.7.sdk
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: quartz font backend (show other bugs)
Version: 1.10.3
Hardware: Other Mac OS X (All)
: medium normal
Assignee: Vladimir Vukicevic
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-23 10:36 UTC by John Ralls
Modified: 2011-10-01 09:31 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Correct all OSX 10.7 build failures (1.68 KB, patch)
2011-07-23 11:06 UTC, John Ralls
Details | Splinter Review
Make cairo-missing a static library (464 bytes, patch)
2011-09-07 07:21 UTC, Andrea Canciani
Details | Splinter Review
Cairo config.log for gtk-osx build (160.75 KB, text/plain)
2011-09-08 11:28 UTC, John Ralls
Details
The dlsym trick (3.66 KB, patch)
2011-09-18 09:27 UTC, Andrea Canciani
Details | Splinter Review

Description John Ralls 2011-07-23 10:36:15 UTC
Lion no longer includes the old 32-bit-only functions, so the ATSUI compatibility functions need an extra term in the #if:
  CC     cairo-quartz-font.lo
cairo-quartz-font.c: In function ‘cairo_quartz_font_face_create_for_atsu_font_id’:
cairo-quartz-font.c:826: error: implicit declaration of function ‘FMGetATSFontRefFromFont’
cairo-quartz-font.c:826: warning: nested extern declaration of ‘FMGetATSFontRefFromFont’


diff --git a/src/cairo-quartz-font.c b/src/cairo-quartz-font.c
index f529fc9..5ba3e1a 100644
--- a/src/cairo-quartz-font.c
+++ b/src/cairo-quartz-font.c
@@ -802,7 +802,7 @@ _cairo_quartz_scaled_font_get_cg_font_ref (cairo_scaled_font_t *abstract_font)
     return ffont->cgFont;
 }
 
-#ifndef __LP64__
+#if !defined __LP64__ && MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_6
 /*
  * compat with old ATSUI backend
  */
Comment 1 John Ralls 2011-07-23 11:06:17 UTC
Created attachment 49446 [details] [review]
Correct all OSX 10.7 build failures

Oops, that should have been "< MAC_OS_X_VERSION_10_7". 
There are also two files in perf that define getline and strndup, which are supplied by Lion in stdio.h and string.h, respectively. This patch works around those, as well.
Comment 2 Andrea Canciani 2011-08-28 22:36:24 UTC
(In reply to comment #1)
> Created an attachment (id=49446) [details]
> Correct all OSX 10.7 build failures
> 
> Oops, that should have been "< MAC_OS_X_VERSION_10_7". 

I can confirm this issue and the fix for ATSUI looks ok to me.

> There are also two files in perf that define getline and strndup, which are
> supplied by Lion in stdio.h and string.h, respectively. This patch works around
> those, as well.

I think that detecting the availability of  getline and strndup at through autoconf would be a better.
Comment 3 Andrea Canciani 2011-09-04 16:29:39 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Created an attachment (id=49446) [details] [details]
> > Correct all OSX 10.7 build failures
> > 
> > Oops, that should have been "< MAC_OS_X_VERSION_10_7". 
> 
> I can confirm this issue and the fix for ATSUI looks ok to me.

Looking more at it, I realized that it's probably an API break.

Another patch, which fixes the build for me is available here:
http://cgit.freedesktop.org/~ranma42/cairo/commit/?h=wip/lion-build&id=226ddd92589bc6d93ad7dab34e79e2770d096a69

Can you confirm if this patch solves your issue as well?

> 
> > There are also two files in perf that define getline and strndup, which are
> > supplied by Lion in stdio.h and string.h, respectively. This patch works around
> > those, as well.
> 
> I think that detecting the availability of  getline and strndup at through
> autoconf would be a better.

The autoconf-based detection is in master (and the implementation if the functions are not available is now in the util/cairo-missing library).
Comment 4 John Ralls 2011-09-05 17:14:52 UTC
Cairo builds on Lion with the ranma42 patch, yes.

The only problem with any build-time configuration for these is that the resulting shared library won't work on previous versions of OSX. That includes Snow Leopard and previous in the cases of getline and strndup, and Tiger for ATSUI support. One can work around that for now by building against the 10.6 SDK.
Comment 5 John Ralls 2011-09-06 15:33:03 UTC
But unfortunately it now fails when building on Leopard:
  CCLD   cairo-analyse-trace
Undefined symbols:
  "_strndup", referenced from:
      _main in cairo-analyse-trace.o
  "_getline", referenced from:
      _main in cairo-analyse-trace.o
ld: symbol(s) not found

$  nm util/cairo-missing/.libs/libcairo-missing.dylib | grep strndup
00001da0 t _strndup

So, not exported.
Comment 6 Andrea Canciani 2011-09-07 07:21:23 UTC
Created attachment 50961 [details] [review]
Make cairo-missing a static library

(In reply to comment #4)
> Cairo builds on Lion with the ranma42 patch, yes.
> 
> The only problem with any build-time configuration for these is that the
> resulting shared library won't work on previous versions of OSX. That includes
> Snow Leopard and previous in the cases of getline and strndup, and Tiger for
> ATSUI support. One can work around that for now by building against the 10.6
> SDK.

Yes, that's true.
If it becomes an issue, we can define strndup()/getline() in cairo-missing unconditionally, so that they will always be available.

Regarding the font thing, I just noticed that although it's not available in the headers, FMGetATSFontRefFromFont is still provided by the 10.7 frameworks:
$ nm /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/Frameworks/QD.framework/Versions/Current/QD | grep FMGetATSFontRefFromFont
0000000000007ec1 T _FMGetATSFontRefFromFont

We can probably make it available just like "private" APIs by dlsym'ing it.

(In reply to comment #5)
> But unfortunately it now fails when building on Leopard:
>   CCLD   cairo-analyse-trace
> Undefined symbols:
>   "_strndup", referenced from:
>       _main in cairo-analyse-trace.o
>   "_getline", referenced from:
>       _main in cairo-analyse-trace.o
> ld: symbol(s) not found
> 
> $  nm util/cairo-missing/.libs/libcairo-missing.dylib | grep strndup
> 00001da0 t _strndup
> 
> So, not exported.

Yes, they're not exported as it was supposed to be a static library.
Can you please check if the attached patch fixes your 10.6 build?

Otherwise, can you provide additional details about your 10.6 build environment?
In my environment the build fails with:
Undefined symbols for architecture x86_64:
  "_png_set_longjmp_fn", referenced from:
      _read_png in lto.o
      _png_simple_error_callback in lto.o
      _write_png in lto.o

(which is weird, as the build works just fine when I don't have "-isysroot /Developer/SDKs/MacOSX10.6.sdk" in CFLAGS/LDFLAGS).
Comment 7 John Ralls 2011-09-08 11:28:24 UTC
Created attachment 50989 [details]
Cairo config.log for gtk-osx build
Comment 8 John Ralls 2011-09-08 11:42:45 UTC
Comment on attachment 50989 [details]
Cairo config.log for gtk-osx build

Yes, that did it. 

(I'd created the attachment before looking to make sure that libcairo-missing had gotten rebuilt -- and naturally, it hadn't.)
Comment 9 Andrea Canciani 2011-09-18 09:27:27 UTC
Created attachment 51316 [details] [review]
The dlsym trick

This patch should work and provide the API on every system (returning nil fonts when it doesn't actually work).
Comment 10 John Ralls 2011-09-18 16:14:29 UTC
OK, that works too, and should handle the binary portability problem as well.
Thanks!
Comment 11 Andrea Canciani 2011-10-01 09:31:32 UTC
Fixed in master by:

commit 8664df767cb9dbe48647f9853e3dcf551701d3ca
Author: Andrea Canciani <ranma42@gmail.com>
Date:   Sat Sep 3 09:39:24 2011 -0700

    quartz: Fix the 32-bits build on MacOSX 10.7
    
    FMGetATSFontRefFromFont() is not public on Lion nor on 64-bits
    Frameworks, but it seems to be available in the dynamic libs, hence we
    can dlsym() it just like other private functions.
    
    Works around the error:
    cairo-quartz-font.c: In function 'cairo_quartz_font_face_create_for_atsu_font_id':
    cairo-quartz-font.c:830: error: implicit declaration of function 'FMGetATSFontRefFromFont'
    
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=39493


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.