Simplify binding generation and remove the need for a custom clang.

This commit is contained in:
Bobby Holley 2016-04-26 13:54:07 -07:00
parent 402f79559b
commit fb0237d85c
5 changed files with 47 additions and 80 deletions

View file

@ -8,10 +8,6 @@ work.
You can see a description of them below.
## `build_custom_clang.sh`
Download a patched LLVM which is needed to use bindgen properly with C++.
## `setup_bindgen.sh`
This uses downloads a custom version of bindgen, up to date to generate the

View file

@ -1,24 +0,0 @@
#!/bin/bash
# Run in the tools directory.
cd "$(dirname $0)"
# Don't run twice.
if [ -d llvm ]; then
echo "llvm directory already exists."
exit 1
fi
# Download and build a custom llvm
git clone https://github.com/llvm-mirror/llvm
cd llvm
git checkout release_38
cd tools
git clone https://github.com/llvm-mirror/clang
cd clang
git checkout release_38
cd ../.. # llvm root dir
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j8

View file

@ -14,11 +14,19 @@ if [ ! -d rust-bindgen ]; then
exit 1
fi
export RUST_BACKTRACE=1
export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export DIST_INCLUDE="$1/dist/include"
# Check for /usr/include
if [ ! -d /usr/include ]; then
echo "/usr/include doesn't exist. Mac users may need to run xcode-select --install."
exit 1
fi
if [ "$(uname)" == "Linux" ]; then
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
else
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
fi
# Prevent bindgen from generating opaque types for the gecko style structs.
export MAP_GECKO_STRUCTS=""
@ -30,26 +38,24 @@ for STRUCT in nsStyleFont nsStyleColor nsStyleList nsStyleText \
nsStyleOutline nsStyleXUL nsStyleSVGReset nsStyleColumn nsStyleEffects
do
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-blacklist-type $STRUCT "
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-raw-line 'use gecko_style_structs::$STRUCT;'$'\n' "
MAP_GECKO_STRUCTS=$MAP_GECKO_STRUCTS"-raw-line 'use gecko_style_structs::$STRUCT;' "
done
# Check for the include directory.
export DIST_INCLUDE="$1/dist/include"
if [ ! -d "$DIST_INCLUDE" ]; then
echo "$DIST_INCLUDE: directory not found"
exit 1
fi
export RUST_BACKTRACE=1
# We need to use 'eval' here to make MAP_GECKO_STRUCTS evaluate properly as
# multiple arguments.
#
# Uncomment the following line to run rust-bindgen in a debugger on mac.
# The absolute path is required to allow launching lldb with an untrusted
# library in DYLD_LIBRARY_PATH.
#
# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb --
eval ./rust-bindgen/target/debug/bindgen \
-x c++ -std=gnu++0x \
"-I$DIST_INCLUDE" \
$PLATFORM_DEPENDENT_DEFINES \
-o ../bindings.rs \
-no-type-renaming \
"$DIST_INCLUDE/mozilla/ServoBindings.h" \

View file

@ -14,49 +14,34 @@ if [ ! -d rust-bindgen ]; then
exit 1
fi
# Need to find a way to avoid hardcoding these
export RUST_BACKTRACE=1
export LIBCLANG_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export LD_LIBRARY_PATH="$(pwd)/llvm/build/Release+Asserts/lib"
export DIST_INCLUDE="$1/dist/include"
CLANG_SEARCH_DIRS=$(clang++ -E -x c++ - -v < /dev/null 2>&1 | awk '{ \
if ($0 == "#include <...> search starts here:") \
in_headers = 1; \
else if ($0 == "End of search list.") \
in_headers = 0; \
else if (in_headers == 1) { \
gsub(/^[ \t]+/, "", $0); \
gsub(/[ \t].+$/, "", $0); \
printf " -isystem %s", $0; \
}
}' | sed -e s/:$//g)
# Check for /usr/include
if [ ! -d /usr/include ]; then
echo "/usr/include doesn't exist. Mac users may need to run xcode-select --install."
exit 1
fi
if [ "$(uname)" == "Linux" ]; then
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
else
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
fi
# Check for the include directory.
export DIST_INCLUDE="$1/dist/include"
if [ ! -d "$DIST_INCLUDE" ]; then
echo "$DIST_INCLUDE: directory not found"
exit 1
fi
PLATFORM_DEPENDENT_DEFINES="";
if [ "$(uname)" == "Linux" ]; then
PLATFORM_DEPENDENT_DEFINES+="-DOS_LINUX";
else
PLATFORM_DEPENDENT_DEFINES+="-DOS_MACOSX";
fi
export RUST_BACKTRACE=1
# Uncomment the following line to run rust-bindgen in a debugger on mac. The
# absolute path is required to allow launching lldb with an untrusted library
# in DYLD_LIBRARY_PATH.
#
# /Applications/Xcode.app/Contents/Developer/usr/bin/lldb --
# gdb -ex "break rust_panic" -ex run --args \
# -enable-cxx-namespaces \
./rust-bindgen/target/debug/bindgen \
-o ../gecko_style_structs.rs \
-x c++ -std=gnu++0x \
-allow-unknown-types \
$CLANG_SEARCH_DIRS \
"-I$DIST_INCLUDE" "-I$DIST_INCLUDE/nspr" \
"-I$1/../nsprpub/pr/include" \
$PLATFORM_DEPENDENT_DEFINES \

View file

@ -4,17 +4,21 @@
cd "$(dirname $0)"
# Setup and build bindgen.
export LIBCLANG_PATH="$(pwd)/llvm/build/lib"
export LD_LIBRARY_PATH="$(pwd)/llvm/build/lib"
export DYLD_LIBRARY_PATH="$(pwd)/llvm/build/lib"
if [ "$(uname)" == "Linux" ]; then
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib;
else
LIBCLANG_PATH=`brew --prefix llvm38`/lib/llvm-3.8/lib;
fi
# Make sure we have a custom clang set up.
if [ ! -d "$LIBCLANG_PATH" ]; then
echo "Custom LLVM/Clang not found. Run build_custom_clang.sh first."
# Make sure we have llvm38.
if [ ! -x "$(command -v clang++-3.8)" ]; then
echo "llmv38 must be installed. Mac users should |brew install llvm38|, Linux varies by distro."
exit 1
fi
export LD_LIBRARY_PATH=$LIBCLANG_PATH
export DYLD_LIBRARY_PATH=$LIBCLANG_PATH
# Check for multirust
if [ ! -x "$(command -v multirust)" ]; then
echo "multirust must be installed."