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 http://llvm.org/svn/llvm-project/llvm/trunk \
 "${HOME?}"/Software/clang/trunk/src
svn co http://llvm.org/svn/llvm-project/cfe/trunk \
 "${HOME?}"/Software/clang/trunk/src/tools/clang
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk \
 "${HOME?}"/Software/clang/trunk/src/tools/clang/tools/extra
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk \
 "${HOME?}"/Software/clang/trunk/src/projects/compiler-rt
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 \
 --enable-optimized
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 = StrRef.data();
   // Account for cases where the string literal is truncated in a declaration.
   const ConstantArrayType *T = Context.getAsConstantArrayType(FExpr->getType());
+if(!T)return;
   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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
CXX=/Users/you/Software/clang/trunk/inst/bin/clang++ -m64 -stdlib=libc++ -mmacosx-version-min=10.8 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1
CLANGDIR=/Users/you/Software/clang/trunk/inst

to autogen.input. That is, look at the values assigned to CC and CXX in config_host.mk after a plain ./autogen.sh, 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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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