Clang Plugins on Mac

The Xcode-provided Clang appears not be bring along the include files needed for plugins, so LibreOffice never ran its set of Clang plugins when building on Mac OS X. Until now.

What works is to build a local copy of Clang, e.g., from trunk with the script

set -ex
mkdir -p "${HOME?}"/Software/clang
mkdir "${HOME?}"/Software/clang/trunk
svn co \
svn co \
svn co \
svn co \
mkdir "${HOME?}"/Software/clang/trunk/build
cd "${HOME?}"/Software/clang/trunk/build
"${HOME?}"/Software/clang/trunk/src/configure \
 --prefix="${HOME?}"/Software/clang/trunk/inst --enable-keep-symbols \
make -j8
make install -j8

where --enable-keep-symbols is important on OS X so that the
clang/clang++ executables do export all the symbols
referenced by plugins.

Current Clang trunk has one bug that is triggered by the internal copy of
python3 in LibreOffice, “Concatenated Objective C format string triggers Sema::CheckFormatString ‘String literal not of constant array type!” assert,“ a workaround is to apply the patch

Index: lib/Sema/SemaChecking.cpp
--- lib/Sema/SemaChecking.cpp (revision 202077)
+++ lib/Sema/SemaChecking.cpp (working copy)
@@ -3533,6 +3533,7 @@
   const char *Str =;
   // Account for cases where the string literal is truncated in a declaration.
   const ConstantArrayType *T = Context.getAsConstantArrayType(FExpr->getType());
   assert(T && "String literal not of constant array type!");
   size_t TypeSize = T->getSize().getZExtValue();
   size_t StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, StrRef.size());

to tools/clang.

On recent LibreOffice trunk, with “Allow building compilerplugins/clang on Mac OS X” and “Drop CLANGBUILD in addition to CLANGDIR”, when doing a build of the 64-bit, ≥ 10.8 variant, add

CC=/Users/you/Software/clang/trunk/inst/bin/clang -m64 -mmacosx-version-min=10.8 -isysroot /Applications/
CXX=/Users/you/Software/clang/trunk/inst/bin/clang++ -m64 -stdlib=libc++ -mmacosx-version-min=10.8 -isysroot /Applications/ -isystem /Applications/

to autogen.input. That is, look at the values assigned to CC and CXX in after a plain ./, replace the path to clang resp. clang++, and add the include path to the Xcode libc++ headers to CXX. (You can likely also drop the implicit -m64 and -stdlib=libc++.)

And that’s it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s